Skip to content

Commit

Permalink
Rename RestClientUtils#get to RestClientUtils#getWithLocale and creat…
Browse files Browse the repository at this point in the history
…e RestClientUtils#get without adding Locale parameter automatically
  • Loading branch information
RenanLukas committed Mar 13, 2024
1 parent 2f25490 commit 36a4ce7
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class RecommendApiCallsProvider @Inject constructor(
cont.resume(Failure(errorMessage))
}

restClientProvider.getRestClientUtilsV2().get(
restClientProvider.getRestClientUtilsV2().getWithLocale(
endPointPath,
listener,
errorListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void getPushNotificationSettings(Context context, RestRequest.List
if (!TextUtils.isEmpty(deviceID)) {
settingsEndpoint += "?device_id=" + deviceID;
}
WordPress.getRestClientUtilsV1_1().get(settingsEndpoint, listener, errorListener);
WordPress.getRestClientUtilsV1_1().getWithLocale(settingsEndpoint, listener, errorListener);
}

public static void registerDeviceForPushNotifications(final Context ctx, String token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class InviteLinksApiCallsProvider @Inject constructor(
cont.resume(Failure(error))
}

WordPress.getRestClientUtilsV1_1().get(
WordPress.getRestClientUtilsV1_1().getWithLocale(
endPointPath,
listener,
errorListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void onErrorResponse(VolleyError volleyError) {
params.put("order_by", "display_name");
params.put("order", "ASC");
String path = String.format(Locale.US, "sites/%d/users", site.getSiteId());
WordPress.getRestClientUtilsV1_1().get(path, params, null, listener, errorListener);
WordPress.getRestClientUtilsV1_1().getWithLocale(path, params, null, listener, errorListener);
}

public static void fetchAuthors(final SiteModel site, final int offset, final FetchUsersCallback callback) {
Expand Down Expand Up @@ -95,7 +95,7 @@ public static void fetchAuthors(final SiteModel site, final int offset, final Fe
params.put("order", "ASC");
params.put("authors_only", "true");
String path = String.format(Locale.US, "sites/%d/users", site.getSiteId());
WordPress.getRestClientUtilsV1_1().get(path, params, null, listener, errorListener);
WordPress.getRestClientUtilsV1_1().getWithLocale(path, params, null, listener, errorListener);
}

public static void fetchRevisionAuthorsDetails(final SiteModel site, List<String> authors,
Expand Down Expand Up @@ -144,7 +144,7 @@ public void onErrorResponse(VolleyError volleyError) {
site.getSiteId(), authors.get(i)));
}

WordPress.getRestClientUtilsV1_1().get("batch/", batchParams, null, listener, errorListener);
WordPress.getRestClientUtilsV1_1().getWithLocale("batch/", batchParams, null, listener, errorListener);
}

public static void fetchFollowers(final SiteModel site, final int page, final FetchFollowersCallback callback) {
Expand Down Expand Up @@ -195,7 +195,7 @@ public void onErrorResponse(VolleyError volleyError) {
params.put("page", Integer.toString(page));
params.put("type", isEmailFollower ? "email" : "wp_com");
String path = String.format(Locale.US, "sites/%d/stats/followers", site.getSiteId());
WordPress.getRestClientUtilsV1_1().get(path, params, null, listener, errorListener);
WordPress.getRestClientUtilsV1_1().getWithLocale(path, params, null, listener, errorListener);
}

public static void fetchViewers(final SiteModel site, final int offset, final FetchViewersCallback callback) {
Expand Down Expand Up @@ -233,7 +233,7 @@ public void onErrorResponse(VolleyError volleyError) {
params.put("number", Integer.toString(FETCH_LIMIT));
params.put("page", Integer.toString(page));
String path = String.format(Locale.US, "sites/%d/viewers", site.getSiteId());
WordPress.getRestClientUtilsV1_1().get(path, params, null, listener, errorListener);
WordPress.getRestClientUtilsV1_1().getWithLocale(path, params, null, listener, errorListener);
}

public static void updateRole(final SiteModel site, long personID, String newRole, final int localTableBlogId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void onErrorResponse(VolleyError volleyError) {
};

String path = "/me/keyring-connections";
WordPress.getRestClientUtilsV1_1().get(path, listener, errorListener);
WordPress.getRestClientUtilsV1_1().getWithLocale(path, listener, errorListener);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PublicizeUpdateServicesV2 @Inject constructor(
}
val errorListener = RestRequest.ErrorListener { volleyError -> failure(volleyError) }
val path = "sites/$siteId/external-services?type=publicize"
restClientProvider.getRestClientUtilsV2().get(path, listener, errorListener)
restClientProvider.getRestClientUtilsV2().getWithLocale(path, listener, errorListener)
}

/*
Expand All @@ -45,6 +45,6 @@ class PublicizeUpdateServicesV2 @Inject constructor(
}
val errorListener = RestRequest.ErrorListener { volleyError -> failure(volleyError) }
val path = String.format(Locale.ROOT, "sites/%d/publicize-connections", siteId)
restClientProvider.getRestClientUtilsV1_1().get(path, listener, errorListener)
restClientProvider.getRestClientUtilsV1_1().getWithLocale(path, listener, errorListener)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,10 @@ public void onErrorResponse(VolleyError volleyError) {
};

if (hasBlogId) {
WordPress.getRestClientUtilsV1_1().get("read/sites/" + blogId, listener, errorListener);
WordPress.getRestClientUtilsV1_1().getWithLocale("read/sites/" + blogId, listener, errorListener);
} else {
WordPress.getRestClientUtilsV1_1()
.get("read/sites/" + UrlUtils.urlEncode(UrlUtils.getHost(blogUrl)), listener, errorListener);
.getWithLocale("read/sites/" + UrlUtils.urlEncode(UrlUtils.getHost(blogUrl)), listener, errorListener);
}
}

Expand Down Expand Up @@ -438,7 +438,7 @@ public void onErrorResponse(VolleyError volleyError) {
} else {
path = "read/feed/" + UrlUtils.urlEncode(feedUrl);
}
WordPress.getRestClientUtilsV1_1().get(path, listener, errorListener);
WordPress.getRestClientUtilsV1_1().getWithLocale(path, listener, errorListener);
}

private static void handleUpdateBlogInfoResponse(JSONObject jsonObject, UpdateBlogInfoListener infoListener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void onErrorResponse(VolleyError volleyError) {
}
};
AppLog.d(T.READER, "updating post");
WordPress.getRestClientUtilsV1_2().get(path, null, null, listener, errorListener);
WordPress.getRestClientUtilsV1_2().getWithLocale(path, null, null, listener, errorListener);
}

private static void handleUpdatePostResponse(@NonNull final ReaderPost localPost,
Expand Down Expand Up @@ -320,7 +320,7 @@ public void onErrorResponse(VolleyError volleyError) {
};

AppLog.d(T.READER, "requesting post");
restClientUtils.get(path, null, null, listener, errorListener);
restClientUtils.getWithLocale(path, null, null, listener, errorListener);
}

private static String getTrackingPixelForPost(@NonNull ReaderPost post) {
Expand Down Expand Up @@ -417,7 +417,7 @@ public void onErrorResponse(VolleyError volleyError) {
+ "?size_local=" + NUM_RELATED_POSTS_TO_REQUEST
+ "&size_global=" + NUM_RELATED_POSTS_TO_REQUEST
+ "&fields=" + ReaderSimplePost.SIMPLE_POST_FIELDS;
WordPress.getRestClientUtilsV1_2().get(path, null, null, listener, errorListener);
WordPress.getRestClientUtilsV1_2().getWithLocale(path, null, null, listener, errorListener);
}

private static void handleRelatedPostsResponse(final ReaderPost sourcePost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void onErrorResponse(VolleyError volleyError) {
}
};
AppLog.d(AppLog.T.READER, "updating comments");
WordPress.getRestClientUtilsV1_1().get(path, null, null, listener, errorListener);
WordPress.getRestClientUtilsV1_1().getWithLocale(path, null, null, listener, errorListener);
}

private static void handleUpdateCommentsResponse(final JSONObject jsonObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class ReaderDiscoverLogic @Inject constructor(
} else {
"read/tags/cards"
}
WordPress.getRestClientUtilsV2()[endpoint, params, null, listener, errorListener]
WordPress.getRestClientUtilsV2().getWithLocale(endpoint, params, null, listener, errorListener)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void onErrorResponse(VolleyError volleyError) {
}
};

WordPress.getRestClientUtilsV1_2().get(sb.toString(), null, null, listener, errorListener);
WordPress.getRestClientUtilsV1_2().getWithLocale(sb.toString(), null, null, listener, errorListener);
}

private static void requestPostsForBlog(final long blogId,
Expand Down Expand Up @@ -174,7 +174,7 @@ public void onErrorResponse(VolleyError volleyError) {
}
};
AppLog.d(AppLog.T.READER, "updating posts in blog " + blogId);
WordPress.getRestClientUtilsV1_2().get(path, null, null, listener, errorListener);
WordPress.getRestClientUtilsV1_2().getWithLocale(path, null, null, listener, errorListener);
}

private static void requestPostsForFeed(final long feedId,
Expand Down Expand Up @@ -203,7 +203,7 @@ public void onErrorResponse(VolleyError volleyError) {
};

AppLog.d(AppLog.T.READER, "updating posts in feed " + feedId);
WordPress.getRestClientUtilsV1_2().get(path, null, null, listener, errorListener);
WordPress.getRestClientUtilsV1_2().getWithLocale(path, null, null, listener, errorListener);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void onErrorResponse(VolleyError volleyError) {

AppLog.d(AppLog.T.READER, "reader search service > starting search for " + query);
EventBus.getDefault().post(new ReaderEvents.SearchPostsStarted(query, offset));
WordPress.getRestClientUtilsV1_2().get(path, null, null, listener, errorListener);
WordPress.getRestClientUtilsV1_2().getWithLocale(path, null, null, listener, errorListener);
}

private void handleSearchResponse(final String query, final int offset, final JSONObject jsonObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void onErrorResponse(VolleyError volleyError) {
HashMap<String, String> params = new HashMap<>();
params.put("locale", mLanguage);
mClientUtilsProvider.getRestClientForTagUpdate()
.get("read/menu", params, null, listener, errorListener);
.getWithLocale("read/menu", params, null, listener, errorListener);
}

/**
Expand Down Expand Up @@ -279,7 +279,7 @@ private void fetchInterestTags() {
HashMap<String, String> params = new HashMap<>();
params.put("_locale", mLanguage);
mClientUtilsProvider.getRestClientForInterestTags()
.get("read/interests", params, null, listener, errorListener);
.getWithLocale("read/interests", params, null, listener, errorListener);
}

private void handleInterestTagsResponse(final JSONObject jsonObject) {
Expand Down Expand Up @@ -316,7 +316,7 @@ public void onErrorResponse(VolleyError volleyError) {
AppLog.d(AppLog.T.READER, "reader service > updating followed blogs. Page requested: " + page);
// request using ?meta=site,feed to get extra info
WordPress.getRestClientUtilsV1_2()
.get("read/following/mine?number=100&page=" + page + "&meta=site%2Cfeed", listener, errorListener);
.getWithLocale("read/following/mine?number=100&page=" + page + "&meta=site%2Cfeed", listener, errorListener);
}

private void handleFollowedBlogsResponse(final ReaderBlogList serverBlogs, final JSONObject jsonObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PostSubscribersApiCallsProvider @Inject constructor(
cont.resume(false)
}

WordPress.getRestClientUtilsV1_1().get(
WordPress.getRestClientUtilsV1_1().getWithLocale(
endPointPath,
listener,
errorListener
Expand All @@ -64,7 +64,7 @@ class PostSubscribersApiCallsProvider @Inject constructor(
cont.resume(Failure(error))
}

WordPress.getRestClientUtilsV1_1().get(
WordPress.getRestClientUtilsV1_1().getWithLocale(
endPointPath,
listener,
errorListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void updateSuggestions(final long siteId) {

AppLog.d(AppLog.T.SUGGESTION, "suggestion service > updating suggestions for siteId: " + siteId);
String path = "/users/suggest" + "?site_id=" + siteId;
WordPress.getRestClientUtils().get(path, listener, errorListener);
WordPress.getRestClientUtils().getWithLocale(path, listener, errorListener);
}

private void handleSuggestionsUpdatedResponse(final long siteId, final JSONObject jsonObject) {
Expand Down Expand Up @@ -136,7 +136,7 @@ private void updateTags(final long siteId) {

AppLog.d(AppLog.T.SUGGESTION, "suggestion service > updating tags for siteId: " + siteId);
String path = "/sites/" + siteId + "/tags";
WordPress.getRestClientUtils().get(path, listener, errorListener);
WordPress.getRestClientUtils().getWithLocale(path, listener, errorListener);
}

private void handleTagsUpdatedResponse(final long siteId, final JSONObject jsonObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public RestClient getRestClient() {

public void getCategories(long siteId, Listener listener, ErrorListener errorListener) {
String path = String.format(Locale.US, "sites/%d/categories", siteId);
get(path, null, null, listener, errorListener);
getWithLocale(path, null, null, listener, errorListener);
}

/**
Expand All @@ -112,7 +112,7 @@ public void getCategories(long siteId, Listener listener, ErrorListener errorLis
* <a href="https://developer.wordpress.com/docs/api/1/get/notifications/">api/1/get/notifications</a>
*/
public void getNotifications(Map<String, String> params, Listener listener, ErrorListener errorListener) {
get("notifications", params, null, listener, errorListener);
getWithLocale("notifications", params, null, listener, errorListener);
}

/**
Expand All @@ -123,7 +123,7 @@ public void getNotification(Map<String, String> params, String noteId,
Listener listener, ErrorListener errorListener) {
params.put("fields", NOTIFICATION_FIELDS);
String path = String.format(Locale.US, "notifications/%s/", noteId);
get(path, params, null, listener, errorListener);
getWithLocale(path, params, null, listener, errorListener);
}

/**
Expand All @@ -135,7 +135,7 @@ public void getNotification(String noteId, Listener listener, ErrorListener erro
HashMap<String, String> params = new HashMap<>();
params.put("fields", NOTIFICATION_FIELDS);
String path = String.format("notifications/%s", noteId);
get(path, params, null, listener, errorListener);
getWithLocale(path, params, null, listener, errorListener);
}

/**
Expand Down Expand Up @@ -166,23 +166,23 @@ public void decrementUnreadCount(String noteId, String decrementAmount,

public void getJetpackSettings(long siteId, Listener listener, ErrorListener errorListener) {
String path = String.format(Locale.US, "jetpack-blogs/%d/rest-api/?path=/jetpack/v4/settings", siteId);
get(path, listener, errorListener);
getWithLocale(path, listener, errorListener);
}

public void getGeneralSettings(long siteId, Listener listener, ErrorListener errorListener) {
String path = String.format(Locale.US, "sites/%d/settings", siteId);
get(path, listener, errorListener);
getWithLocale(path, listener, errorListener);
}

public void getJetpackMonitorSettings(long siteId, Listener listener, ErrorListener errorListener) {
String path = String.format(Locale.US, "jetpack-blogs/%d", siteId);
get(path, listener, errorListener);
getWithLocale(path, listener, errorListener);
}


public void getJetpackModuleSettings(long siteId, Listener listener, ErrorListener errorListener) {
String path = String.format(Locale.US, "sites/%d/jetpack/modules", siteId);
get(path, listener, errorListener);
getWithLocale(path, listener, errorListener);
}

public void setGeneralSiteSettings(long siteId, JSONObject params, Listener listener, ErrorListener errorListener) {
Expand Down Expand Up @@ -228,7 +228,7 @@ public void setJetpackModuleSettings(long siteId, String module, boolean active,

public void getSitePurchases(long siteId, Listener listener, ErrorListener errorListener) {
String path = String.format(Locale.US, "sites/%d/purchases", siteId);
get(path, listener, errorListener);
getWithLocale(path, listener, errorListener);
}

public void exportContentAll(long siteId, Listener listener, ErrorListener errorListener) {
Expand All @@ -238,7 +238,7 @@ public void exportContentAll(long siteId, Listener listener, ErrorListener error

public void getSharingButtons(String siteId, Listener listener, ErrorListener errorListener) {
String path = String.format("sites/%s/sharing-buttons", siteId);
get(path, listener, errorListener);
getWithLocale(path, listener, errorListener);
}

public void setSharingButtons(String siteId, JSONObject params, Listener listener, ErrorListener errorListener) {
Expand All @@ -249,29 +249,38 @@ public void setSharingButtons(String siteId, JSONObject params, Listener listene
/**
* Make GET request
*/
public Request<JSONObject> get(String path, Listener listener, ErrorListener errorListener) {
return get(path, null, null, listener, errorListener);
public Request<JSONObject> getWithLocale(final String path, final Listener listener,
final ErrorListener errorListener) {
return getWithLocale(path, null, null, listener, errorListener);
}

/**
* Make GET request with params
* Make GET request with params. Locale param is added automatically.
*/
public Request<JSONObject> get(String path, Map<String, String> params, RetryPolicy retryPolicy, Listener listener,
ErrorListener errorListener) {
public Request<JSONObject> getWithLocale(final String path, final Map<String, String> params,
RetryPolicy retryPolicy, final Listener listener,
final ErrorListener errorListener) {
// turn params into query string
HashMap<String, String> paramsWithLocale = getRestLocaleParams(mContext);
if (params != null) {
paramsWithLocale.putAll(params);
}
return get(path, paramsWithLocale, retryPolicy, listener, errorListener);
}

/**
* Make GET request with params.
*/
public Request<JSONObject> get(final String path, final Map<String, String> params, RetryPolicy retryPolicy,
final Listener listener, final ErrorListener errorListener) {
String realPath = getSanitizedPath(path);
if (TextUtils.isEmpty(realPath)) {
realPath = path;
}
paramsWithLocale.putAll(getSanitizedParameters(path));
params.putAll(getSanitizedParameters(path));

RestRequest request = mRestClient.makeRequest(Method.GET, mRestClient
.getAbsoluteURL(realPath, paramsWithLocale), null, listener, errorListener);
.getAbsoluteURL(realPath, params), null, listener, errorListener);

if (retryPolicy == null) {
retryPolicy = new DefaultRetryPolicy(REST_TIMEOUT_MS, REST_MAX_RETRIES_GET, REST_BACKOFF_MULT);
Expand Down

0 comments on commit 36a4ce7

Please sign in to comment.