com.eclipsesource.tabris.tracking.internal.analytics.request.AnalyticsRequest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tabris-tracking Show documentation
Show all versions of tabris-tracking Show documentation
Piwik and Google Analytics Tracking for Tabris Apps.
The newest version!
/*******************************************************************************
* Copyright (c) 2014 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* EclipseSource - initial API and implementation
******************************************************************************/
package com.eclipsesource.tabris.tracking.internal.analytics.request;
import static com.eclipsesource.tabris.internal.Clauses.when;
import static com.eclipsesource.tabris.internal.Clauses.whenNull;
import static com.eclipsesource.tabris.tracking.internal.analytics.request.RequestKeyProvider.getRequestKey;
import static com.eclipsesource.tabris.tracking.internal.analytics.request.RequestKeys.APP_NAME;
import static com.eclipsesource.tabris.tracking.internal.analytics.request.RequestKeys.CLIENT_ID;
import static com.eclipsesource.tabris.tracking.internal.analytics.request.RequestValueProvider.getRequestValue;
import static com.eclipsesource.tabris.tracking.internal.analytics.request.RequestValues.HIT_SCREENVIEW;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.eclipsesource.tabris.tracking.internal.Requestable;
@SuppressWarnings("restriction")
public class AnalyticsRequest implements Serializable {
private final String appName;
private final List requestables;
private final String clientId;
public AnalyticsRequest( String appName, String clientId, Requestable... requestables ) {
validateArguments( appName, clientId );
this.appName = appName;
this.clientId = clientId;
this.requestables = Arrays.asList( requestables );
}
private void validateArguments( String appName, String clientId ) {
whenNull( appName ).throwIllegalArgument( "AppName must not be null." );
when( appName.isEmpty() ).throwIllegalArgument( "AppName must not be empty." );
whenNull( clientId ).throwIllegalArgument( "ClientId must not be null." );
when( clientId.isEmpty() ).throwIllegalArgument( "ClientId must not be empty." );
}
public Map assemble() {
Map parameter = createRequestableParameter();
addAppName( parameter );
checkAppNameSet( parameter );
parameter.put( getRequestKey( CLIENT_ID ), clientId );
return parameter;
}
private Map createRequestableParameter() {
Map parameter = new HashMap();
for( Requestable requestable : requestables ) {
parameter.putAll( requestable.getParameter() );
}
return parameter;
}
private void addAppName( Map result ) {
if( appName != null ) {
result.put( getRequestKey( APP_NAME ), appName );
}
}
private void checkAppNameSet( Map hitRequestChunk ) {
when( hitRequestChunk.containsValue( getRequestValue( HIT_SCREENVIEW ) ) && appName == null )
.throwIllegalState( "AppName must be set when assembling an ScreenViewHit request." );
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy