Latest 1.0.2
Homepage https://github.com/CoconutGZ/CoconutNetworking
License MIT
Platforms ios 8.0, requires ARC
Dependencies AFNetworking, FMDB
Authors

CoconutNetworking is a delightful networking util for iOS.

Installation with CocoaPods

Podfile

To integrate CoconutNetworking into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

target 'TargetName' do
pod 'CoconutNetworking', '~> 1.0.1'
end

How To use

//
//  ViewController.m
//  CNNetworking
//
//  Created by mac on 17/1/6.
//  Copyright © 2017年 Ajin. All rights reserved.
//

#import "ViewController.h"
#import "CoconutNetworking.h"
#import "ViewControllerReformer.h"

@interface ViewController () <CNAPIManagerParamSource, CNAPIManagerCallBackDelegate, CNAPIManagerValidator>

@property (nonatomic, strong) CNAPIManager *manager;
@property (nonatomic, strong) ViewControllerReformer *dataReformer;

@property (weak, nonatomic) IBOutlet UILabel *showResultLabel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"viewDidLoad";

//    [self.manager loadData];

    NSLog(@"viewDidLoad");
}

- (IBAction)buttonAction:(id)sender {

    self.showResultLabel.text = @"正在请求...";

    [self.manager loadData];
}

#pragma mark - <CNAPIManagerParamSource, CNAPIManagerCallBackDelegate, CNAPIManagerValidator>

- (NSString *)methodNameForApi:(CNAPIManager *)manager
{

//    return [CNAPIManager URLStringByAppendString:@"/v2/book/search"];
    return @"https://api.douban.com/v2/book/search";
}

- (NSDictionary *)paramsForApi:(CNAPIManager *)manager
{

    NSDictionary *parameters = @{@"q":@"历史",
    @"count":@(100)};
    return parameters;
}

- (CNAPIManagerRequestType)requestTypeForApi:(CNAPIManager *)manager
{
    return CNAPIManagerRequestTypeGet;
}

- (NSTimeInterval)durationCacheForApi:(CNAPIManager *)manager
{

    return 30;
}

- (BOOL)manager:(CNAPIManager *)manager isCorrectWithParamsData:(NSDictionary *)params
{
    return YES;
}

- (void)managerCallAPIDidSuccess:(CNAPIManager *)manager
{

    id result = [self.manager fetchDataWithReformer:nil];
    NSString *string = [self.manager fetchDataWithReformer:self.dataReformer];
    self.showResultLabel.text = @"请求成功!";
    NSLog(@"请求成功");
}

- (void)managerCallAPIDidFailed:(CNAPIManager *)manager
{

    self.showResultLabel.text = [NSString stringWithFormat:@"请求失败:%@", self.manager.errorMessage];
    NSLog(@"请求失败:%@", self.manager.errorMessage);
}

#pragma mark - Getter/Setter
- (CNAPIManager *)manager
{

    if (_manager==nil) {

        _manager = [[CNAPIManager alloc] init];
        _manager.paramSource = self;
        _manager.delegate = self;
        _manager.validator = self;
    }

    return _manager;
}

- (ViewControllerReformer *)dataReformer
{
    if (_dataReformer==nil) {

        _dataReformer = [[ViewControllerReformer alloc] init];
    }

    return _dataReformer;
}

@end

Latest podspec

{
    "name": "CoconutNetworking",
    "version": "1.0.2",
    "summary": "A iOS networking util.",
    "homepage": "https://github.com/CoconutGZ/CoconutNetworking",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "ajin": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/CoconutGZ/CoconutNetworking.git",
        "tag": "1.0.2"
    },
    "source_files": "CNNetworking/**/CoconutNetworking/*.{h,m}",
    "requires_arc": true,
    "dependencies": {
        "AFNetworking": [],
        "FMDB": []
    }
}

Pin It on Pinterest

Share This