| 20 | import java.util.Map; |
| 21 | |
| 22 | public class GithubImpl implements Github { |
| 23 | |
| 24 | private final static String[] SCOPES = {"public_repo","repo", "user", "gist"}; |
| 25 | public final static String HTTPS = "https://"; |
| 26 | public final static String HOST = "api.github.com"; |
| 27 | public final static String URL_SPLITTER = "/"; |
| 28 | public final static String API_HOST = HTTPS + HOST + URL_SPLITTER; |
| 29 | |
| 30 | public final static String ACCEPT_JSON = "application/vnd.github.beta+json"; |
| 31 | public final static String ACCEPT_RAW = "application/vnd.github.VERSION.raw"; |
| 32 | public final static String AGENT_USER = "WeGit/1.0"; |
| 33 | public final static String TOKEN_NOTE = "WeGit APP Token"; |
| 34 | |
| 35 | public final static String CREATE_TOKEN = API_HOST + "authorizations"; // POST |
| 36 | public final static String LIST_TOKENS = API_HOST + "authorizations"; // GET |
| 37 | public final static String REMOVE_TOKEN = API_HOST + "authorizations" |
| 38 | + URL_SPLITTER; // DELETE |
| 39 | public final static String LOGIN_USER = API_HOST + "user"; |
| 40 | public final static String MY_FOLLOWERS = API_HOST + "user/followers"; |
| 41 | public final static String MY_FOLLOWERSINGS = API_HOST + "user/following"; |
| 42 | |
| 43 | public final static int DEFAULT_PAGE_SIZE = 10; |
| 44 | public final static String PAGE = "page"; |
| 45 | public final static String PER_PAGE = "per_page"; |
| 46 | |
| 47 | private String token = null; |
| 48 | private HttpKnife http; |
| 49 | private Context context; |
| 50 | private GithubError githubError; |
| 51 | private AuthError authError; |
| 52 | |
| 53 | |
| 54 | private final static int _422 = 422; //Sending invalid fields |
| 55 | private final static int _400 = 400; //Sending the wrong type of JSON;Sending invalid JSON |
| 56 | private final static int _401 = 401; //Bad credentials |
| 57 | private final static int _403 = 403; //Maximum number of login attempts exceeded. Please try again later. |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | public GithubImpl(Context context) { |
| 64 | this.context = context; |
| 65 | this.http = new HttpKnife(context); |
| 66 | githubError = new GithubError(context.getString(R.string.network_error)); |
| 67 | authError = new AuthError("Token 失效"); |
| 68 | } |
| 69 | |
| 70 | public void filterError(Response response) throws GithubError,AuthError{ |
| 71 | if (response.isSuccess() == false) |
| 72 | throw githubError; |
| 73 | if (response.statusCode() == _401) { |
| 74 | throw authError; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public String createToken(String username, String password) |
nothing calls this directly
no outgoing calls
no test coverage detected