public static boolean downloadFile(final String url, final File out) { return downloadFile(url, out, null); }
private static String performCall(final URL url, final String method, final String data) { return performCall(url, method, data, null); }
public static String performCall(final String url, final String method, final HashMap<String, String> params) { try { return performCall(new URL(url), method, encodeQuery(params)); } catch (UnsupportedEncodingException | MalformedURLException e) { e.printStackTrace(); } return ""; }
public static CompleteAuthenticationResult completeGitHubAuth(SlAppSettings appSettings, String clientId, String clientSecret, String code) { final HashMap<String, String> map = new HashMap<>(); map.put("client_id", clientId); map.put("client_secret", clientSecret); map.put("code", code); CompleteAuthenticationResult ret = new CompleteAuthenticationResult(); HashMap<String, String> postResult = NetworkUtils.getDataMap( NetworkUtils.performCall(GITHUB_COMPLETE_AUTH_URL, NetworkUtils.POST, map) ); if (postResult.containsKey("error")) { ret.message = postResult.get("error_description"); } else { ret.token = postResult.get("access_token"); ret.grantedScopes = postResult.get("scope"); appSettings.setGitHubAccess(ret.token, ret.grantedScopes); if (appSettings.hasGitHubAuthorization()) { ret.ok = true; } } return ret; } }
public static String performCall(final String url, final JSONObject json) { return performCall(url, POST, json); }
public static boolean downloadFile(final URL url, final File outFile, final Callback.a1<Float> progressCallback) { return downloadFile(url, outFile, null, progressCallback); }
public static String performCall(final String url, final String method, final String data) { try { return performCall(new URL(url), method, data); } catch (MalformedURLException e) { e.printStackTrace(); } return ""; }
public static boolean downloadFile(final String url, final File out, final Callback.a1<Float> progressCallback) { try { return downloadFile(new URL(url), out, progressCallback); } catch (MalformedURLException e) { // Won't happen e.printStackTrace(); return false; } }
public static String performCall(final String url, final String method) { try { return performCall(new URL(url), method, ""); } catch (MalformedURLException e) { e.printStackTrace(); } return ""; }
if (!NetworkUtils.downloadFile(url, f)) mMemoryCache.clear();
public static String performCall(final String url, final String method, final JSONObject json) { try { return performCall(new URL(url), method, json.toString()); } catch (MalformedURLException e) { e.printStackTrace(); } return ""; }
public boolean syncRepo(final Messenger.OnSyncProgress callback) { NetworkUtils.downloadFile(FDROID_INDEX_URL, getIndexFile("jar"), new Callback.a1<Float>() { @Override public void callback(Float progress) {
public void run() { // Returns a simple result, handleable without json parser {"key":"feediyujiq"} String ret = NetworkUtils.performCall(server + "/documents", NetworkUtils.POST, text); final String key = (ret.length() > 15) ? ret.split("\"")[3] : ""; handler.post(() -> callback.callback(!key.isEmpty(), server + "/" + key)); } }.start();
private static JSONObject getUserInfo(String token) { try { return new JSONObject(NetworkUtils.performCall(getUrl( "user?access_token=%s", token), NetworkUtils.GET)); } catch (JSONException e) { e.printStackTrace(); return null; } }
public static String getDefaultBranch(final RepoHandler repo) { try { JSONObject result = new JSONObject(NetworkUtils.performCall(getUrl( "repos/%s", repo.toOwnerRepo()), NetworkUtils.GET)); return result.getString("default_branch"); } catch (JSONException | InvalidObjectException e) { e.printStackTrace(); return null; } }
public static JSONArray getBranches(final RepoHandler repo) { try { return new JSONArray(NetworkUtils.performCall(getUrl( "repos/%s/branches", repo.toOwnerRepo()), NetworkUtils.GET)); } catch (JSONException | InvalidObjectException e) { e.printStackTrace(); return null; } }
public static JSONObject createIssue(RepoHandler repo, String title, String description, String token) throws InvalidObjectException { try { JSONObject params = new JSONObject(); params.put("title", title); params.put("body", description); return new JSONObject(NetworkUtils.performCall(getUrl("repos/%s/issues?access_token=%s", repo.toOwnerRepo(), token), params)); } catch (JSONException e) { e.printStackTrace(); return null; } }
public static JSONObject commentIssue(RepoHandler repo, int issueNumber, String body, String token) throws InvalidObjectException { try { JSONObject params = new JSONObject(); params.put("body", body); return new JSONObject(NetworkUtils.performCall(getUrl( "repos/%s/issues/%d/comments?access_token=%s", repo.toOwnerRepo(), issueNumber, token), params)); } catch (JSONException e) { e.printStackTrace(); return null; } }
private static JSONArray getCommits(final String token, final RepoHandler repo) throws InvalidObjectException { try { return new JSONArray(NetworkUtils.performCall(getUrl( "repos/%s/commits?access_token=%s", repo.toOwnerRepo(), token), NetworkUtils.GET)); } catch (JSONException e) { e.printStackTrace(); return null; } }
public static JSONObject createPullRequest(final String token, final RepoHandler originalRepo, final String title, final String head, final String base, final String body) throws InvalidObjectException { try { JSONObject params = new JSONObject(); params.put("title", title); params.put("head", head); params.put("base", base); if (body != null && !body.isEmpty()) params.put("body", body); return new JSONObject(NetworkUtils.performCall(getUrl( "repos/%s/pulls?access_token=%s", originalRepo.toOwnerRepo(), token), params)); } catch (JSONException e) { e.printStackTrace(); return null; } }