OlapicRestClient Class Reference
| Inherits from | NSObject |
| Declared in | OlapicRestClient.h |
Tasks
Detect Embedded Entities
-
– detectEmbeddedEntities: -
– detectEmbeddedEntities -
– setEndpointPatternForEmbeddedEntitiesDetection: -
– getEndpointPatternForEmbeddedEntitiesDetection -
– setEntitiesToDetect: -
– addEntityToDetect: -
– getEntitiesToDetect -
– setEntitiesToDetectPerEndpointPattern: -
– setEntityToDetect:forEndpointPattern: -
– getEntitiesToDetectPerEndpointPattern -
– usePreCacheForURL: -
– getPreCache -
– clearPreCache
GET
-
– get:parameters:onSuccess:onFailure: -
– get:parameters:onSuccess:onFailure:extraHeaders: -
– get:parameters:onSuccess:onFailure:extraHeaders:reconnect: -
– getData:parameters:onSuccess:onFailure:
POST
-
– post:parameters:data:onSuccess:onFailure: -
– post:parameters:data:onSuccess:onFailure:onProgress: -
– post:parameters:data:onSuccess:onFailure:onProgress:reconnect: -
– postJSON:withContent:onSuccess:onFailure:
LINK/UNLINK
-
– link:parameters:onSuccess:onFailure:extraHeaders:reconnect: -
– unlink:parameters:onSuccess:onFailure:extraHeaders:reconnect:
Base
Extras
Utils
Instance Methods
addEntityToDetect:
Add a single entity name to the list of entities that should be detected on an API response.
- (void)addEntityToDetect:(NSString *)entityParameters
- entity
The name of the entity.
Discussion
Example:
[[[OlapicSDK sharedOlapicSDK] rest] addEntityToDetect:@"streams:all"];
Declared In
OlapicRestClient.hbaseRequest: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)reconnectParameters
- 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.hclearPreCache
Remove all entries from the Pre Cache.
- (void)clearPreCacheDeclared In
OlapicRestClient.hdetectEmbeddedEntities
Check if the Rest client is detecting embedded entities on the API requests.
- (BOOL)detectEmbeddedEntitiesReturn Value
If the flag is ON or OFF.
Declared In
OlapicRestClient.hdetectEmbeddedEntities:
Set the Rest client to detect or not embedded entities on the API requests.
- (void)detectEmbeddedEntities:(BOOL)detectParameters
- detect
Whether it should detect the entities or not.
Declared In
OlapicRestClient.hget: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 ))failureParameters
- 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.hget: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 *)headersParameters
- 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.hget: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)reconnectParameters
- 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.hgetData: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 ))failureParameters
- 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.hgetDefaultParametersForBulkRequestsToTheAPI
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 *)getDefaultParametersForBulkRequestsToTheAPIReturn Value
The default parameters
Availability
v1.0
Declared In
OlapicRestClient.hgetEndpointPatternForEmbeddedEntitiesDetection
Get the RegEx pattern for API request URL.
- (NSString *)getEndpointPatternForEmbeddedEntitiesDetectionReturn Value
A RegEx pattern.
Declared In
OlapicRestClient.hgetEntitiesToDetect
Get the list of names for entities that should be detected on an API response.
- (NSArray *)getEntitiesToDetectReturn Value
A list of entities names.
Declared In
OlapicRestClient.hgetEntitiesToDetectPerEndpointPattern
Get the dictionary with the specific URL RegEx patterns for entities.
- (NSDictionary *)getEntitiesToDetectPerEndpointPatternReturn Value
A dicitionary where the keys are entities names and the values RegEx patterns for the URL.
Declared In
OlapicRestClient.hgetErrorFromResponseMetadata:
Generate a NSError object using a invalid response from the API
- (NSError *)getErrorFromResponseMetadata:(NSDictionary *)responseParameters
- response
The API response
Return Value
A NSError object with the response metadata as description
Availability
v1.0
Declared In
OlapicRestClient.hgetOperationManager
Get the AFNetworking operation manager
- (OlapicAFHTTPRequestOperationManager *)getOperationManagerReturn Value
A new instance of the operation manager
Declared In
OlapicRestClient.hgetPreCache
Get the list of detected entities by their URLs.
- (NSDictionary *)getPreCacheReturn Value
A dictionary with the entire contents of the Pre Cache.
Declared In
OlapicRestClient.hgetSDK
Get the OlapicSDK reference
- (OlapicSDK *)getSDKReturn Value
The OlapicSDK
Availability
v1.0
Declared In
OlapicRestClient.hisValid:
Validate an API response (it will check for a 200 status)
- (BOOL)isValid:(NSDictionary *)requestParameters
- request
The API response
Return Value
If the response status is 200
Availability
v1.0
Declared In
OlapicRestClient.hlink: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)reconnectParameters
- 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.hpost: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 ))failureParameters
- 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.hpost: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 ))progressParameters
- 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.hpost: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)reconnectParameters
- 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.hpostJSON: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 ))failureParameters
- 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.hprepareMetadataForPOST:
Prepare a dictionary to be sent on a POST request
- (NSArray *)prepareMetadataForPOST:(NSDictionary *)metadataParameters
- metadata
The information to prepare
Return Value
A list with the information ready
Availability
v1.0
Declared In
OlapicRestClient.hsetEndpointPatternForEmbeddedEntitiesDetection:
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 *)endpointParameters
- endpoint
A RegEx pattern for the URL.
Discussion
Example:
[[[OlapicSDK sharedOlapicSDK] rest]
setEndpointPatternForEmbeddedEntitiesDetection:@"\\/(media|stream|users)\\/([0-9]+|recent)(?:\\?|)"];
Declared In
OlapicRestClient.hsetEntitiesToDetect:
Set a list of names for entities that should be detected on an API response.
- (void)setEntitiesToDetect:(NSArray *)propertiesParameters
- 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.hsetEntitiesToDetectPerEndpointPattern:
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 *)patternsParameters
- 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.hsetEntityToDetect: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 *)patternParameters
- entity
The entity name.
- pattern
The RegEx pattern to match.
Discussion
Example:
[[[OlapicSDK sharedOlapicSDK] rest] setEntityToDetect:@"media" forEndpointPattern:@"\\/media\\/([0-9]+)"];
Declared In
OlapicRestClient.hunlink: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)reconnectParameters
- 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.husePreCacheForURL:
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 *)URLParameters
- 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