Class AerisEngine
- java.lang.Object
-
- com.aerisweather.aeris.communication.AerisEngine
-
- All Implemented Interfaces:
PermissionsTask.PermissionsCallback
public class AerisEngine extends Object implements PermissionsTask.PermissionsCallback
Aeris singleton that manages the important OAuth info needed to make requests. In order to call an Aeris request without manually passing the clientId, client secret and App ID to a request, this engine must be initialized.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AerisEngine.Units
-
Field Summary
Fields Modifier and Type Field Description static AerisEngine
inst
-
Constructor Summary
Constructors Constructor Description AerisEngine()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getAppId()
Get the App id.String
getClientId()
Get the client id.String
getClientSecret()
Get the client secret.static AerisEngine
getInstance()
Get an instance of the AerisEngine.AerisPermissions
getPermissions()
Returns the current Aeris permissions if they have been obtained through the API.void
initPermissions(android.content.Context context)
static void
initWithKeys(String clientId, String clientSecret, android.content.Context context)
Intializes the engine with client id, client secret, and app package name for the app ID.static void
initWithKeys(String clientId, String clientSecret, String appId)
Initializes the engine with client id, client secret, and app package name for the app ID.boolean
isDebugLogcatEnabled()
Returns true if debug logcat is enabled for all requests/responses.boolean
isStandardUnits(android.content.Context context, boolean defaultVal)
Helper within the engine to get if standard has been set as a preference.void
onPermissionsObtained(AerisPermissionsResponse response)
Callback method for handling the response of the PermissionsTaskvoid
setDebugLogcatEnabled(boolean enabled)
Sets whether all requests/responses should be output to the logcat.void
setPermissions(AerisPermissions permissions)
Sets the permissions.void
setUnits(AerisEngine.Units unit, android.content.Context context)
Helper within the engine to set the units to an Android preference.
-
-
-
Field Detail
-
inst
public static AerisEngine inst
-
-
Method Detail
-
initWithKeys
public static void initWithKeys(String clientId, String clientSecret, android.content.Context context)
Intializes the engine with client id, client secret, and app package name for the app ID.- Parameters:
clientId
- the client id given by Aeris.clientSecret
- the client secret given by Aeris.context
- Needed to grab the package name.
-
initPermissions
public void initPermissions(android.content.Context context)
-
initWithKeys
public static void initWithKeys(String clientId, String clientSecret, String appId)
Initializes the engine with client id, client secret, and app package name for the app ID.- Parameters:
clientId
- the client id given by Aeris.clientSecret
- the client secret given by Aeris.appId
- App id of the project using the lib.
-
getInstance
public static AerisEngine getInstance()
Get an instance of the AerisEngine. Should only be called afterinitWithKeys(String, String, Context)
has been called.- Returns:
- the instance of AerisEngine.
-
setDebugLogcatEnabled
public void setDebugLogcatEnabled(boolean enabled)
Sets whether all requests/responses should be output to the logcat. Default is false.Each request can be turned on specifically as well.- Parameters:
enabled
- if debug should be enabled.
-
isDebugLogcatEnabled
public boolean isDebugLogcatEnabled()
Returns true if debug logcat is enabled for all requests/responses. Default if false.- Returns:
- true if debug is enabled.
-
getClientId
public String getClientId()
Get the client id.- Returns:
- the client id.
-
getClientSecret
public String getClientSecret()
Get the client secret.- Returns:
- the client secret.
-
getAppId
public String getAppId()
Get the App id.- Returns:
- app id, the package name of the project.
-
onPermissionsObtained
public void onPermissionsObtained(AerisPermissionsResponse response)
Description copied from interface:PermissionsTask.PermissionsCallback
Callback method for handling the response of the PermissionsTask- Specified by:
onPermissionsObtained
in interfacePermissionsTask.PermissionsCallback
- Parameters:
response
- permissions response from Aeris API
-
setUnits
public void setUnits(AerisEngine.Units unit, android.content.Context context)
Helper within the engine to set the units to an Android preference. Currently only STANDARD, METRIC supported.- Parameters:
unit
- Unit type to set as.context
- context to use for preference.
-
isStandardUnits
public boolean isStandardUnits(android.content.Context context, boolean defaultVal)
Helper within the engine to get if standard has been set as a preference.- Parameters:
context
- context to use.defaultVal
- default value if an android preference has not been set.- Returns:
- true if in standard units
-
getPermissions
public AerisPermissions getPermissions()
Returns the current Aeris permissions if they have been obtained through the API. This is done automatically on application startup. If they have not been obtained for some reason, it will use default settings.- Returns:
- The permissions.
-
setPermissions
public void setPermissions(AerisPermissions permissions)
Sets the permissions. This will not be stored to a preference as the the ones retrieved by the Aeris API will be.- Parameters:
permissions
- permissions to use.
-
-