Giter Site home page Giter Site logo

dxdal's Introduction

Using DXDAL

At first you should create request factory

@interface MyRequestFactory : DXDALRequestFactory

where you should override two methods:

- (id <DXDALDataProvider>)getDataProvider;
- (Class)getDefaultRequestClass; 

for example:

- (id<DXDALDataProvider>)getDataProvider {
    return [[DXDALDataProviderHTTP alloc] initWithBaseURL:[NSURL URLWithString:@"http://google.com"]];
}

- (Class)getDefaultRequestClass {
    return [DXDALRequestHTTP class];
}

Default parameters

use

- (void)addDefaultConfig:(DXDALRequestConfigurationBlock)configBlock;

ั‚ะพ add default configuration blocks for every request, for example:

MyRequestFactory *factory = [MyRequestFactory sharedInstance];
       
[factory addDefaultConfig:^(id request) {
            [request addParam:user.userID withName:@"user_id"];
}];

Requestst definition

GET Request

- (DXDALRequest *)getLastUpdateDate {
    return [self buildRequestWithConfigBlock:^(DXDALRequestHTTP *request) {
        request.httpMethod = @"GET";
        request.httpPath = @"get_last_updated"; // method
        
        [request addParam:somedate withName:@"date"];
        
        request.parser = [DXDALParserJSON new];
        request.mapper = [MDUpdateDateMapper new];
        
        request.entityClass = [NSString class];
        
    }];
}

POST Request

- (DXDALRequest*)loginUserName:(NSString *)userName password:(NSString *)password {
    return [self buildRequestWithConfigBlock:^(DXDALRequestHTTP *request) {
        request.httpMethod = @"POST";
        request.httpPath = @"check_credentials"; //metod
        
        [request addParam:userName withName:@"username"];
        [request addParam:password withName:@"password"];
        
        request.parser = [DXDALParserJSON new];
        request.mapper = [UserModelMapper new];
        request.entityClass = [User class];
        
        [request addErrorHandler:[self standartErrorHandler]];
    }];
}

ModelMapper

it's class which implements DXDALMapper protocol with method:

- (id)mapFromInputData:(id)inputData withClass:(Class)mappingClass;

where inputData - it's parsed dictionary from server response, for example:

- (id)mapFromInputData:(id)inputData withClass:(Class)mappingClass {

    User *user = [[User alloc] init];
        
    user.firstName = [inputData objectForKey:@"first_name"];
    user.lastName = [inputData objectForKey:@"last_name"];
    
    return user;
}

Using request example

DXDALRequestSuccesHandler successLogin = ^(id response){
    
    User *user = response;
    NSLog(@"user name: %@ %@", user.firstName, user.lastName);

}

MDAuthRequestFactory *factory = [MDAuthRequestFactory sharedInstance];
    
DXDALRequest *request = [factory loginUserName:_loginField.text password:_passwordField.text];
[request addSuccessHandler:successLogin];
[request addErrorHandler:^(NSError *error)
{
    NSLog(@"Login request error: %@", [error description]);
}];

[request start];

Progress

You can add progress block:

- (void)addProgressHandler:(DXDALProgressHandler)handler;

it will returns progressValue and progressDelta, for example:

DXDALProgressHandler progressHandler = ^(float progress, float progressDelta) {
    NSLog(@"progress: %f, progressDelta: %f", progress, progressDelta);
};

[request addProgressHandler:progressHandler];

dxdal's People

Contributors

mashkovmax avatar sergeyzenchenko avatar thesantaclaus avatar thesooth avatar yuriybosov avatar maksym-letiushov avatar igor-khomich avatar malaar avatar alexburkhay avatar goncharik avatar korzun1993 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.