-
Notifications
You must be signed in to change notification settings - Fork 460
IterableApiClient
Demonstrates an interable REST API client that loads paginated records (strings) thanks to an iterator
Inheritance
Implements
Iterable<RecordPage>
private static final RESPONSE_PAGE_SIZE
Integer
Inherited
TESTVISIBLE
The name of the Named Credential to use
protected namedCredentialName
String
Constructor accepting a named credential.
public IterableApiClient(String namedCredential)
Name | Type | Description |
---|---|---|
namedCredential | String | name of the Named Credential to use |
Returns an iterator on RecordPage (as required by the Iterable interface)
public Iterator<RecordPage> iterator()
Iterator<RecordPage>
Internal method that issues a REST request to read a record page
private RecordPage getRecordPage(Integer pageIndex)
Name | Type | Description |
---|---|---|
pageIndex | Integer |
RecordPage
A page with a list of records
Inherited
TESTVISIBLE
SUPPRESSWARNINGS
Omnibus callout method. This is the primary method for making a REST callout. Most of the other methods in this class serve as convient, syntactic sugar on this method.
protected HttpResponse makeApiCall(HttpVerb method, String path, String query, String body, Map<String,String> headers)
Name | Type | Description |
---|---|---|
method | HttpVerb | Enum HTTP verb to use. i.e. GET |
path | String | patch component of the callout url i.e. /services/data/v39.0/SObjects
|
query | String | Query portion of the URL i.e. ?q=SELECT Id FROM Account
|
body | String | JSON string representing the body of the callout in post/patch situations |
headers | Map<String,String> | A map<String,String> of headers to use while making this callout |
HttpResponse
Inherited
TESTVISIBLE
SUPPRESSWARNINGS
Makes an HTTP Callout to an api resource. Convienence method that assumes the Default Headers.
protected HttpResponse makeApiCall(HttpVerb method, String path, String query, String body)
Name | Type | Description |
---|---|---|
method | HttpVerb | HTTPVerb to use. See the enum above. |
path | String | Http path component of the URL. ie: /path/to/resource
|
query | String | Query component of the URL ie: after ?foo=bar
|
body | String | Body to send with this call. |
HttpResponse
Inherited
TESTVISIBLE
convenience version of makeApiCall without body param. Invokes omnibus version above, with blank body param and default headers.
protected HttpResponse makeApiCall(HttpVerb method, String path, String query)
Name | Type | Description |
---|---|---|
method | HttpVerb | HTTPVerb to use. See the enum above. |
path | String | Http path component of the URL. ie: /path/to/resource
|
query | String | Query component of the URL ie: after ?foo=bar
|
HttpResponse
Inherited
TESTVISIBLE
convenience version of makeApiCall without body or query params. Invokes omnibus version above, with blank body and query params
protected HttpResponse makeApiCall(HttpVerb method, String path)
Name | Type | Description |
---|---|---|
method | HttpVerb | HTTPVerb to use. See the enum above. |
path | String | Http path component of the URL. ie: /path/to/resource
|
HttpResponse
Inherited
TESTVISIBLE
convenience method for a GET Call that only requires a path
protected HttpResponse get(String path)
Name | Type | Description |
---|---|---|
path | String | Http path component of the URL. ie: /path/to/resource
|
HttpResponse
Inherited
TESTVISIBLE
convenience method for a GET Call that only requires a path and query
protected HttpResponse get(String path, String query)
Name | Type | Description |
---|---|---|
path | String | Http path component of the URL. ie: /path/to/resource
|
query | String | Query component of the URL ie: after ?foo=bar
|
HttpResponse
Inherited
TESTVISIBLE
convenience method for deleteing a resource based only on path
protected HttpResponse del(String path)
Name | Type | Description |
---|---|---|
path | String | Http path component of the URL. ie: /path/to/resource
|
HttpResponse
Inherited
TESTVISIBLE
convenience method for a Delete Call that only requires a path and query
protected HttpResponse del(String path, String query)
Name | Type | Description |
---|---|---|
path | String | Http path component of the URL. ie: /path/to/resource
|
query | String | Query component of the URL ie: after ?foo=bar
|
HttpResponse
Inherited
TESTVISIBLE
convenience method for a POST Call that only requires a path and body
protected HttpResponse post(String path, String body)
Name | Type | Description |
---|---|---|
path | String | Http path component of the URL. ie: /path/to/resource
|
body | String | JSON string to post |
HttpResponse
Inherited
TESTVISIBLE
convenience method for a POST Call that only requires a path, query and body
protected HttpResponse post(String path, String query, String body)
Name | Type | Description |
---|---|---|
path | String | Http path component of the URL. ie: /path/to/resource
|
query | String | Query component of the URL ie: after ?foo=bar
|
body | String | JSON string to post |
HttpResponse
Inherited
TESTVISIBLE
convenience method for a PUT Call that only requires a path and body
protected HttpResponse put(String path, String body)
Name | Type | Description |
---|---|---|
path | String | Http path component of the URL. ie: /path/to/resource
|
body | String | JSON string to post |
HttpResponse
Inherited
TESTVISIBLE
convenience method for a PUT Call that only requires a path, query and body
protected HttpResponse put(String path, String query, String body)
Name | Type | Description |
---|---|---|
path | String | Http path component of the URL. ie: /path/to/resource
|
query | String | Query component of the URL ie: after ?foo=bar
|
body | String | JSON string to post |
HttpResponse
Inherited
TESTVISIBLE
convenience method for a PATCH Call that only requires a path, query and body
protected HttpResponse patch(String path, String body)
Name | Type | Description |
---|---|---|
path | String | Http path component of the URL. ie: /path/to/resource
|
body | String | JSON string to post |
HttpResponse
Inherited
TESTVISIBLE
convenience method for a PATCH Call that only requires a path, query and body
protected HttpResponse patch(String path, String query, String body)
Name | Type | Description |
---|---|---|
path | String | Http path component of the URL. ie: /path/to/resource
|
query | String | Query component of the URL ie: after ?foo=bar
|
body | String | JSON string to post |
HttpResponse
Inherited
TESTVISIBLE
Ensures that the inputted string ends in a /
makes callouts more robust.
protected String ensureStringEndsInSlash(String resource)
Name | Type | Description |
---|---|---|
resource | String | string to ensure ends in /
|
String
inputted string with ,[object Object], if it didn't already end in one.
Inherited
SUPPRESSWARNINGS
A static wrapper for the main makeApiCall method
public static HttpResponse makeApiCall(String namedCredential, HttpVerb method, String path, String query, String body, Map<String,String> headers)
Name | Type | Description |
---|---|---|
namedCredential | String | The named credential to use |
method | HttpVerb | HTTPVerb enum value. See Enum above |
path | String | Http path component of the URL. ie: /path/to/resource
|
query | String | Query component of the URL ie: after ?foo=bar
|
body | String | JSON string to post |
headers | Map<String,String> | Map<String,String> representing outgoing Request |
headers |
HttpResponse
System.Debug(RestClient.makeApiCall('GoogleBooksAPI',
RestClient.HttpVerb.GET,
'volumes',
'q=salesforce',
'',
new Map<String,String>()));
Inherited
SUPPRESSWARNINGS
A static wrapper for the main makeApiCall method that assumes default headers.
public static HttpResponse makeApiCall(String namedCredential, HttpVerb method, String path, String query)
Name | Type | Description |
---|---|---|
namedCredential | String | The named credential to use |
method | HttpVerb | HTTPVerb enum value. See Enum above |
path | String | Http path component of the URL. ie: /path/to/resource
|
query | String | Query component of the URL ie: after ?foo=bar
|
HttpResponse
System.Debug(RestClient.makeApiCall('GoogleBooksAPI',
RestClient.HttpVerb.GET,
'volumes',
'q=salesforce'));
Inherited
A static wrapper for the main makeApiCall method where you only need the path
public static HttpResponse makeApiCall(String namedCredential, HttpVerb method, String path)
Name | Type | Description |
---|---|---|
namedCredential | String | The named credential to use |
method | HttpVerb | HTTPVerb enum value. See Enum above |
path | String | Http path component of the URL. ie: /path/to/resource
|
HttpResponse
System.Debug(RestClient.makeApiCall('GoogleBooksAPI',
RestClient.HttpVerb.GET,
'volumes'));
Public custom exception class
Custom Iterator used to navigate IterableApiClient responses as RecordPage. The iterator keeps track on the iteration state with currentPageIndex and totalRecordCount. It uses IterableApiClient to perform REST requests to load the record pages.
Implements
Iterator<RecordPage>
private client
private currentPageIndex
Integer
private totalRecordCount
Integer
private RecordPageIterator(IterableApiClient client)
Name | Type | Description |
---|---|---|
client | IterableApiClient |
public Boolean hasNext()
Boolean
public RecordPage next()
RecordPage
Public class used for JSON deserialization of record page response
private records
List<String>
private totalRecordCount
Integer
public List<String> getRecords()
List<String>