Latest 0.1.3
Homepage https://github.com/espeiorin/SOA-iOS-SDK
License MIT
Platforms ios 7.0, requires ARC
Dependencies AFNetworking
Frameworks UIKit
Authors

Licence
Plafform
Plafform

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.

Getting SOA iOS SDK

Cocoapods

pod 'SOA-iOS-SDK', '~> 0.1.3'

Configure it

In order to get SOA SDK working, you must configure the API URL and shared headers.

  • apiURL for the REST Calls
  • rpcURL for the RPC Calls
[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];

Miscelaneous

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;

The SOA Object

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.

Creating New

SOAObject *hotel = [[SOAObject alloc] initWithEntityName:@"hotel"];

SOAObject *knownHotel = [[SOAObject alloc] initWithEntityName:@"hotel" entityId:12];

Dealing with data

[hotel setValue:@"Ibis" forKey:@"name"];
[hotel setValue:@"R. Nove de Março" forKey:@"street"];

NSString *name = [hotel valueForKey:@"name"];

Fetching an Object

[SOAObject getWithEntityName:@"hotel"
                    entityId:12
             completionBlock:^(id result, NSError *error) {
                 SOAObject *object = (SOAObject *)result;
             }];

Saving an Object

Static Way
[SOAObject saveEntity:@"hotel"
           parameters:@{
                        @"id" : @(10),
                        @"name" : @"Bourbon",
                        @"street" : @"R. Visconde de Taunay"
                        }
      completionBlock:^(id result, NSError *error) {

      }];
Instance Way
[hotel saveWithCompletionBlock:^(id result, NSError *error) {

}];

Deleting an Object

Static Way
[SOAObject getWithEntityName:@"hotel"
                    entityId:12
             completionBlock:^(id result, NSError *error) {
                 SOAObject *object = (SOAObject *)result;
             }];
Instance Way
[hotel deleteWithCompletionBlock:^(id result, NSError *error) {

}];

The SOA Query

Building a query

SOAQuery *query = [[SOAQuery alloc] initWithEntityName:@"hotel"];
query.offset = 0;
query.limit = 100;
query.fields = @[@"name", @"id"];

SOA Filter

SOAFilter *filter = [SOAFilter where:@"id" equalTo:@26];
[query addFilter:filter];

SOA Join

SOAFilter *joinFilter = [SOAFilter where:@"id" equalTo:@10];
SOAJoin *join = [SOAJoin joinField:@"user" withFilter:joinFilter];
[query addJoin:join];

Perform Query

[query performQueryWithCompletionBlock:^(id result, NSError *error) {
    NSLog(@"%@", result);
}];

The SOA RPC Call

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);
   }];

Dealing with authorization errors

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];

Latest podspec

{
    "name": "SOA-iOS-SDK",
    "version": "0.1.3",
    "summary": "SOA-iOS-SDK is a client built to consume SOA Server based APIs.",
    "description": "                   [SOA Server](https://github.com/coderockr/soa) 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 a long time using SOA Server I decided to transport the same mindset to Objective-C and the result is this library.nn                    ##Getting SOA iOS SDKnn                    ###Cocoapodsnn                    ##Configure itn                    In order to get SOA SDK working, you must configure the API URL and shared headers.n                    * apiURL for the REST Callsn                    * rpcURL for the RPC Callsnn                    ```objcn                    [SOAManager defaultManager].apiURL = [NSURL URLWithString:@"http://serveraddress.com/api/v1"];nn                    [SOAManager defaultManager].rpcURL = [NSURL URLWithString:@"http://serveraddress.com/rpc/v1"];nn                    [[SOAManager defaultManager] setDefaultHeaders:@{@"Authorization" : @"_authorization_token_"}];n                    ```nn                    Including shared headers for each HTTP Method available at REST API.n                    ```objcn                    SOAServiceMethodGET,n                    SOAServiceMethodPOST,n                    SOAServiceMethodPUT,n                    SOAServiceMethodDELETE,n                    SOAServiceMethodALLnn                    [[SOAManager defaultManager] setDefaultHeaders:@{@"Content-Type" : @"application/x-www-form-urlencoded"} forMethod:SOAServiceMethodPOST];nn                    [[SOAManager defaultManager] setDefaultHeaders:@{@"Content-Type" : @"application/x-www-form-urlencoded"} forMethod:SOAServiceMethodPUT];n                    ```nn                    ###Miscelaneousn                    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.n                    ```objcn                    [SOAManager defaultManager].maxConcurrentRequests = 4;n                    [SOAManager defaultManager].controlNetworkActivity = YES;n                    ```nn                    ##The SOA Objectnn                    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. nn                    Beyond it, you can store any kind of data (pointers) using setValue:forKey: and you can also retrieve any data using valueForKey: method.nnn                    ###Creating Newnn                    ```objcn                    SOAObject *hotel = [[SOAObject alloc] initWithEntityName:@"hotel"];nn                    SOAObject *knownHotel = [[SOAObject alloc] initWithEntityName:@"hotel" entityId:12];n                    ```n                    ###Dealing with datan                    ```objcn                    [hotel setValue:@"Ibis" forKey:@"name"];n                    [hotel setValue:@"R. Nove de Maru00e7o" forKey:@"street"];nn                    NSString *name = [hotel valueForKey:@"name"];n                    ```nn                    ###Fetching an Objectn                    ```objcn                    [SOAObject getWithEntityName:@"hotel"n                                        entityId:12n                                 completionBlock:^(id result, NSError *error) {n                                     SOAObject *object = (SOAObject *)result;n                                 }];n                    ```nn                    ###Saving an Objectn                    #####Static Wayn                    ```objcn                    [SOAObject saveEntity:@"hotel"n                               parameters:@{n                                            @"id" : @(10),n                                            @"name" : @"Bourbon",n                                            @"street" : @"R. Visconde de Taunay"n                                            }n                          completionBlock:^(id result, NSError *error) {n                              n                          }];n                    ```n                    #####Instance Wayn                    ```objcn                    [hotel saveWithCompletionBlock:^(id result, NSError *error) {n                        n                    }];n                    ```n                    ###Deleting an Objectn                    #####Static Wayn                    ```objcn                    [SOAObject getWithEntityName:@"hotel"n                                        entityId:12n                                 completionBlock:^(id result, NSError *error) {n                                     SOAObject *object = (SOAObject *)result;n                                 }];n                    ```n                    #####Instance Wayn                    ```objcn                    [hotel deleteWithCompletionBlock:^(id result, NSError *error) {n                        n                    }];n                    ```n                    ##The SOA Queryn                    ###Building a queryn                    ```objcn                    SOAQuery *query = [[SOAQuery alloc] initWithEntityName:@"hotel"];n                    query.offset = 0;n                    query.limit = 100;n                    query.fields = @[@"name", @"id"];n                    ```nn                    ###SOA Filtern                    ```objcn                    SOAFilter *filter = [SOAFilter where:@"id" equalTo:@26];n                    [query addFilter:filter];n                    ```n                    ###SOA Joinn                    ```objcn                    SOAFilter *joinFilter = [SOAFilter where:@"id" equalTo:@10];n                    SOAJoin *join = [SOAJoin joinField:@"user" withFilter:joinFilter];n                    [query addJoin:join];n                    ```nn                    ###Perform Queryn                    ```objcn                    [query performQueryWithCompletionBlock:^(id result, NSError *error) {n                        NSLog(@"%@", result);n                    }];n                    ```nn                    ##The SOA RPC Callnn                    ```objcn                    SOARPCCall *rpc = [[SOARPCCall alloc] init];n                    [rpc callProcedure:@"/authentication/login"n                            parameters:@{@"email" : @"[email protected]", @"password" : @"passwd"}n                               headers:niln                       completionBlock:^(id result, NSError *error) {n                           NSLog(@"%@", result);n                           NSLog(@"%@", error);n                       }];n                    ```n",
    "homepage": "https://github.com/espeiorin/SOA-iOS-SDK",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Andru00e9 Gustavo Espeiorin": "[email protected]"
    },
    "social_media_url": "http://twitter.com/espeiorin",
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/espeiorin/SOA-iOS-SDK.git",
        "tag": "0.1.3"
    },
    "source_files": [
        "Classes",
        "Classes/**/*.{h,m}"
    ],
    "exclude_files": "Classes/Exclude",
    "public_header_files": "Classes/**/*.h",
    "frameworks": "UIKit",
    "requires_arc": true,
    "dependencies": {
        "AFNetworking": [
            "~> 2.0"
        ]
    }
}

Pin It on Pinterest

Share This