Inherits from NSObject
Declared in OlapicRestClient.h

Overview

The object in charge of connecting with the API

Instance Methods

addEntityToDetect:

Add a single entity name to the list of entities that should be detected on an API response.

- (void)addEntityToDetect:(NSString *)entity

Parameters

entity

The name of the entity.

Discussion

Example:

[[[OlapicSDK sharedOlapicSDK] rest] addEntityToDetect:@"streams:all"];

Declared In

OlapicRestClient.h

baseRequest:method:parameters:onSuccess:onFailure:headers:reconnect:

Do a basic request to the API server using a custom connection method, query string parameters and extra request headers. You can also use the reconnect flag to indicate that this is not a reconnection and that in case of failing, it should try the request again

- (void)baseRequest:(NSString *)URL method:(NSString *)method parameters:(NSDictionary *)parameters onSuccess:(void ( ^ ) ( id responseObject ))success onFailure:(void ( ^ ) ( NSError *error ))failure headers:(NSDictionary *)headers reconnect:(BOOL)reconnect

Parameters

URL

The API URL

method

The request method (For now, it only supports: GET, LINK and UNLINK)

parameters

Query string parameters

success

A callback block for when the connection is successfully done

failure

A callback block for when the connection fails

headers

A dictionary with extra request headers

reconnect

If the request is a reconnection. If YES, it won’t try to connect in case of failure

Availability

v1.0

Discussion

This method is used by get:…, link:… and unlink:…

Example:

NSMutableDictionary *headers = [[NSMutableDictionary alloc] init];
[headers setValue:@"Olapic" forKey:@"requestedBy"];
[[[OlapicSDK sharedOlapicSDK] rest] simpleRequest:@"//photorankapi-a.akamaihd.net/customers/{ID}/media/recent/"
                                    withMethod:@"GET"
                                    parameters:nil
                                    onSuccess:^(id responseObject){
                                        NSLog(@"Response: %@",responseObject);
                                    }
                                    onFailure:^(NSError *error){
                                        NSLog(@"Error: %@",error.description);
                                    } extraHeaders:headers reconnect:YES];

Declared In

OlapicRestClient.h

clearPreCache

Remove all entries from the Pre Cache.

- (void)clearPreCache

Declared In

OlapicRestClient.h

detectEmbeddedEntities

Check if the Rest client is detecting embedded entities on the API requests.

- (BOOL)detectEmbeddedEntities

Return Value

If the flag is ON or OFF.

Declared In

OlapicRestClient.h

detectEmbeddedEntities:

Set the Rest client to detect or not embedded entities on the API requests.

- (void)detectEmbeddedEntities:(BOOL)detect

Parameters

detect

Whether it should detect the entities or not.

Declared In

OlapicRestClient.h

get:parameters:onSuccess:onFailure:

Make a GET request. In case the request fails, it will get a new OAuth token and try it again

- (void)get:(NSString *)URL parameters:(NSDictionary *)parameters onSuccess:(void ( ^ ) ( id responseObject ))success onFailure:(void ( ^ ) ( NSError *error ))failure

Parameters

URL

The API URL

parameters

The parameters for the query string

success

A callback block for when the connection is successfully done

failure

A callback block for when the connection fails

Availability

v1.0

Discussion

Example:

[[[OlapicSDK sharedOlapicSDK] rest] get:@"//photorankapi-a.akamaihd.net/customers/{ID}/media/recent/"
                                    parameters:nil
                                    onSuccess:^(id responseObject){
                                        NSLog(@"Response: %@",responseObject);
                                    }
                                    onFailure:^(NSError *error){
                                        NSLog(@"Error: %@",error.description);
                                    }];

Declared In

OlapicRestClient.h

get:parameters:onSuccess:onFailure:extraHeaders:

Make a GET request with extra request headers. In case the request fails, it will get a new OAuth token and try it again

- (void)get:(NSString *)URL parameters:(NSDictionary *)parameters onSuccess:(void ( ^ ) ( id responseObject ))success onFailure:(void ( ^ ) ( NSError *error ))failure extraHeaders:(NSDictionary *)headers

Parameters

URL

The API URL

parameters

The parameters for the query string

success

A callback block for when the connection is successfully done

failure

A callback block for when the connection fails

headers

Extra headers for the request

Availability

v1.0

Discussion

Example:

NSMutableDictionary *headers = [[NSMutableDictionary alloc] init];
[headers setValue:@"Olapic" forKey:@"requestedBy"];
[[[OlapicSDK sharedOlapicSDK] rest] get:@"//photorankapi-a.akamaihd.net/customers/{ID}/media/recent/"
                                    parameters:nil
                                    onSuccess:^(id responseObject){
                                        NSLog(@"Response: %@",responseObject);
                                    }
                                    onFailure:^(NSError *error){
                                        NSLog(@"Error: %@",error.description);
                                    } extraHeaders:headers];

Declared In

OlapicRestClient.h

get:parameters:onSuccess:onFailure:extraHeaders:reconnect:

Make a GET request with extra request headers and set if it should try to reconnect with a new OAuth token if it fails. If reconnect is NO, it means that this is not a reconnection and it should try to do it again

- (void)get:(NSString *)URL parameters:(NSDictionary *)parameters onSuccess:(void ( ^ ) ( id responseObject ))success onFailure:(void ( ^ ) ( NSError *error ))failure extraHeaders:(NSDictionary *)headers reconnect:(BOOL)reconnect

Parameters

URL

The API URL

parameters

The parameters for the query string

success

A callback block for when the connection is successfully done

failure

A callback block for when the connection fails

headers

Extra headers for the request

reconnect

If the request is a reconnection. If YES, it won’t try to connect in case of failure

Availability

v1.0

Discussion

Example:

NSMutableDictionary *headers = [[NSMutableDictionary alloc] init];
[headers setValue:@"Olapic" forKey:@"requestedBy"];
[[[OlapicSDK sharedOlapicSDK] rest] get:@"//photorankapi-a.akamaihd.net/customers/{ID}/media/recent/"
                                    parameters:nil
                                    onSuccess:^(id responseObject){
                                        NSLog(@"Response: %@",responseObject);
                                    }
                                    onFailure:^(NSError *error){
                                        NSLog(@"Error: %@",error.description);
                                    } extraHeaders:headers reconnect:YES];

Declared In

OlapicRestClient.h

getData:parameters:onSuccess:onFailure:

Make a GET request, but get the result on NSData format. This can be used to load an image

- (void)getData:(NSString *)URL parameters:(NSDictionary *)parameters onSuccess:(void ( ^ ) ( NSData *responseData ))success onFailure:(void ( ^ ) ( NSError *error ))failure

Parameters

URL

The API URL

parameters

The parameters for the query string

success

A callback block for when the connection is successfully done

failure

A callback block for when the connection fails

Availability

v1.0

Discussion

Example:

[[[OlapicSDK sharedOlapicSDK] rest] getData:@"//photorankapi-a.akamaihd.net/sample.png"
                                    parameters:nil
                                    onSuccess:^(id responseObject){
                                        NSLog(@"Response: %@",responseObject);
                                    }
                                    onFailure:^(NSError *error){
                                        NSLog(@"Error: %@",error.description);
                                    }];

Declared In

OlapicRestClient.h

getDefaultParametersForBulkRequestsToTheAPI

Because the requests inside a bulk request batch don’t go through this class, they don’t have the default parameters required by the API, like version and such.

- (NSDictionary *)getDefaultParametersForBulkRequestsToTheAPI

Return Value

The default parameters

Availability

v1.0

Declared In

OlapicRestClient.h

getEndpointPatternForEmbeddedEntitiesDetection

Get the RegEx pattern for API request URL.

- (NSString *)getEndpointPatternForEmbeddedEntitiesDetection

Return Value

A RegEx pattern.

Declared In

OlapicRestClient.h

getEntitiesToDetect

Get the list of names for entities that should be detected on an API response.

- (NSArray *)getEntitiesToDetect

Return Value

A list of entities names.

Declared In

OlapicRestClient.h

getEntitiesToDetectPerEndpointPattern

Get the dictionary with the specific URL RegEx patterns for entities.

- (NSDictionary *)getEntitiesToDetectPerEndpointPattern

Return Value

A dicitionary where the keys are entities names and the values RegEx patterns for the URL.

Declared In

OlapicRestClient.h

getErrorFromResponseMetadata:

Generate a NSError object using a invalid response from the API

- (NSError *)getErrorFromResponseMetadata:(NSDictionary *)response

Parameters

response

The API response

Return Value

A NSError object with the response metadata as description

Availability

v1.0

Declared In

OlapicRestClient.h

getOperationManager

Get the AFNetworking operation manager

- (OlapicAFHTTPRequestOperationManager *)getOperationManager

Return Value

A new instance of the operation manager

Declared In

OlapicRestClient.h

getPreCache

Get the list of detected entities by their URLs.

- (NSDictionary *)getPreCache

Return Value

A dictionary with the entire contents of the Pre Cache.

Declared In

OlapicRestClient.h

getSDK

Get the OlapicSDK reference

- (OlapicSDK *)getSDK

Return Value

The OlapicSDK

Availability

v1.0

Declared In

OlapicRestClient.h

isValid:

Validate an API response (it will check for a 200 status)

- (BOOL)isValid:(NSDictionary *)request

Parameters

request

The API response

Return Value

If the response status is 200

Availability

v1.0

Declared In

OlapicRestClient.h

link:parameters:onSuccess:onFailure:extraHeaders:reconnect:

Make a LINK request to the API. In case the request fails, it will get a new OAuth token and try it again

- (void)link:(NSString *)URL parameters:(NSDictionary *)parameters onSuccess:(void ( ^ ) ( id responseObject ))success onFailure:(void ( ^ ) ( NSError *error ))failure extraHeaders:(NSDictionary *)headers reconnect:(BOOL)reconnect

Parameters

URL

The API URL

parameters

The parameters for the query string

success

A callback block for when the connection is successfully done

failure

A callback block for when the connection fails

headers

Extra headers for the request

reconnect

If the request is a reconnection. If YES, it won’t try to connect in case of failure

Availability

v1.0

Discussion

Example:

NSMutableDictionary *headers = [[NSMutableDictionary alloc] init];
[headers setValue:@"<stream-url>; rel=relation" forKey:@"requestedBy"];
[[[OlapicSDK sharedOlapicSDK] rest] link:@"//photorankapi-a.akamaihd.net/customers/{ID}/media/recent/"
                                    withMethod:@"GET"
                                    parameters:nil
                                    onSuccess:^(id responseObject){
                                        NSLog(@"Response: %@",responseObject);
                                    }
                                    onFailure:^(NSError *error){
                                        NSLog(@"Error: %@",error.description);
                                    } extraHeaders:headers reconnect:YES];

Declared In

OlapicRestClient.h

post:parameters:data:onSuccess:onFailure:

Make a POST Request. In case the request fails, it will get a new OAuth token and try it again

- (void)post:(NSString *)URL parameters:(NSDictionary *)parameters data:(NSArray *)data onSuccess:(void ( ^ ) ( id responseObject ))success onFailure:(void ( ^ ) ( NSError *error ))failure

Parameters

URL

The API URL

parameters

The parameters for the query string

data

A list of metadata information

success

A callback block for when the connection is successfully done

failure

A callback block for when the connection fails

Availability

v1.0

Discussion

Example:

[[[OlapicSDK sharedOlapicSDK] rest] post:@"//photorankapi-a.akamaihd.net/post"
                                    parameters:nil
                                    data:postData
                                    onSuccess:^(id responseObject){
                                        NSLog(@"Response: %@",responseObject);
                                    }
                                    onFailure:^(NSError *error){
                                        NSLog(@"Error: %@",error.description);
                                    }];

Declared In

OlapicRestClient.h

post:parameters:data:onSuccess:onFailure:onProgress:

Make a POST Request and track the connection progress. In case the request fails, it will get a new OAuth token and try it again

- (void)post:(NSString *)URL parameters:(NSDictionary *)parameters data:(NSArray *)data onSuccess:(void ( ^ ) ( id responseObject ))success onFailure:(void ( ^ ) ( NSError *error ))failure onProgress:(void ( ^ ) ( float progress ))progress

Parameters

URL

The API URL

parameters

The parameters for the query string

data

A list of metadata information

success

A callback block for when the connection is successfully done

failure

A callback block for when the connection fails

progress

A callback block that can be used to track the connection progress

Availability

v1.0

Discussion

Example:

[[[OlapicSDK sharedOlapicSDK] rest] post:@"//photorankapi-a.akamaihd.net/post"
                                    parameters:nil
                                    data:postData
                                    onSuccess:^(id responseObject){
                                        NSLog(@"Response: %@",responseObject);
                                    }
                                    onFailure:^(NSError *error){
                                        NSLog(@"Error: %@",error.description);
                                    }
                                    onProgress:^(float progress){
                                        NSLog(@"Progress: %%@",(progress/100));
                                    }];

Declared In

OlapicRestClient.h

post:parameters:data:onSuccess:onFailure:onProgress:reconnect:

Make a POST Request, track the connection progress and set if it should try to reconnect with a new OAuth token if it fails. If reconnect is NO, it means that this is not a reconnection and it should try to do it again

- (void)post:(NSString *)URL parameters:(NSDictionary *)parameters data:(NSArray *)data onSuccess:(void ( ^ ) ( id responseObject ))success onFailure:(void ( ^ ) ( NSError *error ))failure onProgress:(void ( ^ ) ( float progress ))progress reconnect:(BOOL)reconnect

Parameters

URL

The API URL

parameters

The parameters for the query string

data

A list of metadata information

success

A callback block for when the connection is successfully done

failure

A callback block for when the connection fails

progress

A callback block that can be used to track the connection progress

reconnect

If the request is a reconnection. If YES, it won’t try to connect in case of failure

Availability

v1.0

Discussion

Example:

[[[OlapicSDK sharedOlapicSDK] rest] post:@"//photorankapi-a.akamaihd.net/post"
                                    parameters:nil
                                    data:postData
                                    onSuccess:^(id responseObject){
                                        NSLog(@"Response: %@",responseObject);
                                    }
                                    onFailure:^(NSError *error){
                                        NSLog(@"Error: %@",error.description);
                                    }
                                    onProgress:^(float progress){
                                        NSLog(@"Progress: %%@",(progress/100));
                                    }];

Declared In

OlapicRestClient.h

postJSON:withContent:onSuccess:onFailure:

Make a POST request using a JSON object as request payload. This is a generic method and it won’t use the Olapic API OAuth parameters

- (void)postJSON:(NSString *)URL withContent:(NSDictionary *)content onSuccess:(void ( ^ ) ( id responseObject ))success onFailure:(void ( ^ ) ( NSError *error ))failure

Parameters

URL

The API URL

content

The object to be used as JSON

success

A callback block for when the connection is successfully done

failure

A callback block for when the connection fails

Availability

v1.0

Discussion

Example:

NSMutableDictinoary *JSON = [[NSMutableDictionary alloc] init];
[JSON setValue:@"value" forKey:@"key"];
[[[OlapicSDK sharedOlapicSDK] rest] postJSON:@"//photorankapi-a.akamaihd.net/json"
                                    withContent:JSON
                                    onSuccess:^(id responseObject){
                                        NSLog(@"Response: %@",responseObject);
                                    }
                                    onFailure:^(NSError *error){
                                        NSLog(@"Error: %@",error.description);
                                    }];

Declared In

OlapicRestClient.h

prepareMetadataForPOST:

Prepare a dictionary to be sent on a POST request

- (NSArray *)prepareMetadataForPOST:(NSDictionary *)metadata

Parameters

metadata

The information to prepare

Return Value

A list with the information ready

Availability

v1.0

Declared In

OlapicRestClient.h

setEndpointPatternForEmbeddedEntitiesDetection:

Set a RegEx pattern that will be used to evaluate an API request URL and see if it should detect embedded entities on the response or not.

- (void)setEndpointPatternForEmbeddedEntitiesDetection:(NSString *)endpoint

Parameters

endpoint

A RegEx pattern for the URL.

Discussion

Example:

[[[OlapicSDK sharedOlapicSDK] rest]
setEndpointPatternForEmbeddedEntitiesDetection:@"\\/(media|stream|users)\\/([0-9]+|recent)(?:\\?|)"];

Declared In

OlapicRestClient.h

setEntitiesToDetect:

Set a list of names for entities that should be detected on an API response.

- (void)setEntitiesToDetect:(NSArray *)properties

Parameters

properties

A list of entities names.

Discussion

Example:

NSArray *entities = [[NSArray alloc] initWithObjects:@"streams:all", @"categories:all", nil];
[[[OlapicSDK sharedOlapicSDK] rest] setEntitiesToDetect:entities];

Declared In

OlapicRestClient.h

setEntitiesToDetectPerEndpointPattern:

Set a dictionary with specific RegEx patterns for entities names, so, even if the main pattern matches, you can use this as an extra check for the entity.

- (void)setEntitiesToDetectPerEndpointPattern:(NSDictionary *)patterns

Parameters

patterns

A dicitionary where the keys are entities names and the values RegEx patterns for the URL.

Discussion

Example:

NSMutableDictionary *patterns = [[NSMutableDictionary alloc] init];
[patterns setValue:@"\\/(media|stream|users)\\/([0-9]+|recent)(?:\\?|)" forKey:@"streams:all"];
[patterns setValue:@"\\/media\\/([0-9]+)" forKey:@"media"];
[[[OlapicSDK sharedOlapicSDK] rest] setEntitiesToDetectPerEndpointPattern:patterns];

Declared In

OlapicRestClient.h

setEntityToDetect:forEndpointPattern:

Set a single entity to be detected only when the given RegEx pattern matches the API request URL.

- (void)setEntityToDetect:(NSString *)entity forEndpointPattern:(NSString *)pattern

Parameters

entity

The entity name.

pattern

The RegEx pattern to match.

Discussion

Example:

[[[OlapicSDK sharedOlapicSDK] rest] setEntityToDetect:@"media" forEndpointPattern:@"\\/media\\/([0-9]+)"];

Declared In

OlapicRestClient.h

unlink:parameters:onSuccess:onFailure:extraHeaders:reconnect:

Make a UNLINK request to the API. In case the request fails, it will get a new OAuth token and try it again

- (void)unlink:(NSString *)URL parameters:(NSDictionary *)parameters onSuccess:(void ( ^ ) ( id responseObject ))success onFailure:(void ( ^ ) ( NSError *error ))failure extraHeaders:(NSDictionary *)headers reconnect:(BOOL)reconnect

Parameters

URL

The API URL

parameters

The parameters for the query string

success

A callback block for when the connection is successfully done

failure

A callback block for when the connection fails

headers

Extra headers for the request

reconnect

If the request is a reconnection. If YES, it won’t try to connect in case of failure

Availability

v1.0

Discussion

Example:

NSMutableDictionary *headers = [[NSMutableDictionary alloc] init];
[headers setValue:@"<stream-url>; rel=relation" forKey:@"requestedBy"];
[[[OlapicSDK sharedOlapicSDK] rest] unlink:@"//photorankapi-a.akamaihd.net/customers/{ID}/media/recent/"
                                    withMethod:@"GET"
                                    parameters:nil
                                    onSuccess:^(id responseObject){
                                        NSLog(@"Response: %@",responseObject);
                                    }
                                    onFailure:^(NSError *error){
                                        NSLog(@"Error: %@",error.description);
                                    } extraHeaders:headers reconnect:YES];

Declared In

OlapicRestClient.h

usePreCacheForURL:

In case the Pre Cache (the place where the detected entities are stored) has an entry for a request that you already obtained or you don’t need anymore, you can use this method to remove the entry.

- (BOOL)usePreCacheForURL:(NSString *)URL

Parameters

URL

The API request URL.

Return Value

Whether the entry was ‘used’ or not.

Discussion

[[[OlapicSDK sharedOlapicSDK] rest] usePreCacheForURL:@"https://api.olapic.com/media/42"];

Declared In

OlapicRestClient.h