Copyright (c) 2012 CloudMine LLC, http://cloudmine.me
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software")...
If you think the Android project cloudmine-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.cloudmine.api.rest;
//fromwww.java2s.comimport com.cloudmine.api.CMSessionToken;
import com.cloudmine.api.DeviceIdentifier;
import com.cloudmine.api.Strings;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* <br>
* Copyright CloudMine LLC. All rights reserved<br>
* See LICENSE file included with SDK for details.
*/publicclass AndroidHeaderFactory extends JavaHeaderFactory {
publicstaticfinal String CLOUD_MINE_AGENT = "Android/0.6.1";
privatestatic Map<String, String> DEFAULT_HEADERS = new HashMap<String, String>();
static {
DEFAULT_HEADERS.put(AGENT_HEADER_KEY, CLOUD_MINE_AGENT);
}
publicstatic Map<String, String> getHeaderMapping(String sessionTokenString, String apiKey) {
Map<String, String> headerMap = new HashMap<String, String>(DEFAULT_HEADERS);
headerMap.put(HeaderFactory.DEVICE_HEADER_KEY, getDeviceHeaderValue());
headerMap.put(HeaderFactory.API_HEADER_KEY, apiKey); //worry about sync issues? not now but could be an issue
if(Strings.isNotEmpty(sessionTokenString)) headerMap.put(HeaderFactory.SESSION_TOKEN_HEADER_KEY, sessionTokenString);
return headerMap;
}
publicstatic Map<String, String> getHeaderMapping(CMSessionToken sessionToken, String apiKey) {
String sessionTokenString = sessionToken == null ? null : sessionToken.getSessionToken();
return getHeaderMapping(sessionTokenString, apiKey);
}
privatestatic String getDeviceHeaderValue() {
String deviceId = DeviceIdentifier.getUniqueId();
String timingHeaders = ResponseTimeDataStore.getContentsAsStringAndClearMap();
String deviceHeaderValue = deviceId;
if(Strings.isNotEmpty(timingHeaders)) deviceHeaderValue += "; " + timingHeaders;
return deviceHeaderValue;
}
protected String getDeviceIdentifier() {
return DeviceIdentifier.getUniqueId();
}
@Override
public String getCloudMineAgent() {
return CLOUD_MINE_AGENT;
}
}