CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.
TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Andre Espeiorin.
SOA Server is a great way to build your Web Services, it's built on top of Silex and Doctrine 2, but using iOS as a client you couldn't get the same experience, until now. After using SOA Server for a long time I decided to use the same mindset with Objective-C and the result is this library.
In order to get SOA SDK working, you must configure the API URL and shared headers.
[SOAManager defaultManager].apiURL = [NSURL URLWithString:@"http://serveraddress.com/api/v1"];
[SOAManager defaultManager].rpcURL = [NSURL URLWithString:@"http://serveraddress.com/rpc/v1"];
[[SOAManager defaultManager] setDefaultHeaders:@{@"Authorization" : @"_authorization_token_"}];
Including shared headers for each HTTP Method available at REST API.
SOAServiceMethodGET,
SOAServiceMethodPOST,
SOAServiceMethodPUT,
SOAServiceMethodDELETE,
SOAServiceMethodALL
[[SOAManager defaultManager] setDefaultHeaders:@{@"Content-Type" : @"application/x-www-form-urlencoded"} forMethod:SOAServiceMethodPOST];
[[SOAManager defaultManager] setDefaultHeaders:@{@"Content-Type" : @"application/x-www-form-urlencoded"} forMethod:SOAServiceMethodPUT];
Right now, you can configure the queue concurrent requests limits and you can also delegate to SOA SDK the responsability to display or hide the Network Activity Status.
[SOAManager defaultManager].maxConcurrentRequests = 4;
[SOAManager defaultManager].controlNetworkActivity = YES;
SOAObject is a NSObject subclass built to storage entity's data. SOAObject has only one mandatory property, which is Entity Name, but you can set the entity id. Both properties are intended to identify the object.
Beyond it, you can store any kind of data (pointers) using setValue:forKey: and you can also retrieve any data using valueForKey: method.
SOAObject *hotel = [[SOAObject alloc] initWithEntityName:@"hotel"];
SOAObject *knownHotel = [[SOAObject alloc] initWithEntityName:@"hotel" entityId:12];
[hotel setValue:@"Ibis" forKey:@"name"];
[hotel setValue:@"R. Nove de Março" forKey:@"street"];
NSString *name = [hotel valueForKey:@"name"];
[SOAObject getWithEntityName:@"hotel"
entityId:12
completionBlock:^(id result, NSError *error) {
SOAObject *object = (SOAObject *)result;
}];
[SOAObject saveEntity:@"hotel"
parameters:@{
@"id" : @(10),
@"name" : @"Bourbon",
@"street" : @"R. Visconde de Taunay"
}
completionBlock:^(id result, NSError *error) {
}];
[hotel saveWithCompletionBlock:^(id result, NSError *error) {
}];
[SOAObject getWithEntityName:@"hotel"
entityId:12
completionBlock:^(id result, NSError *error) {
SOAObject *object = (SOAObject *)result;
}];
[hotel deleteWithCompletionBlock:^(id result, NSError *error) {
}];
SOAQuery *query = [[SOAQuery alloc] initWithEntityName:@"hotel"];
query.offset = 0;
query.limit = 100;
query.fields = @[@"name", @"id"];
SOAFilter *filter = [SOAFilter where:@"id" equalTo:@26];
[query addFilter:filter];
SOAFilter *joinFilter = [SOAFilter where:@"id" equalTo:@10];
SOAJoin *join = [SOAJoin joinField:@"user" withFilter:joinFilter];
[query addJoin:join];
[query performQueryWithCompletionBlock:^(id result, NSError *error) {
NSLog(@"%@", result);
}];
SOARPCCall *rpc = [[SOARPCCall alloc] init];
[rpc callProcedure:@"/authentication/login"
parameters:@{@"email" : @"[email protected]", @"password" : @"passwd"}
headers:nil
completionBlock:^(id result, NSError *error) {
NSLog(@"%@", result);
NSLog(@"%@", error);
}];
From version 0.1.3, you can observe authorization failures using NSNotificationCenter, the notification name is SOAServiceAuthErrorNotification:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selector:) name:SOAServiceAuthErrorNotification object:nil];