Skip to content

Latest commit

 

History

History
110 lines (79 loc) · 3.5 KB

README.md

File metadata and controls

110 lines (79 loc) · 3.5 KB

GreedNetwork Join the chat at https://gitter.im/greedlab/GreedNetwork Build Status

a network request util for iOS 7+, based on AFNetworking and GreedJSON

Installation

pod 'GreedNetwork'

Usage

GRNetworkForm

decalre your network parameters as properties in GRNetworkForm instance's interface file;

@interface GRTestFrom : GRNetworkForm

@property (nonatomic, strong) NSString *password;

@property (nonatomic, strong) NSString *username;

@property (nonatomic, strong) NSString *q;

@end

you could customize default parameters value in the implementation file;

@implementation GRTestFrom

- (instancetype)init {
    self = [super init];
    if (self) {
        self.username = @"foo";
        self.password = @"foo1";
        self.q = @"test";
    }
    return self;
}

@end

initialize your GreedNetwork instance and start your network connection with

    - (void)gr_requestWithNetworkForm:(GRNetworkForm *)form
                          success:(void (^)(GRNetworkResponse *responseObject))success
                          failure:(void (^)(GRNetworkResponse *responseObject))failure

that is it!

- (void)testRequest
{
    GRTestForm *form = [[GRTestForm alloc] init];
    form.q = @"GreedNetwork";
    form.password = self.passTextField.text;
    form.username = self.userTextField.text;
    NSLog(@"form:%@",[form gr_dictionary]);
    [self gr_requestWithNetworkForm:form success:^(GRNetworkResponse *responseObject) {
        NSLog(@"request:%@",responseObject.responseDictionary);
    } failure:^(GRNetworkResponse *responseObject) {
        NSLog(@"request:%@",[responseObject.error userInfo]);
    }];
}
- (void)testQueue
{
    for (NSInteger index = 0; index < 2; index ++) {
        GRTestForm *form = [[GRTestForm alloc] init];
        form.q = @"GreedNetwork";
        form.successBlock = ^(GRNetworkResponse *responseObject) {
            NSLog(@"queue_%@:%@",@(index),responseObject.responseDictionary);
        };
        form.failureBlock = ^(GRNetworkResponse *responseObject) {
            NSLog(@"queue_%@:%@",@(index),[responseObject.error userInfo]);
        };

        NSLog(@"form:%@",[form gr_dictionary]);
        [[GRNetworkQueue getInstance] addForm:form];
    }
}

Advantage

Compared with the other network util based on AFNetworking ,GreedNetwork has these advantages as follows:

1.if you are going to migrate AFNetworking from 2.x to 3.x,we give you GreedNetwork as candidate.

2.when you have decalred the properties in your GRNetworkForm instance, your network request header,request parameters and HTTP body is generated automatically.

3.GreedNetwork is highly customizable to be adopted to your own project;

CHANGELOG

CHANGELOG.md

LICENSE

MIT