Skip to content

Instantly share code, notes, and snippets.

@raviyadav4875
Created April 28, 2018 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raviyadav4875/f179284c10b79d76557374b29f309c5b to your computer and use it in GitHub Desktop.
Save raviyadav4875/f179284c10b79d76557374b29f309c5b to your computer and use it in GitHub Desktop.
WebApiRequest.java
package com.askfortrciks.volleywithgsondemo.volley;
import com.android.volley.AuthFailureError;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.StringRequest;
import java.util.HashMap;
import java.util.Map;
public class WebApiRequest extends StringRequest {
private Map<String, String> headers = new HashMap<String, String>();
private Map<String, String> params = new HashMap<String, String>();
public WebApiRequest(int method, String url, Listener<String> listener,
ErrorListener errorListener, String token) {
super(method, url, listener, errorListener);
if (token != null) {
this.headers.put("Cookie", token);
}
}
public WebApiRequest(int method, String url,
Listener<String> listener, ErrorListener errorListener) {
super(method, url, listener, errorListener);
}
public WebApiRequest(int method, String url, Listener<String> listener, ErrorListener errorListener,
String token, Map<String, String> params) {
super(method, url, listener, errorListener);
if (token != null && params != null) {
this.headers.put("Cookie", token);
this.params = params;
}
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return headers;
}
/**
* To add headers in any api request in the form of
* key and value
* @param title
* @param content
*/
public void setHeader(String title, String content) {
headers.put(title, content);
}
/**
* To add parameters in the api request
* @return
* @throws AuthFailureError
*/
@Override
protected Map<String, String> getParams() throws AuthFailureError {
return params;
}
public void setParam(String title, String content) {
params.put(title, content);
}
}
public class WebServicesConstant {
//Main Host Url to access apis
public static final String BASE_URL_APPLICATION="https://api.themoviedb.org/3/";
//Image urls
public static final String BASE_URL_IMAGE_ORIGINAL="https://image.tmdb.org/t/p/original";
public static final String BASE_URL_IMAGE_W_500="https://image.tmdb.org/t/p/w500";
//api key (Its my personal) you have to crate your own to avoid suspension of your account
public static final String API_KEY="23fc7389372548c592b1f08cb8a0dffe";
//api connections
public static final String MOVIE="movie/";
public static final String TOP_RATED="top_rated";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment