Latest 0.3.0
Homepage https://github.com/stefz/Mercurio
License MIT
Platforms ios 7.0, requires ARC
Dependencies AFNetworking, Mantle, SAMKeychain
Authors

[![CI Status](http://img.shields.io/travis/Stefano Zanetti/Mercurio.svg?style=flat)](https://travis-ci.org/Stefano Zanetti/Mercurio)
Version
License
Platform

Mercurio is a fast way to make an api with AFNetworking and parse the response with Mantle.

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

Mercurio is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'Mercurio', '~> 0.1.3'

Example

Define a response object
@interface MEResponse : MEModel

@property (copy, nonatomic) NSString *accept;
@property (copy, nonatomic) NSString *acceptEncoding;
@property (copy, nonatomic) NSString *acceptLanguage;
@property (copy, nonatomic) NSString *host;
@property (copy, nonatomic) NSString *userAgent;

@end
@implementation MEResponse

+ (NSDictionary *)JSONKeyPathsByPropertyKey {
    return @{ selStr(accept) : @"Accept",
              selStr(acceptEncoding) : @"Accept-Encoding",
              selStr(acceptLanguage) : @"Accept-Language",
              selStr(host) : @"Host",
              selStr(userAgent) : @"User-Agent" };
}

@end

GET

You must create an instance of MEApi, set the path, the class response and eventually the root of json response object. That’s all!

MEApi *api = [MEApi apiWithMethod:MEApiMethodGET
                             path:@"https://httpbin.org/get"
                    responseClass:[MEResponse class]
                         jsonRoot:@"headers"];

Now you simple have to tell the MESessionManager which API you want execute and nothing else.

[[MESessionManager sharedInstance] sessionDataTaskWithApi:api
                                               completion:^(id responseObject, NSURLSessionDataTask *task, NSError *error) {
                                                   if (!error) {
                                                       NSLog(@"%@", responseObject);
                                                   }
                                               }];
POST Multipart

Like the previous example, you must create an instance of MEMultipartFormApi. MEMultipartFormApi is a MEApi that is conformed to the MEMultipartFormApiProtocol protocol.

MEMultipartFormApi *api = [MEMultipartFormApi apiWithMethod:MEApiMethodPOST
                                                       path:@"http://posttestserver.com/post.php?dir=mercurio"
                                              responseClass:[NSNull class]
                                                   jsonRoot:nil];

[api setMultipartFormConstructingBodyBlock:^(id<AFMultipartFormData> formData) {
       [formData appendPartWithFileData:[NSData data]
                                   name:@""name"
                               fileName:@"file.jpg"
                               mimeType:@"image/jpeg"];
}];

And then the MESessionManager does the rest.

[[MESessionManager sharedInstance] sessionMultipartDataTaskWithApi:api
                                                        completion:^(id responseObject, NSURLSessionDataTask *task, NSError *error) {    
                                                            if (!error) {
                                                                NSLog(@"%@", responseObject);
                                                            }
                                                        }];

MESessionManager always returns a NSURLSessionDataTask so you can cancel the operation at any time.

Author

Stefano Zanetti, [email protected]

License

Mercurio is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Mercurio",
    "version": "0.3.0",
    "summary": "Mercurio is a fast way to make an api with AFNetworking and parse the response with Mantle.",
    "homepage": "https://github.com/stefz/Mercurio",
    "license": "MIT",
    "authors": {
        "Stefano Zanetti": "[email protected]"
    },
    "source": {
        "git": "https://github.com/stefz/Mercurio.git",
        "tag": "0.3.0"
    },
    "social_media_url": "https://twitter.com/stezanna",
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "dependencies": {
        "AFNetworking": [
            "~> 3.0"
        ],
        "Mantle": [
            "~> 2.0.6"
        ],
        "SAMKeychain": [
            "~> 1.5.1"
        ]
    }
}

Pin It on Pinterest

Share This