-
Notifications
You must be signed in to change notification settings - Fork 3
/
MainViewController.m
121 lines (98 loc) · 4.19 KB
/
MainViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// MainViewController.m
// NJDXDAL
//
// Created by LimeStore on 10.07.12.
// Copyright (c) 2012 111Minutes. All rights reserved.
//
#import "MainViewController.h"
#import "NJDXDALHTTPOperation.h"
#import "NJDXDALOperationsCenter.h"
#import "NJDXDALRequestBuilder.h"
#import "NJDXDALMappingController.h"
#import "NJDXDALMappingConfigurator.h"
#import "NJDXDALParser.h"
#import "Meta.h"
@interface MainViewController ()
{
NJDXDALOperationsCenter* _httpOpManager;
NSMutableURLRequest* _lastRequest;
NJDXDALOperation *_operation;
}
@end
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100, 100, 100, 50);
[button setTitle:@"Add" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonPressed)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button2.frame = CGRectMake(100, 200, 100, 50);
[button2 setTitle:@"Cancel" forState:UIControlStateNormal];
[button2 addTarget:self action:@selector(cancelPressed)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button2];
_httpOpManager = [NJDXDALOperationsCenter new];
}
-(void)buttonPressed
{
/* NJDXDALRequestBuilder *requestBuilder = [NJDXDALRequestBuilder new];
NJDXDALOperationConfigurationBlock configBlock = ^(NJDXDALHTTPOperation *operation) {
operation.httpMethod = @"GET";
operation.httpPath = @"/v2/venues/40a55d80f964a52020f31ee3";
[operation addParam:@"oauth_token" value:@"XXX"];
[operation addParam:@"v" value:@"YYYYMMDD"];
NJDXDALMappingConfigurator *rootConfig = [[NJDXDALMappingConfigurator alloc] initForClass:[Meta class]];
[rootConfig setCorrespondenceOfProperty:@"codeData" toDataField:@"code"];
NJDXDALMappingController *mapper = [[NJDXDALMappingController alloc] initWithRootMappingConfigurator:rootConfig keyPath:@"meta"];
mapper.delegate = operation;
operation.mapper = mapper;
};
_operation = [requestBuilder operationWithUrl:@"https://api.foursquare.com" configurationBlock:configBlock contentType:@"json"];
[_operation start];*/
/* NJDXDALRequestBuilder *requestBuilder = [NJDXDALRequestBuilder new];
NJDXDALOperationConfigurationBlock configBlock = ^(NJDXDALHTTPOperation *operation) {
operation.httpMethod = @"POST";
[operation addParam:@"password" value:@"1111aa"];
[operation addParam:@"email" value:@"[email protected]"];
};
NJDXDALOperation *loginOperation = [requestBuilder operationWithUrl:@"http://kc.9bitinteractive.com/mobile/users/login" configurationBlock:configBlock contentType:@"JSON"];
[loginOperation start];*/
NJDXDALRequestBuilder *requestBuilder = [NJDXDALRequestBuilder new];
NJDXDALOperationConfigurationBlock configBlock = ^(NJDXDALHTTPOperation *operation) {
operation.httpMethod = @"FILES";
[operation addParam:@"user_id" value:@"20"];
[operation addParam:@"key" value:@"a1c5bf2ec654779202b327444feb69d1"];
[operation addParam:@"email" value:@"[email protected]"];
[operation addFile:UIImageJPEGRepresentation([UIImage imageNamed:@"pic.jpg"] , 90) withName:@"pic.jpg"];
};
NJDXDALOperation *loginOperation = [requestBuilder operationWithUrl:@"http://0.0.0.0:3000/index/upload" configurationBlock:configBlock contentType:@"JSON"];
[loginOperation start];
}
-(void)cancelPressed
{
NSLog(@"Canceling...");
[_operation cancel];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end