Latest 0.1.0
Homepage https://github.com/beastgrim/WRService
License MIT
Platforms ios 8.0, osx 10.8, tvos 9.0
Authors

WRService is light and convinient tool for working with an API via NSURLSession for most of applications.

Standart configuration has 2 queues: default and background. Background queue has less priority than standart queue. Each quque is represented as an NSURLSession instance.

You get internet data throuth WROperations. There is an example:

NSURL *url = [NSURL URLWithString:@"http://speedtest.ftp.otenet.gr/files/test100Mb.db"];

WROperation *op = [[WROperation alloc] initWithUrl:url];

[[WRService shared] execute:op onSuccess:^(WROperation * _Nonnull op, NSData * _Nonnull data) {
    NSLog(@"Backgound task is READY! %@", op);
} onFail:^(WROperation * _Nonnull op, NSError * _Nonnull error) {
    NSLog(@"Fail error: %@", error);
}];

You can get progress via block or delegate. Example:

op.progressCallback = ^(float progress) {
    NSLog(@"Progress: %f", progress);
};

If you emplemented WRObjectOperationProtocol to your class you can get result as your class instance or array of your class instanse. Example:

NSURL *url = [NSURL URLWithString:@"http://ip.jsontest.com"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];

WRObjectOperation * objOp = [[WRObjectOperation alloc] initWithRequest:req resultClass:[Article class]];

[[WRService shared] execute:objOp onSuccess:^(WROperation * _Nonnull op, Article  _Nonnull result) {
    NSLog(@"Article: %@", result);
} onFail:^(WROperation * _Nonnull op, NSError * _Nonnull error) {
    NSLog(@"Error: %@", error);
}];

WROperation.

Each WROperation has priority property. There are three types of priority:
WROperationPriorityDefault, WROperationPriorityBackground, WROperationPriorityExclusive.

If you start an operation with Exclusive priority all task (except Exclusive) will be suspended.
Suspended tasks will continue work after all exclusive tasks is finished.

JSON encoding and decoding.

And if you want have the fastest way for creating class which will be decoded from JSON use NSObject_WRJSON category for generating Objective-C class from JSON object. Example:

NSURL *url = [NSURL URLWithString:@"https://api.github.com/events"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];

WRObjectOperation *op = [[WRObjectOperation alloc] initWithRequest:req];

[[WRService shared] execute:op onSuccess:^(WROperation * _Nonnull op, NSData*  _Nonnull result) {

    id json = [NSJSONSerialization JSONObjectWithData:result options:0 error:nil];
    if (json) {
        NSString *classInterface = [NSObject wrGenerateClass:@"GitHubEvent" fromJSON:json];
        NSLog(@"%@", classInterface);
    }
} onFail:nil];

/* Result of NSLog: */

@class Repo, Actor, Payload;
@interface GitHubEvent : NSObject

@property (nonatomic, strong) Repo repo;
@property (nonatomic, strong) Actor
actor;
@property (nonatomic, assign) short public;
@property (nonatomic, assign) NSInteger id;
@property (nonatomic, copy) NSString created_at;
@property (nonatomic, strong) Payload
payload;
@property (nonatomic, copy) NSString *type;
@end

@interface Repo : NSObject

@property (nonatomic, assign) NSInteger id;
@property (nonatomic, copy) NSString name;
@property (nonatomic, copy) NSString
url;
@end

@interface Actor : NSObject

@property (nonatomic, copy) NSString display_login;
@property (nonatomic, assign) NSInteger id;
@property (nonatomic, copy) NSString
login;
@property (nonatomic, copy) NSString avatar_url;
@property (nonatomic, copy) NSString
url;
@property (nonatomic, copy) NSString *gravatar_id;
@end

@interface Payload : NSObject

@property (nonatomic, copy) NSString before;
@property (nonatomic, copy) NSString
ref;
@property (nonatomic, assign) NSInteger push_id;
@property (nonatomic, assign) NSInteger size;
@property (nonatomic, assign) NSInteger distinct_size;
@property (nonatomic, copy) NSString *head;
@end

Cocoapods support

CI Status
Version
License
Platform

Example

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

Requirements

Installation

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

pod "WRService"

Author

beastgrim, [email protected]

License

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

Latest podspec

{
    "name": "WRService",
    "version": "0.1.0",
    "summary": "WRService is light and convinient tool for working with an API via NSURLSession for most of applications.",
    "description": "# WRServicennWRService is light and convinient tool for working with an API via NSURLSession  for most of applications.nnStandart configuration has 2 queues: default and background. Background queue has less priority than standart queue. Each quque is represented as an NSURLSession instance. nnYou get internet data throuth WROperations. There is an example:nn    NSURL *url = [NSURL URLWithString:@"http://speedtest.ftp.otenet.gr/files/test100Mb.db"];n    n    WROperation *op = [[WROperation alloc] initWithUrl:url];n    n    [[WRService shared] execute:op onSuccess:^(WROperation * _Nonnull op, NSData * _Nonnull data) {n        NSLog(@"Backgound task is READY! %@", op);n    } onFail:^(WROperation * _Nonnull op, NSError * _Nonnull error) {n        NSLog(@"Fail error: %@", error);n    }];nnnnYou can get progress via block or delegate. Example:nn    op.progressCallback = ^(float progress) {n        NSLog(@"Progress: %f", progress);n    };n    nnIf you emplemented WRObjectOperationProtocol to your class you can get result as your class instance or array of your class instanse. Example:nn    NSURL *url = [NSURL URLWithString:@"http://ip.jsontest.com"];n    NSURLRequest *req = [NSURLRequest requestWithURL:url];n    n    WRObjectOperation * objOp = [[WRObjectOperation alloc] initWithRequest:req resultClass:[Article class]];n    n    [[WRService shared] execute:objOp onSuccess:^(WROperation * _Nonnull op, Article  _Nonnull result) {n        NSLog(@"Article: %@", result);n    } onFail:^(WROperation * _Nonnull op, NSError * _Nonnull error) {n        NSLog(@"Error: %@", error);n    }];nnWROperation.n------------nnEach WROperation has priority property. There are three types of priority: nWROperationPriorityDefault, WROperationPriorityBackground, WROperationPriorityExclusive.nnIf you start an operation with Exclusive priority all task (except Exclusive) will be suspended. nSuspended tasks will continue work after all exclusive tasks is finished.nnnJSON encoding and decoding.n--------------------------nAnd if you want have the fastest way for creating class which will be decoded from JSON use NSObject_WRJSON category for generating Objective-C class from JSON object. Example:nn    NSURL *url = [NSURL URLWithString:@"https://api.github.com/events"];n    NSURLRequest *req = [NSURLRequest requestWithURL:url];n    n    WRObjectOperation *op = [[WRObjectOperation alloc] initWithRequest:req];n    n    [[WRService shared] execute:op onSuccess:^(WROperation * _Nonnull op, NSData*  _Nonnull result) {n        n        id json = [NSJSONSerialization JSONObjectWithData:result options:0 error:nil];n        if (json) {n            NSString *classInterface = [NSObject wrGenerateClass:@"GitHubEvent" fromJSON:json];n            NSLog(@"%@", classInterface);n        }n    } onFail:nil];n    n    n    /* Result of NSLog: */[email protected] Repo, Actor, Payload;@interface GitHubEvent : [email protected] (nonatomic, strong) Repo *repo;@property (nonatomic, strong) Actor *actor;@property (nonatomic, assign) short public;@property (nonatomic, assign) NSInteger id;@property (nonatomic, copy) NSString *created_at;@property (nonatomic, strong) Payload *payload;@property (nonatomic, copy) NSString *type;@[email protected] Repo : [email protected] (nonatomic, assign) NSInteger id;@property (nonatomic, copy) NSString *name;@property (nonatomic, copy) NSString *url;@[email protected] Actor : [email protected] (nonatomic, copy) NSString *display_login;@property (nonatomic, assign) NSInteger id;@property (nonatomic, copy) NSString *login;@property (nonatomic, copy) NSString *avatar_url;@property (nonatomic, copy) NSString *url;@property (nonatomic, copy) NSString *gravatar_id;@[email protected] Payload : [email protected] (nonatomic, copy) NSString *before;@property (nonatomic, copy) NSString *ref;@property (nonatomic, assign) NSInteger push_id;@property (nonatomic, assign) NSInteger size;@property (nonatomic, assign) NSInteger distinct_size;@property (nonatomic, copy) NSString *head;@end",
    "homepage": "https://github.com/beastgrim/WRService",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "beastgrim": "[email protected]"
    },
    "source": {
        "git": "https://github.com/beastgrim/WRService.git",
        "branch": "0.1.0",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.8",
        "tvos": "9.0"
    },
    "source_files": "WRService/Classes/**/*"
}

Pin It on Pinterest

Share This