SCWebServiceDefinition Class Reference
Inherits from | SCDictionaryDefinition : SCDataDefinition : NSObject |
Declared in | SCWebServiceDefinition.h |
Overview
This class functions as a means to further extend the definition of remote web services. Using web service definitions, classes like SCObjectCell and SCObjectSection will be able to better generate user interface elements that truly represent their bound web service.
Sample use:
// Define the Twitter API search web service for the search term '#iosdev'.
SCWebServiceDefinition *tweetDef = [SCWebServiceDefinition definitionWithBaseURL:@"http://search.twitter.com/"
fetchObjectsAPI:@"search.json" resultsKeyName:@"results" resultsDictionaryKeyNames:nil];
[tweetDef.fetchObjectsParameters setValue:@"#iosdev" forKey:@"q"];
[tweetDef.fetchObjectsParameters setValue:@"recent" forKey:@"result_type"];
tweetDef.batchSizeParameterName = @"rpp";
tweetDef.nextBatchURLKeyName = @"next_page";
SCPropertyDefinition *textPropertyDef = [SCPropertyDefinition definitionWithName:@"text"
title:@"Tweet" type:SCPropertyTypeTextView];
[tweetDef addPropertyDefinition:textPropertyDef];
// Create a section that will display the tweets in batches of 50
SCArrayOfObjectsSecion *tweetsSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil
webServiceDefinition:tweetDef batchSize:50];
[self.tableViewModel addSection:tweetsSection];
Tasks
Creation and Initialization
-
+ definitionWithBaseURL:fetchObjectsAPI:resultsKeyName:resultsDictionaryKeyNamesString:
Allocates and returns an initialized SCWebServiceDefinition.
-
+ definitionWithBaseURL:fetchObjectsAPI:resultsKeyName:resultsDictionaryKeyNames:
Allocates and returns an initialized SCWebServiceDefinition.
-
– initWithBaseURL:fetchObjectsAPI:resultsKeyName:resultsDictionaryKeyNamesString:
Returns an initialized SCWebServiceDefinition.
-
– initWithBaseURL:fetchObjectsAPI:resultsKeyName:resultsDictionaryKeyNames:
Allocates and returns an initialized SCWebServiceDefinition.
Configuration
-
baseURL
The base URL of the web service.
property -
httpHeaders
The dictionary of HTTP header values.
property -
fetchObjectsAPI
The string containing the fetch objects API.
property -
fetchObjectsParameters
The dictionary of fetch objects parameters.
property -
resultsKeyName
The name of the results dictionary key that will contain the objects fetched from the web service.
property -
atomicResultKeyName
Set only if the fetched result is an atomic array of a single dictionary object. When this is the case, resultsKeyName can be set to a key in the returned atomic dictionary.
property -
batchSizeParameterName
The name of the parameter that can be assigned the fetched batch size.
property -
batchStartIndexParameterName
The name of the parameter that can be assigned the batch starting index.
property -
batchInitialStartIndex
The initial starting index for the batch. Default: 0.
property -
nextBatchURLKeyName
The name of the results dictionary key that contains the URL to the next batch of objects.
property -
objectIdKeyName
The name of the object key containing a unique id.
property -
readOnlyKeyNames
The string containing all the readonly object keys separated by semi-colons. All keys specified here will not be updated during an object update operation.
property -
insertObjectAPI
The string containing the insert object API.
property -
insertObjectParameters
The dictionary of insert object parameters.
property -
updateObjectAPI
The string containing the update object API.
property -
updateObjectParameters
The dictionary of update object parameters.
property -
deleteObjectAPI
The string containing the delete object API.
property -
deleteObjectParameters
The dictionary of delete object parameters.
property
Authorization Methods
-
– setAuthorizationHeaderWithUsername:password:
Sets the “Authorization” HTTP header to a HTTP basic authentication value with Base64-encoded username and password. This overwrites any existing value for this header.
-
– setAuthorizationHeaderWithToken:
Sets the “Authorization” HTTP header to a token-based authentication value, such as an OAuth access token. This overwrites any existing value for this header.
-
– clearAuthorizationHeader
Clears any existing value for the “Authorization” HTTP header.
Properties
atomicResultKeyName
Set only if the fetched result is an atomic array of a single dictionary object. When this is the case, resultsKeyName can be set to a key in the returned atomic dictionary.
@property (nonatomic, copy) NSString *atomicResultKeyName
Declared In
SCWebServiceDefinition.h
baseURL
The base URL of the web service.
@property (nonatomic, strong) NSURL *baseURL
Declared In
SCWebServiceDefinition.h
batchInitialStartIndex
The initial starting index for the batch. Default: 0.
@property (nonatomic, readwrite) NSUInteger batchInitialStartIndex
Discussion
Note: Only has effect if batchStartIndexParameterName is set.
Declared In
SCWebServiceDefinition.h
batchSizeParameterName
The name of the parameter that can be assigned the fetched batch size.
@property (nonatomic, copy) NSString *batchSizeParameterName
Declared In
SCWebServiceDefinition.h
batchStartIndexParameterName
The name of the parameter that can be assigned the batch starting index.
@property (nonatomic, copy) NSString *batchStartIndexParameterName
Declared In
SCWebServiceDefinition.h
deleteObjectAPI
The string containing the delete object API.
@property (nonatomic, copy) NSString *deleteObjectAPI
Declared In
SCWebServiceDefinition.h
deleteObjectParameters
The dictionary of delete object parameters.
@property (nonatomic, readonly) NSMutableDictionary *deleteObjectParameters
Declared In
SCWebServiceDefinition.h
fetchObjectsAPI
The string containing the fetch objects API.
@property (nonatomic, copy) NSString *fetchObjectsAPI
Declared In
SCWebServiceDefinition.h
fetchObjectsParameters
The dictionary of fetch objects parameters.
@property (nonatomic, readonly) NSMutableDictionary *fetchObjectsParameters
Discussion
Sample use:
[tweetDef.fetchObjectsParameters setValue:@"#iosdev" forKey:@"q"];
Declared In
SCWebServiceDefinition.h
httpHeaders
The dictionary of HTTP header values.
@property (nonatomic, readonly) NSMutableDictionary *httpHeaders
Discussion
Sample use:
[myWebServiceDef.httpHeaders setValue:@"application/json" forKey:@"Content-Type"];
Declared In
SCWebServiceDefinition.h
insertObjectAPI
The string containing the insert object API.
@property (nonatomic, copy) NSString *insertObjectAPI
Declared In
SCWebServiceDefinition.h
insertObjectParameters
The dictionary of insert object parameters.
@property (nonatomic, readonly) NSMutableDictionary *insertObjectParameters
Declared In
SCWebServiceDefinition.h
nextBatchURLKeyName
The name of the results dictionary key that contains the URL to the next batch of objects.
@property (nonatomic, copy) NSString *nextBatchURLKeyName
Declared In
SCWebServiceDefinition.h
objectIdKeyName
The name of the object key containing a unique id.
@property (nonatomic, copy) NSString *objectIdKeyName
Declared In
SCWebServiceDefinition.h
readOnlyKeyNames
The string containing all the readonly object keys separated by semi-colons. All keys specified here will not be updated during an object update operation.
@property (nonatomic, copy) NSString *readOnlyKeyNames
Declared In
SCWebServiceDefinition.h
resultsKeyName
The name of the results dictionary key that will contain the objects fetched from the web service.
@property (nonatomic, copy) NSString *resultsKeyName
Declared In
SCWebServiceDefinition.h
Class Methods
definitionWithBaseURL:fetchObjectsAPI:resultsKeyName:resultsDictionaryKeyNames:
Allocates and returns an initialized SCWebServiceDefinition.
+ (id)definitionWithBaseURL:(NSString *)baseURL fetchObjectsAPI:(NSString *)api resultsKeyName:(NSString *)resultsKey resultsDictionaryKeyNames:(NSArray *)keyNames
Parameters
- baseURL
The base URL of the web service.
- api
The api string used to fetch the objects.
- resultsKey
The name of the dictionary key that will contain the fetched objects.
- keyNames
An array containing the key names of the results dictionary.
Declared In
SCWebServiceDefinition.h
definitionWithBaseURL:fetchObjectsAPI:resultsKeyName:resultsDictionaryKeyNamesString:
Allocates and returns an initialized SCWebServiceDefinition.
+ (id)definitionWithBaseURL:(NSString *)baseURL fetchObjectsAPI:(NSString *)api resultsKeyName:(NSString *)resultsKey resultsDictionaryKeyNamesString:(NSString *)keyNamesString
Parameters
- baseURL
The base URL of the web service.
- api
The api string used to fetch the objects.
- resultsKey
The name of the dictionary key that will contain the fetched objects.
- keyNamesString
A string containing the key names of the results dictionary separated by semi-colons. Example string: @“firstName;lastName”. Property groups can also be defined in the string using the following format: @“Personal Details:(firstName, lastName); Address:(street, state, country)”. The group title can also be ommitted to create a group with no title. For example: @“:(firstName, lastName)”.
Key names string syntax options:
@"key1;key2;key3;..." @"group1 header:(key1, key2,...):group1 footer;group2..."
Declared In
SCWebServiceDefinition.h
Instance Methods
clearAuthorizationHeader
Clears any existing value for the “Authorization” HTTP header.
- (void)clearAuthorizationHeader
Declared In
SCWebServiceDefinition.h
initWithBaseURL:fetchObjectsAPI:resultsKeyName:resultsDictionaryKeyNames:
Allocates and returns an initialized SCWebServiceDefinition.
- (id)initWithBaseURL:(NSString *)baseURL fetchObjectsAPI:(NSString *)api resultsKeyName:(NSString *)resultsKey resultsDictionaryKeyNames:(NSArray *)keyNames
Parameters
- baseURL
The base URL of the web service.
- api
The api string used to fetch the objects.
- resultsKey
The name of the dictionary key that will contain the fetched objects.
- keyNames
An array containing the key names of the results dictionary.
Declared In
SCWebServiceDefinition.h
initWithBaseURL:fetchObjectsAPI:resultsKeyName:resultsDictionaryKeyNamesString:
Returns an initialized SCWebServiceDefinition.
- (id)initWithBaseURL:(NSString *)baseURL fetchObjectsAPI:(NSString *)api resultsKeyName:(NSString *)resultsKey resultsDictionaryKeyNamesString:(NSString *)keyNamesString
Parameters
- baseURL
The base URL of the web service.
- api
The api string used to fetch the objects.
- resultsKey
The name of the dictionary key that will contain the fetched objects.
- keyNamesString
A string containing the key names of the results dictionary separated by semi-colons. Example string: @“firstName;lastName”. Property groups can also be defined in the string using the following format: @“Personal Details:(firstName, lastName); Address:(street, state, country)”. The group title can also be ommitted to create a group with no title. For example: @“:(firstName, lastName)”.
Key names string syntax options:
@"key1;key2;key3;..." @"group1 header:(key1, key2,...):group1 footer;group2..."
Declared In
SCWebServiceDefinition.h
setAuthorizationHeaderWithToken:
Sets the “Authorization” HTTP header to a token-based authentication value, such as an OAuth access token. This overwrites any existing value for this header.
- (void)setAuthorizationHeaderWithToken:(NSString *)token
Parameters
- token
The authentication token
Declared In
SCWebServiceDefinition.h
setAuthorizationHeaderWithUsername:password:
Sets the “Authorization” HTTP header to a HTTP basic authentication value with Base64-encoded username and password. This overwrites any existing value for this header.
- (void)setAuthorizationHeaderWithUsername:(NSString *)username password:(NSString *)password
Parameters
- username
The HTTP basic auth username
- password
The HTTP basic auth password
Declared In
SCWebServiceDefinition.h