Latest1.5.1
Homepagehttps://github.com/plu/ReactiveNetworking
LicenseMIT
Platformsios 6.0, osx 10.8, requires ARC
Authors

Build Status

ReactiveNetworking is a Cocoa and Cocoa Touch framework for interacting with some API via HTTP, built using
AFNetworking,
Mantle, and
ReactiveCocoa.

Most of the code is shamelessly copied from Github’s OctoKit.

Usage

API response

Let’s assume an API, that returns for GET /users/plu the following
JSON response:

{
    "user": {
        "id": 42,
        "login_name": "plu",
        "display_name": "Johannes Plunien"
    }
}

Model object

@interface ReadmeUser : MTLModel <MTLJSONSerializing>

@property (nonatomic, copy, readonly) NSString *objectID;
@property (nonatomic, copy, readonly) NSString *login;
@property (nonatomic, copy, readonly) NSString *name;

@end

@implementation ReadmeUser

+ (NSDictionary *)JSONKeyPathsByPropertyKey
{
    return @{@"objectID": @"id",
             @"login": @"login_name",
             @"name": @"display_name"};
}

@end

API client

@interface ReadmeClient : RNClient

- (RACSignal *)fetchUser:(NSString *)username;

@end

@implementation ReadmeClient

- (instancetype)initWithBaseURL:(NSURL *)url
{
    if (url == nil) url = [NSURL URLWithString:@"https://api.example.com"];
    self = [super initWithBaseURL:url];
    if (self) {
        [self registerHTTPOperationClass:AFJSONRequestOperation.class];
        [self setDefaultHeader:@"Accept" value:@"application/json"];
    }
    return self;
}

- (RACSignal *)fetchUser:(NSString *)username
{
    NSString *path = [NSString stringWithFormat:@"/users/%@", username];
    NSMutableURLRequest *request = [self requestWithMethod:@"GET" path:path parameters:nil];
    return [self enqueueRequest:request
                    resultClass:ReadmeUser.class
                       keyPaths:@[@"user"]];
}

@end

How to use it

ReadmeClient *client = [[ReadmeClient alloc] initWithBaseURL:nil];
[[client fetchUser:@"plu"] subscribeNext:^(RNResponse *response) {
    NSLog(@"%@", response.parsedResult);
}];

It will log something like:

<ReadmeUser: 0x10052a140> {
    login = plu;
    name = "Johannes Plunien";
    objectID = 42;
}

License (MIT)

Copyright (c) 2014 Johannes Plunien

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Latest podspec

{
    "name": "ReactiveNetworking",
    "version": "1.5.1",
    "license": "MIT",
    "summary": "Mixes the great AFNetworking with ReactiveCocoa.",
    "homepage": "https://github.com/plu/ReactiveNetworking",
    "authors": {
        "Johannes Plunien": "[email protected]"
    },
    "social_media_url": "https://twitter.com/plutooth",
    "source": {
        "git": "https://github.com/plu/ReactiveNetworking.git",
        "tag": "1.5.1",
        "submodules": true
    },
    "requires_arc": true,
    "platforms": {
        "ios": "6.0",
        "osx": "10.8"
    },
    "default_subspecs": "Core",
    "prefix_header_contents": "#if __IPHONE_OS_VERSION_MIN_REQUIREDn  #import n  #import n  #import n#elsen  #import n  #import n  #import n#endifn",
    "subspecs": [
        {
            "name": "Core",
            "source_files": "ReactiveNetworking/*.{h,m}",
            "dependencies": {
                "ReactiveNetworking/Dependencies": []
            }
        },
        {
            "name": "Dependencies",
            "dependencies": {
                "AFNetworking": [
                    "~> 1.0"
                ],
                "Mantle": [
                    "~> 1.0"
                ],
                "ReactiveCocoa": [
                    "~> 2.0"
                ],
                "ReactiveCocoa/UI": [
                    "~> 2.0"
                ]
            }
        },
        {
            "name": "Testing",
            "dependencies": {
                "Expecta": [
                    "~> 0.3"
                ],
                "OHHTTPStubs": [
                    "~> 3.1"
                ],
                "Specta": [
                    "~> 0.2"
                ]
            }
        }
    ]
}

Pin It on Pinterest

Share This