API.Get

static class Get

The protocol for GET requests is as follows… 1. Check if cache has relevant data. If so, return it. 2. Send network request to update data.

Methods

autocompleteLanguage

static void autocompleteLanguage(RequestQueue queue, String text, Response.Listener<NetworkResponse<List<Language>>> listener)

Get potential Languages that match a user’s query text

Parameters:
  • queue – Queue to which the asynchronous task will be added
  • text – User’s query text to get autocomplete results for
  • listener – Listener whose com.android.volley.Response.Listener.onResponse(Object) is called with the NetworkResponse created by the query.

autocompletePlace

static void autocompletePlace(RequestQueue queue, String text, Response.Listener<NetworkResponse<List<Location>>> listener)

Get potential Locations that match a user’s query text

Parameters:
  • queue – Queue to which the asynchronous task will be added
  • text – User’s query text to get autocomplete results for
  • listener – Listener whose com.android.volley.Response.Listener.onResponse(Object) is called with the NetworkResponse created by the query.

instantiatePostReplyUser

static void instantiatePostReplyUser(RequestQueue queue, PostReply comment, Response.Listener<PostReply> listener)

The API will return Post JSON Objects with id’s for the user. Often, we will want to get the user information associated with a post, such as the name and profile picture. This method allows us to instantiate this user information for each post.

Parameters:
  • queue – The Volley RequestQueue object that handles all the request queueing.
  • comment – An already instantiated PostReply object that has a null author field but a defined userId field.
  • listener – the UI listener that will be called when we complete the task at hand.

instantiatePostUser

static void instantiatePostUser(RequestQueue queue, org.codethechange.culturemesh.models.Post post, Response.Listener<org.codethechange.culturemesh.models.Post> listener)

The API will return Post JSON Objects with id’s for the user. Often, we will want to get the user information associated with a post, such as the name and profile picture. This method allows us to instantiate this user information for each post.

Parameters:
  • queue – The Volley RequestQueue object that handles all the request queueing.
  • post – An already instantiated Post object that has a null author field but a defined userId field.
  • listener – the UI listener that will be called when we complete the task at hand.

language

static void language(RequestQueue queue, long id, Response.Listener<NetworkResponse<Language>> listener)

Get the Language that has the provided ID

Parameters:
  • queue – Queue to which the asynchronous task will be added
  • id – ID of the Language to find. Must be unique, and the same ID must be used throughout.
  • listener – Listener whose com.android.volley.Response.Listener.onResponse(Object) is called with the NetworkResponse created by the query.

loginToken

static void loginToken(RequestQueue queue, SharedPreferences settings, Response.Listener<NetworkResponse<String>> listener)

Generically get a login token. If the token is fresh (less than API.TOKEN_REFRESH seconds have passed since the last token was retrieved the current token is simply supplied. Otherwise, an attempt is made to login with the token to get a new one. If this fails, the token has expired, and the user is directed to sign in again by the error dialog. If it succeeds, the new token is stored in place of the old one.

Parameters:
  • queue – Queue to which the asynchronous task will be added
  • listener – Listener whose onResponse method will be called when task completes

See also: NetworkResponse.genErrorDialog(Context,int,boolean), API.LOGIN_TOKEN, API.TOKEN_RETRIEVED

loginWithCred

static void loginWithCred(RequestQueue queue, String email, String password, SharedPreferences settings, Response.Listener<NetworkResponse<LoginResponse>> listener)

Use a user’s login credentials to login to the server. A user’s credentials consist of the email address associated with their account and their password for the CultureMesh website. If the credentials are accepted by the server, the resulting LoginResponse will be stored in the NetworkResponse, which will not be in a failed state, and passed to the listener. If the credentials are rejected, the NetworkResponse will be in a failed state with an error message communicating the occurrence of an authentication failure and instructing the user to sign in again. After dismissing the error dialog, the LoginActivity will be launched.

Parameters:
  • queue – Queue to which the asynchronous task will be added
  • email – Email address that will serve as the username in the attempted login
  • password – Password to use in the login attempt
  • listener – Will be called with the NetworkResponse when the operation completes

See also: NetworkResponse.genErrorDialog(Context,int,boolean)

loginWithToken

static void loginWithToken(RequestQueue queue, String token, SharedPreferences settings, Response.Listener<NetworkResponse<LoginResponse>> listener)

Same as API.Get.loginWithCred(RequestQueue,String,String,SharedPreferences,Response.Listener), but a login token is used in place of the user’s credentials.

Parameters:
  • queue – Queue to which the asynchronous task will be added
  • token – Login token to use to get another token
  • listener – Will be called with the NetworkResponse when the operation completes

netFromFromAndNear

static void netFromFromAndNear(RequestQueue queue, FromLocation from, NearLocation near, Response.Listener<NetworkResponse<Network>> listener)

Get the Network that has the provided FromLocation and NearLocation

Parameters:
  • queue – Queue to which the asynchronous task will be added
  • fromFromLocation of the Network to find
  • nearNearLocation of the Network to find
  • listener – Listener whose com.android.volley.Response.Listener.onResponse(Object) is called with the NetworkResponse created by the query.

netFromLangAndNear

static void netFromLangAndNear(RequestQueue queue, Language lang, NearLocation near, Response.Listener<NetworkResponse<Network>> listener)

Get the Network that has the provided Language and NearLocation

Parameters:
  • queue – Queue to which the asynchronous task will be added
  • langLanguage of the Network to find
  • nearNearLocation of the Network to find
  • listener – Listener whose com.android.volley.Response.Listener.onResponse(Object) is called with the NetworkResponse created by the query.

network

static void network(RequestQueue queue, long id, Response.Listener<NetworkResponse<Network>> callback)

Get the Network corresponding to the provided ID

Parameters:
  • queue – Queue to which the asynchronous task to get the Network will be added
  • id – ID of the Network to get
  • callback – Listener whose com.android.volley.Response.Listener.onResponse(Object) is called with the NetworkResponse created by the query.

networkEvents

static void networkEvents(RequestQueue queue, long id, String maxId, Response.Listener<NetworkResponse<List<Event>>> listener)

Get the Events corresponding to a Network

Parameters:
  • queue – Queue to which the asynchronous task will be added
  • id – ID of the Network whose Events will be fetched
  • listener – Listener whose com.android.volley.Response.Listener.onResponse(Object) is called with the NetworkResponse created by the query.

networkPostCount

static void networkPostCount(RequestQueue queue, long id, Response.Listener<NetworkResponse<Long>> listener)

Get the number of org.codethechange.culturemesh.models.Posts that are currently on a Network

Parameters:

networkPosts

static void networkPosts(RequestQueue queue, long id, String maxId, Response.Listener<NetworkResponse<List<org.codethechange.culturemesh.models.Post>>> listener)

Get the org.codethechange.culturemesh.models.Posts of a Network

Parameters:

networkUserCount

static void networkUserCount(RequestQueue queue, long id, Response.Listener<NetworkResponse<Long>> listener)

Get the number of Users who are currently members of a Network

Parameters:
  • queue – Queue to which the asynchronous task will be added
  • id – ID of the Network whose User count will be retrieved
  • listener – Listener whose Response.Listener.onResponse(Object) is called with a NetworkResponse that stores the result of the network request

networkUsers

static void networkUsers(RequestQueue queue, long id, Response.Listener<NetworkResponse<ArrayList<User>>> listener)

Get all the Users who are members of a Network

Parameters:
  • queue – Queue to which the asynchronous task will be added
  • id – ID of the Network whose users will be fetched
  • listener – Listener whose com.android.volley.Response.Listener.onResponse(Object) is called with the NetworkResponse created by the query.

post

static void post(RequestQueue queue, long id, Response.Listener<NetworkResponse<org.codethechange.culturemesh.models.Post>> callback)

Get a org.codethechange.culturemesh.models.Post from it’s ID

Parameters:

postReplies

static void postReplies(RequestQueue queue, long id, Response.Listener<NetworkResponse<ArrayList<PostReply>>> listener)

Fetch the comments of a post.

Parameters:
  • queue – The RequestQueue to house the network requests.
  • id – the id of the post that we want comments for.
  • listener – the listener that we will call when the request is finished.

user

static void user(RequestQueue queue, long id, Response.Listener<NetworkResponse<User>> listener)

Get a User object from it’s ID

Parameters:
  • id – ID of user to find
Returns:

If such a user was found, it will be the payload. Otherwise, the request will be marked as failed.

userEvents

static void userEvents(RequestQueue queue, long id, String role, Response.Listener<NetworkResponse<ArrayList<org.codethechange.culturemesh.models.Event>>> listener)

Get the Events a User is subscribed to.

Parameters:
  • queue – Queue to which the asynchronous task is added.
  • id – ID of the User whose events are being searched for
  • role – Either hosting or attending
  • listener – Listener whose onResponse method is called with the results of the task

userEventsForNetwork

static void userEventsForNetwork(RequestQueue queue, SharedPreferences settings, long networkId, Response.Listener<NetworkResponse<ArrayList<Event>>> listener)

Get the Events a User is subscribed to for a given Network.

Parameters:
  • queue – Queue to which the asynchronous task is added.
  • settings – SharedPreferences instance storing the token.
  • networkId – the id of the Network of interest.
  • listener – The response listener to be called when the request completes.

userID

static void userID(RequestQueue queue, String email, Response.Listener<NetworkResponse<Long>> listener)

Get the ID of a User from an email address. Errors are communicated via a failed NetworkResponse.

Parameters:
  • queue – Queue to which the asynchronous task will be added
  • email – Email of user whose ID to look up
  • listener – Listener whose onResponse method is called when the task has completed

userNetworks

static void userNetworks(RequestQueue queue, long id, Response.Listener<NetworkResponse<ArrayList<Network>>> listener)

Get the networks a user belongs to

Parameters:
  • queue – RequestQueue to which the asynchronous job will be added
  • id – ID of the user whose networks will be fetched
  • listener – Listener whose com.android.volley.Response.Listener.onResponse(Object) is called with a NetworkResponse of an ArrayList of Networks

userPosts

static void userPosts(RequestQueue queue, long id, Response.Listener<NetworkResponse<ArrayList<org.codethechange.culturemesh.models.Post>>> listener)

Get the org.codethechange.culturemesh.models.Posts a User has made.

Parameters:
  • queue – The RequestQueue that will house the network requests.
  • id – The id of the User.
  • listener – The listener that the UI will call when the request is finished.