[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge pull request #1 from Automattic/feature/add-ability-to-make-syn…
Browse files Browse the repository at this point in the history
…ch-calls

Use Volley native listeners instead our implementation
  • Loading branch information
roundhill committed Apr 2, 2014
2 parents 8480e3d + 8a876d2 commit 0b66055
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
19 changes: 8 additions & 11 deletions src/com/wordpress/rest/Oauth.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.wordpress.rest;

import android.util.Log;

import com.android.volley.Response;
import com.android.volley.ParseError;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.NetworkResponse;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;

import java.util.Map;
import java.util.HashMap;
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Response;
import com.android.volley.toolbox.HttpHeaderParser;

public class Oauth {

Expand Down
25 changes: 10 additions & 15 deletions src/com/wordpress/rest/RestClient.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.wordpress.rest;

import android.util.Log;
import android.content.Context;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;

import org.json.JSONObject;

import com.android.volley.Request.Method;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.JsonRequest;
import com.android.volley.Response.Listener;
import com.android.volley.Response.ErrorListener;
import com.android.volley.toolbox.Volley;
import com.android.volley.Request.Method;

import java.util.Map;
import java.net.URLEncoder;
import java.io.UnsupportedEncodingException;
import com.android.volley.Response.Listener;

public class RestClient {

Expand All @@ -33,18 +30,16 @@ public RestClient(RequestQueue queue, String token){
mAccessToken = token;
}

public RestRequest get(String path, RestRequest.Listener listener,
RestRequest.ErrorListener errorListener){
public RestRequest get(String path, Listener<JSONObject> listener, ErrorListener errorListener){
return makeRequest(Method.GET, getAbsoluteURL(path), null, listener, errorListener);
}

public RestRequest post(String path, Map<String,String> body, RestRequest.Listener listener,
RestRequest.ErrorListener errorListener){
public RestRequest post(String path, Map<String,String> body, Listener<JSONObject> listener, ErrorListener errorListener){
return makeRequest(Method.POST, getAbsoluteURL(path), body, listener, errorListener);
}

public RestRequest makeRequest(int method, String url, Map<String, String> params,
RestRequest.Listener listener, RestRequest.ErrorListener errorListener ){
Listener<JSONObject> listener, ErrorListener errorListener ){
RestRequest request = new RestRequest(method, url, params, listener, errorListener);
request.setUserAgent(mUserAgent);
request.setAccessToken(mAccessToken);
Expand Down
10 changes: 5 additions & 5 deletions src/com/wordpress/rest/RestRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public class RestRequest extends Request<JSONObject> {
public static final String REST_AUTHORIZATION_HEADER="Authorization";
public static final String REST_AUTHORIZATION_FORMAT="Bearer %s";

public interface Listener extends Response.Listener<JSONObject> {}
public interface ErrorListener extends Response.ErrorListener {}
public interface Listener extends Response.Listener<JSONObject> {} //This is just a shortcut for Response.Listener<JSONObject>
public interface ErrorListener extends Response.ErrorListener {} //This is just a shortcut for Response.ErrorListener

private final Listener mListener;
private final com.android.volley.Response.Listener<JSONObject> mListener;
private final Map<String,String> mParams;
private final Map<String,String> mHeaders = new HashMap<String,String>(2);
public RestRequest(int method, String url, Map<String, String> params, Listener listener,
ErrorListener errorListener){
public RestRequest(int method, String url, Map<String, String> params, com.android.volley.Response.Listener<JSONObject> listener,
com.android.volley.Response.ErrorListener errorListener){
super(method, url, errorListener);
mParams = params;
mListener = listener;
Expand Down

0 comments on commit 0b66055

Please sign in to comment.