Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

DAL

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 DXDAL.xcodeproj
Octocat-spinner-32 DXDAL.xcworkspace
Octocat-spinner-32 DXDAL
Octocat-spinner-32 DXDALTests
Octocat-spinner-32 TestProject
Octocat-spinner-32 .gitignore
Octocat-spinner-32 License.txt
Octocat-spinner-32 Podfile
Octocat-spinner-32 README.md
README.md

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];
Something went wrong with that request. Please try again.