@LevelUpApi(contract=INTERNAL) public final class RequestUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
HEADER_ACCEPT
Header key for the accepts.
|
static String |
HEADER_CONTENT_TYPE_JSON
Value for the accepts header for JSON.
|
static String |
HEADER_DEVICE_MODEL_KEY
Header key that maps to the model of the current device.
|
static String |
HEADER_DEVICE_MODEL_VALUE
Header value representing the model of the current device.
|
static String |
HEADER_USER_AGENT
Header key for the user agent.
|
static String |
PARAM_API_KEY
Parameter for the app's LevelUp API key.
|
static String |
PARAM_CLIENT_ID
Deprecated.
|
static String |
PARAM_DEVICE_IDENTIFIER
Parameter for the device identifier.
|
Modifier and Type | Method and Description |
---|---|
static void |
addApiKeyToRequestBody(Context context,
com.google.gson.JsonObject body)
Add the API key to the request body.
|
static void |
addApiKeyToRequestBody(Context context,
JSONObject body)
Add the API key to the request body.
|
static void |
addApiKeyToRequestQueryParams(Context context,
Map<String,String> params)
Add the API key to the request query parameters.
|
static void |
addDeviceIdToRequestBody(Context context,
com.google.gson.JsonObject body)
Add the Device ID to the request body if the Device ID can be determined.
|
static void |
addDeviceIdToRequestBody(Context context,
JSONObject body)
Add the Device ID to the request body if the Device ID can be determined.
|
static String |
getApiKey(Context context)
Get the API key for the context passed.
|
static Map<String,String> |
getDefaultRequestHeaders(Context context)
Get the request headers for all API requests.
|
static String |
getDeviceId(Context context)
Gets the deviceId to add to the login/register requests.
|
static String |
getUserAgent(Context context)
Returns a
String representation to use as the User-Agent string when communicating
with the server. |
public static final String HEADER_ACCEPT
public static final String HEADER_CONTENT_TYPE_JSON
public static final String HEADER_USER_AGENT
public static final String HEADER_DEVICE_MODEL_KEY
HEADER_DEVICE_MODEL_VALUE
,
Constant Field Valuespublic static final String HEADER_DEVICE_MODEL_VALUE
HEADER_DEVICE_MODEL_KEY
public static final String PARAM_API_KEY
@Deprecated public static final String PARAM_CLIENT_ID
PARAM_API_KEY
and will be removed in the next major release of the SDK.public static final String PARAM_DEVICE_IDENTIFIER
public static Map<String,String> getDefaultRequestHeaders(Context context)
context
- Application context.public static String getUserAgent(Context context)
String
representation to use as the User-Agent string when communicating
with the server. A sample string looks like:
"LevelUp/2.3.12 (Linux; U; Android; 1.0; generic_x86/sd_x86; en-US;) LevelUpSdk/0.0.1".
context
- Application context.public static String getApiKey(Context context)
context
- the Application context.public static String getDeviceId(Context context)
context
- the Application context.public static void addApiKeyToRequestQueryParams(Context context, Map<String,String> params)
context
- Application context.params
- the query parameter Map
to add the API key to.public static void addApiKeyToRequestBody(Context context, JSONObject body)
context
- Application context.body
- the JSONObject
to add the API key to.public static void addApiKeyToRequestBody(Context context, com.google.gson.JsonObject body)
context
- Application context.body
- the JsonObject
to add the API key to.public static void addDeviceIdToRequestBody(Context context, JSONObject body)
context
- Application contextbody
- the JSONObject
to add the Device ID topublic static void addDeviceIdToRequestBody(Context context, com.google.gson.JsonObject body)
context
- Application contextbody
- the JsonObject
to add the Device ID to