Permalink
Browse files

refactoring 2

  • Loading branch information...
Malaar committed Mar 25, 2012
1 parent 194f4be commit 1b096b95b86a47ac920378bc57c40d932657463e

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -9,7 +9,6 @@
#import "DXDALDataProviderMultipartForm.h"
#import "DXDALRequestMultipartForm.h"
#import "DXDALResponseParserJSON.h"
#import "AFNetworking.h"
#import "JSONKit.h"
@@ -34,7 +34,8 @@ typedef void (^DXDALRequestErrorHandler)(NSError *error);
- (void)resume;
- (void)addParam:(NSString *)param withName:(NSString *)key;
- (void)addParamString:(NSString *)param withName:(NSString *)key;
- (void)addParamNumber:(NSNumber*)param withName:(NSString *)key;
- (void)didFinishWithResponse:(id)response;
- (void)didFailWithResponse:(id)response;
@@ -37,13 +37,22 @@ - (id)initWithDataProvider:(id<DXDALDataProvider>)dataProvider {
return self;
}
- (void)addParam:(NSString *)param withName:(NSString *)key {
- (void)addParamString:(NSString *)param withName:(NSString *)key {
assert(key != nil);
assert(param != nil);
[_params setObject:param forKey:key];
}
- (void)addParamNumber:(NSNumber*)param withName:(NSString *)key

This comment has been minimized.

@fylfot

fylfot Mar 26, 2012

А я бы оставил addParam принимающий NSObject, класс которого проверяется на типы NSArray, NSDictionary, NSNumber, NSString и затем их обрабатывать как положено.

This comment has been minimized.

@Igor-Khomich

Igor-Khomich via email Mar 26, 2012

Contributor

This comment has been minimized.

@sergeyzenchenko

sergeyzenchenko Mar 27, 2012

Contributor

да тебе

This comment has been minimized.

@Igor-Khomich

Igor-Khomich via email Mar 28, 2012

Contributor

This comment has been minimized.

@fylfot

fylfot Mar 28, 2012

Парни, я не знаю чей это коммит, я лишь прокоментировал ченж из коммита.

{
assert(key != nil);
assert(param != nil);
[_params setObject:param forKey:key];
}
- (void)addSuccessHandler:(DXDALRequestSuccesHandler)handler {
assert(handler != nil);
[_successHandlers addObject:[handler copy]];

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -6,10 +6,11 @@
#import "DXDALDataProviderHTTP.h"
#import "DXDALRequestHTTP.h"
#import "AFNetworking.h"
#import "DXDALResponseParserJSON.h"
#import "JSONKit.h"
#import "DXDALRequestHTTP.h"
#import "DXDALParser.h"
#import "DXDALMapper.h"
@implementation DXDALDataProviderHTTP
@@ -49,10 +50,12 @@ - (AFHTTPRequestOperation*) operationFromRequest:(DXDALRequestHTTP*) httpRequest
NSURLRequest *urlRequest = [self urlRequestFromRequest:httpRequest];
NSLog(@"start request: %@", [urlRequest URL]);
AFHTTPRequestOperation *operation = [_httpClient HTTPRequestOperationWithRequest:urlRequest success:^(AFHTTPRequestOperation *operation, id responseObject) {
id result = [httpRequest.parser parseJSON:operation.responseString withEntityClass:httpRequest.entityClass];
AFHTTPRequestOperation *operation = [_httpClient HTTPRequestOperationWithRequest:urlRequest success:^(AFHTTPRequestOperation *operation, id responseObject)
{
id parsedObject = [httpRequest.parser parseString:operation.responseString];
id result = [httpRequest.mapper mapFromInputData:parsedObject withClass:httpRequest.entityClass];
[httpRequest didFinishWithResponse:result];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSMutableDictionary *userInfo = [[error userInfo] mutableCopy];
@@ -0,0 +1,15 @@
//
// DXDALMapperStandart.h
// DXDAL
//
// Created by Malaar on 25.03.12.
// Copyright (c) 2012 111Minutes. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "DXDALMapper.h"
@interface DXDALMapperStandart : NSObject <DXDALMapper>
@end
@@ -0,0 +1,32 @@
//
// DXDALMapperStandart.m
// DXDAL
//
// Created by Malaar on 25.03.12.
// Copyright (c) 2012 111Minutes. All rights reserved.
//
#import "DXDALMapperStandart.h"
#import "NSObject+JTObjectMapping.h"
@implementation DXDALMapperStandart
- (id) mapFromInputData:(id)inputData withClass:(Class)mappingClass
{
id result = nil;
if ([inputData isKindOfClass:[NSArray class]]) {
result = [NSMutableArray new];
for (NSDictionary *dict in inputData) {
NSObject *obj = [mappingClass objectFromJSONObject:dict mapping:[mappingClass mapping]];
[result addObject:obj];
}
} else {
result = [mappingClass objectFromJSONObject:inputData mapping:[mappingClass mapping]];
}
return result;
}
@end
@@ -7,11 +7,11 @@
//
#import <Foundation/Foundation.h>
#import "DXDALResponseParser.h"
#import "DXDALParser.h"
@class DXDALRequestHTTP;
@interface DXDALResponseParserJSON : NSObject <DXDALResponseParser>
@interface DXDALParserJSON : NSObject <DXDALParser>
@end
@@ -0,0 +1,21 @@
//
// DXDALResponseParserJSON.m
// DXDAL
//
// Created by Sergey Zenchenko on 3/9/12.
// Copyright (c) 2012 111Minutes. All rights reserved.
//
#import "DXDALParserJSON.h"
#import "JSONKit.h"
//#import "DXDALRequestHTTP.h"
@implementation DXDALParserJSON

This comment has been minimized.

@fylfot

fylfot Mar 28, 2012

Я так полагаю автоматический маппинг теперь погиб?

А то я хотел патч предложить:
if (!httpRequest.entityClass) { // Ignore Auto Mapping
return jsonResult;
}

- (id) parseString:(NSString *)aString
{
return [aString objectFromJSONString];
}
@end
@@ -8,7 +8,8 @@
#import <Foundation/Foundation.h>
#import "DXDALRequest.h"
@protocol DXDALResponseParser;
@protocol DXDALParser;
@protocol DXDALMapper;
@interface DXDALRequestHTTP : DXDALRequest
@@ -19,7 +20,7 @@
@property(nonatomic, readwrite, strong) NSDictionary *defaultHTTPHeaders;
@property (nonatomic, assign) Class entityClass;
@property (nonatomic, strong) NSDictionary *mapping;
@property (nonatomic, strong) id<DXDALResponseParser> parser;
@property (nonatomic, strong) id<DXDALParser> parser;
@property (nonatomic, strong) id<DXDALMapper> mapper;
@end
@@ -5,15 +5,16 @@
//
#import "DXDALRequestHTTP.h"
#import "DXDALResponseParser.h"
@implementation DXDALRequestHTTP
@synthesize httpMethod = _httpMethod;
@synthesize httpPath = _httpPath;
@synthesize defaultHTTPHeaders = _defaultHTTPHeaders;
@synthesize entityClass, mapping;
@synthesize entityClass;
@synthesize parser;
@synthesize mapper;
- (NSString*)httpMethod {
return [_httpMethod uppercaseString];

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

0 comments on commit 1b096b9

Please sign in to comment.