class API
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
(package private) static class |
API.Get
The protocol for GET requests is as follows...
|
(package private) static class |
API.Post |
(package private) static class |
API.Put |
Modifier and Type | Field and Description |
---|---|
(package private) static java.lang.String |
API_URL_BASE
Base of the URL all API endpoints use.
|
(package private) static java.lang.String |
CURRENT_USER
Identifier for the currently-signed-in user's ID.
|
(package private) static java.lang.String |
FEED_ITEM_COUNT_SIZE
The number of items (e.g.
|
(package private) static java.lang.String |
HOSTING |
(package private) static java.lang.String |
LOGIN_TOKEN
Settings identifier for the currently cached login token for the user.
|
(package private) static java.lang.String |
NO_MAX_PAGINATION |
(package private) static java.lang.String |
SELECTED_NETWORK
Identifier for the user's currently selected
Network . |
(package private) static java.lang.String |
SELECTED_USER
The SharedPreferences key for communicating to ViewProfileActivity which user we are viewing.
|
(package private) static java.lang.String |
SETTINGS_IDENTIFIER
Identifier for the app's shared preferences.
|
private static java.lang.String |
TAG
Tag to use for log statements.
|
(package private) static int |
TOKEN_REFRESH
Number of milliseconds to use a login token before refreshing it.
|
(package private) static java.lang.String |
TOKEN_RETRIEVED
Settings identifier for when the current login token was retrieved.
|
(package private) static java.lang.String |
USER_EMAIL
Identifier for the currently-signed-in user's email.
|
Constructor and Description |
---|
API() |
Modifier and Type | Method and Description |
---|---|
private static void |
emptyModel(RequestQueue queue,
java.lang.String url,
java.lang.String func,
int requestMethod,
android.content.SharedPreferences settings,
<any> listener)
Add to the provided queue a request to the server at the provided URL using the provided method
|
private static void |
expandDatabaseNetwork(RequestQueue queue,
org.codethechange.culturemesh.models.DatabaseNetwork dn,
<any> listener)
DatabaseNetwork s do not store all the information associated with a Network . |
(package private) static java.lang.String |
genBasicAuth(java.lang.String token)
Generate from a login token the string to put in the header of a request
as the value of the
Authorization token in order to perform Basic Authentication. |
(package private) static java.lang.String |
genBasicAuth(java.lang.String email,
java.lang.String password)
Generate from a username/email and password the string to put in the header of a request
as the value of the
Authorization token in order to perform Basic Authentication. |
(package private) static java.lang.String |
getCredentials()
Use this method to append our credentials to our server requests.
|
private static java.lang.String |
getPagination(java.lang.String id)
Fetches query parameter string you need to add in to the request url.
|
private static void |
locationToPlace(RequestQueue queue,
org.codethechange.culturemesh.models.Location loc,
<any> listener)
Location s do not store all the information associated with a Place . |
private static int |
processNetworkError(java.lang.String method,
java.lang.String task,
VolleyError error)
Process errors that could be returned in the form of a
VolleyError the Response.Listener |
static final java.lang.String SETTINGS_IDENTIFIER
SharedPreferences settings = getSharedPreferences(API.SETTINGS_IDENTIFIER, MODE_PRIVATE)
static final java.lang.String SELECTED_NETWORK
Network
. This is used to save the network
the user was last viewing so that network can be re-opened when the user navigates back.
Example: settings.getLong(API.SELECTED_NETWORK, -1)
.static final java.lang.String SELECTED_USER
static final java.lang.String CURRENT_USER
settings.getLong(API.CURRENT_USER, -1)
.static final java.lang.String USER_EMAIL
settings.getLong(API.USER_EMAIL, -1)
.static final java.lang.String API_URL_BASE
/token
endpoint has the URL
API_URL_BASE + "/token"
.static final java.lang.String NO_MAX_PAGINATION
static final java.lang.String HOSTING
static final java.lang.String FEED_ITEM_COUNT_SIZE
Post
s or Event
s
to fetch with each paginated requeststatic final java.lang.String LOGIN_TOKEN
TOKEN_REFRESH
.static final java.lang.String TOKEN_RETRIEVED
LOGIN_TOKEN
,
Constant Field Valuesprivate static final java.lang.String TAG
static final int TOKEN_REFRESH
LOGIN_TOKEN
,
Constant Field Valuesprivate static void emptyModel(RequestQueue queue, java.lang.String url, java.lang.String func, int requestMethod, android.content.SharedPreferences settings, <any> listener)
queue
- Queue to which the asynchronous task will be addedurl
- URL of the endpoint to send the request tofunc
- Name of the function making the request for logging purposesrequestMethod
- The method (e.g. POST, PUT, GET, etc.) to use in making the request. Use
the constants provided in Request.Method
settings
- Reference to the app's SharedPreferences
where the user's login tokens
are storedlistener
- Listener that will be called with the result of the task once completedprivate static void expandDatabaseNetwork(RequestQueue queue, org.codethechange.culturemesh.models.DatabaseNetwork dn, <any> listener)
DatabaseNetwork
s do not store all the information associated with a Network
.
Instead, a DatabaseNetwork
is like a bundle of pointers to the parts of the
Network
it represents. This method "expands" a DatabaseNetwork
into a
Network
by resolving those "pointers" and combining the results. The objects referred
to by IDs in the DatabaseNetwork
are fetched with API calls and re-bundled into a
Network
. See the documentation for Location
for more information on this
inheritance hierarchy.queue
- Queue to which the asynchronous task will be addeddn
- DatabaseNetwork
to expand into a Network
listener
- Listener whose com.android.volley.Response.Listener#onResponse(Object)
is called with the NetworkResponse
created by the query.private static void locationToPlace(RequestQueue queue, org.codethechange.culturemesh.models.Location loc, <any> listener)
Location
s do not store all the information associated with a Place
.
Instead, a Location
is like a bundle of pointers to the parts of the
Place
it represents. This method "expands" a Location
into a
Place
by resolving those "pointers" and combining the results. The objects referred
to by IDs in the Location
are fetched with API calls and re-bundled into a
Place
. See the documentation for Location
for more information on this
inheritance hierarchy.queue
- Queue to which the asynchronous task will be addedloc
- Location
to expand into a Place
listener
- Listener whose com.android.volley.Response.Listener#onResponse(Object)
is called with the NetworkResponse
created by the query.private static int processNetworkError(java.lang.String method, java.lang.String task, VolleyError error)
VolleyError
the Response.Listenermethod
- The method where the error occurredtask
- Description of the task being attempted. This will be included in log entries.error
- The error returnedstatic java.lang.String getCredentials()
static java.lang.String genBasicAuth(java.lang.String email, java.lang.String password)
Authorization
token in order to perform Basic Authentication.
For example: headers.put("Authorization", genBasicAuth(email, password))
. A login
token can be used if it is passed as the email
, in which case the password
is ignored by the server.email
- Email or username of account to login as; can also be a login tokenpassword
- Password to login withAuthorization
static java.lang.String genBasicAuth(java.lang.String token)
Authorization
token in order to perform Basic Authentication.
For example: headers.put("Authorization", genBasicAuth(token))
.token
- Login token to authenticate to serverAuthorization
private static java.lang.String getPagination(java.lang.String id)
id
- maximum id of item you want to fetch. Use API.NO_MAX_PAGINATION if you want no limit.