Skip to content

Commit

Permalink
#80 fix pagination for certian methods
Browse files Browse the repository at this point in the history
- getAvailableRegions
- getAvailableSizes
- getAvailableDomains
- getAvailableKeys
  • Loading branch information
jeevatkm committed Apr 26, 2018
1 parent 29c3afc commit 44d9f6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public interface Constants {
// HTTP Param name
String PARAM_PAGE_NO = "page";
String PARAM_PER_PAGE = "per_page";
int DEFAULT_PAGE_SIZE = 25; // per DO doc

String NO_CONTENT_JSON_STRUCT = "{\"response\": {\"request_status\": true, \"status_code\": %s}}";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ public Action convertImage(Integer imageId) throws DigitalOceanException,
public Regions getAvailableRegions(Integer pageNo) throws DigitalOceanException,
RequestUnsuccessfulException {
validatePageNo(pageNo);
return (Regions) perform(new ApiRequest(ApiAction.AVAILABLE_REGIONS, pageNo)).getData();
return (Regions) perform(new ApiRequest(ApiAction.AVAILABLE_REGIONS, pageNo, DEFAULT_PAGE_SIZE)).getData();
}

// =======================================
Expand All @@ -782,7 +782,7 @@ public Regions getAvailableRegions(Integer pageNo) throws DigitalOceanException,
public Sizes getAvailableSizes(Integer pageNo) throws DigitalOceanException,
RequestUnsuccessfulException {
validatePageNo(pageNo);
return (Sizes) perform(new ApiRequest(ApiAction.AVAILABLE_SIZES, pageNo)).getData();
return (Sizes) perform(new ApiRequest(ApiAction.AVAILABLE_SIZES, pageNo, DEFAULT_PAGE_SIZE)).getData();
}

// =======================================
Expand All @@ -792,7 +792,7 @@ public Sizes getAvailableSizes(Integer pageNo) throws DigitalOceanException,
@Override
public Domains getAvailableDomains(Integer pageNo) throws DigitalOceanException,
RequestUnsuccessfulException {
return (Domains) perform(new ApiRequest(ApiAction.AVAILABLE_DOMAINS, pageNo)).getData();
return (Domains) perform(new ApiRequest(ApiAction.AVAILABLE_DOMAINS, pageNo,DEFAULT_PAGE_SIZE)).getData();
}

@Override
Expand Down Expand Up @@ -879,7 +879,7 @@ public Delete deleteDomainRecord(String domainName, Integer recordId)
@Override
public Keys getAvailableKeys(Integer pageNo) throws DigitalOceanException,
RequestUnsuccessfulException {
return (Keys) perform(new ApiRequest(ApiAction.AVAILABLE_KEYS, pageNo)).getData();
return (Keys) perform(new ApiRequest(ApiAction.AVAILABLE_KEYS, pageNo, DEFAULT_PAGE_SIZE)).getData();
}

@Override
Expand Down Expand Up @@ -1680,7 +1680,7 @@ private URI createUri(ApiRequest request) {

if (RequestMethod.GET == request.getMethod()) {
if (null == request.getPerPage()) {
ub.setParameter(PARAM_PER_PAGE, "25"); // As per DO documentation
ub.setParameter(PARAM_PER_PAGE, String.valueOf(DEFAULT_PAGE_SIZE)); // As per DO documentation
} else {
ub.setParameter(PARAM_PER_PAGE, request.getPerPage().toString());
}
Expand Down

0 comments on commit 44d9f6a

Please sign in to comment.