-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmanual.rtf
285 lines (245 loc) · 12.8 KB
/
manual.rtf
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
{\rtf1\ansi\ansicpg1251\cocoartf1138\cocoasubrtf470
{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fnil\fcharset0 Menlo-Regular;\f2\fmodern\fcharset0 Courier;
\f3\fmodern\fcharset0 Courier-Bold;}
{\colortbl;\red255\green255\blue255;\red38\green38\blue38;\red170\green13\blue145;\red133\green0\blue175;
\red217\green11\blue0;\red63\green110\blue116;\red246\green246\blue246;\red46\green13\blue110;\red46\green110\blue185;
\red38\green71\blue75;\red196\green26\blue22;\red46\green111\blue253;\red230\green87\blue141;\red92\green38\blue153;
}
\paperw11900\paperh16840\margl1440\margr1440\vieww14620\viewh10900\viewkind0
\deftab720
\pard\pardeftab720\sa200
\f0\b\fs48 \cf0 Using DXDAL 2.0\
\pard\pardeftab720\sa300
\b0\fs28 \cf2 At first you should create request builder\
\pard\tx560\pardeftab560\pardirnatural
\f1\fs22 \cf3 \CocoaLigature0 @interface \cf4 MyRequestBuilder\cf0 : NJDXDALRequestBuilder\
\
\
\pard\pardeftab720\sa200
\f0\b\fs48 \cf0 \CocoaLigature1 Default parameters\
\pard\pardeftab720\sa300
\b0\fs28 \cf2 use\
\pard\tx560\pardeftab560\pardirnatural
\f1\fs22 \cf0 \CocoaLigature0 - (void)\cf5 addDefaultConfig\cf0 :(\cf6 NJDXDALOperationConfigurationBlock\cf0 ) configurationBlock;\
\
\pard\tx560\pardeftab560\pardirnatural
\f0\fs28 \cf2 \CocoaLigature1 \uc0\u1090 \u1086 add default configuration blocks for every operation, for example:\
\pard\pardeftab720
\f2\fs26 \cf2 \cb7 \
\pard\tx560\pardeftab560\pardirnatural
\f1\fs22 \cf4 \cb1 \CocoaLigature0 MyRequestBuilder\cf0 *requestBuilder = [\cf4 MyRequestBuilder\cf0 \cf8 new\cf0 ];\
\cf6 NJDXDALOperationConfigurationBlock\cf0 configBlock = ^(\cf6 NJDXDALHTTPOperation\cf0 *operation)\
\{\
// some configurations of operation.v \
\};\
[requestBuilder \cf5 addDefaultConfig\cf0 :configBlock];\
\
\
\
\pard\pardeftab720\sa200
\f0\b\fs48 \cf0 \CocoaLigature1 Operations definition
\fs36 \cf9 \
\pard\pardeftab720
\cf0 Mapping configuration\cf9 \
\
\pard\tx560\pardeftab560\pardirnatural
\f1\b0\fs22 \cf6 \CocoaLigature0 NJDXDALOperationConfigurationBlock\cf0 configBlock = ^(\cf6 NJDXDALHTTPOperation\cf0 *operation)\
\{\
// some operation configuration \
\
// Create configuration for mapper\
\cf6 NJDXDALMappingConfigurator\cf0 *rootConfig = [[\cf6 NJDXDALMappingConfigurator\cf0 \cf8 alloc\cf0 ] \cf10 initForClass\cf0 :[\cf6 Meta\cf0 \cf8 class\cf0 ]];\
[rootConfig \cf10 setCorrespondenceOfProperty\cf0 :\cf11 @"codeData"\cf0 \cf10 toDataField\cf0 :\cf11 @"code"\cf0 ];\
\cf6 NJDXDALMappingController\cf0 *mapper = [[\cf6 NJDXDALMappingController\cf0 \cf8 alloc\cf0 ] \cf10 initWithRootMappingConfigurator\cf0 :rootConfig \cf10 keyPath\cf0 :\cf11 @"meta"\cf0 ];\
mapper.\cf6 delegate\cf0 = operation;\
operation.\cf6 mapper\cf0 = mapper;\
\};\
\pard\pardeftab720
\f0\b\fs36 \cf9 \CocoaLigature1 \
\
\pard\pardeftab720\sa200
\cf2 GET Operation\
\pard\tx560\pardeftab560\pardirnatural
\f1\b0\fs22 \cf6 \CocoaLigature0 NJDXDALOperationConfigurationBlock\cf0 configBlock = ^(\cf6 NJDXDALHTTPOperation\cf0 *operation)\
\{\
operation.\cf6 httpMethod\cf0 = \cf11 @"GET"\cf0 ;\
operation.\cf6 httpPath\cf0 = \cf11 @"/v2/venues/40a55d80f964a52020f31ee3"\cf0 ;\
[operation \cf10 addParam\cf0 :\cf11 @"oauth_token"\cf0 \cf10 value\cf0 :\cf11 @"XXX"\cf0 ];\
[operation \cf10 addParam\cf0 :\cf11 @"v"\cf0 \cf10 value\cf0 :\cf11 @"YYYYMMDD"\cf0 ];\
\
// some mapping configs\
\
// set current operation as delegate for mapper \
mapper.\cf6 delegate\cf0 = operation;\
\
// set your custom mapper as operation mapper\
operation.\cf6 mapper\cf0 = mapper;\
\
\};\
\pard\pardeftab720
\f3\b\fs26 \cf2 \cb7 \CocoaLigature1 \
\pard\pardeftab720
\f0\fs36 \cf9 \cb1 \
\pard\tx560\pardeftab560\pardirnatural
\f1\b0\fs22 \cf6 \CocoaLigature0 NJDXDALOperation\cf0 *_operation = [requestBuilder \cf10 operationWithUrl\cf0 :\cf11 @"https://api.foursquare.com"\cf0 \cf10 configurationBlock\cf0 :configBlock \cf10 contentType\cf0 :\cf11 @"json"\cf0 ];
\f0\b\fs36 \cf9 \CocoaLigature1 \
\pard\tx560\pardeftab560\pardirnatural
\fs48 \cf9 \
\pard\pardeftab720\sa200
\fs36 \cf2 POST Operation\
\pard\tx560\pardeftab560\pardirnatural
\f1\b0\fs22 \cf6 \CocoaLigature0 NJDXDALOperationConfigurationBlock\cf0 configBlock = ^(\cf6 NJDXDALHTTPOperation\cf0 *operation)\
\{\
operation.\cf6 httpMethod\cf0 = \cf11 @"POST"\cf0 ;\
operation.\cf6 httpPath\cf0 = \cf11 @"path"\cf0 ;\
[operation \cf10 addParam\cf0 :\cf11 @"param1"\cf0 \cf10 value\cf0 :\cf11 @"v1"\cf0 ];\
[operation \cf10 addParam\cf0 :\cf11 @"param2"\cf0 \cf10 value\cf0 :\cf11 @"v2"\cf0 ];\
\
// some mapping configs\
\
// set current operation as delegate for mapper \
mapper.\cf6 delegate\cf0 = operation;\
\
// set your custom mapper as operation mapper\
operation.\cf6 mapper\cf0 = mapper;\
\
\};
\f0\b\fs36 \cf9 \CocoaLigature1 \
\
\
\pard\tx560\pardeftab560\pardirnatural
\fs48 \cf0 About Parser
\fs36 \cf9 \
\
\b0\fs28 \cf0 To use NJDXDAL parser you need to provide it with NSData object containing data for parsing. In addition you need to provide info about type of passed data. It should be an NSString e.g. "xml" or "json". Also you should have an NJDXDALParserDelegate to catch parsed data.\
\
If you want to add a parser to the system, you should do the following:\
\
1. Your parser name should start with "NJDXDALParser" and have at least one character after it to specify type of data that will be parsed, e.g. NJDXDALParserBPLIST;\
2. Your parser should implement NJDXDALParserProtocol;\
3. Necessarily fill the obtained error property if happen any parsing problem;\
4. (id)parseData:error: method should return exclusively NSArray or NSDictionary or nil in case of error;\
\pard\tx560\pardeftab560\pardirnatural
\b\fs36 \cf9 \
\pard\tx560\pardeftab560\pardirnatural
\cf0 NJDXDALParserProtocol follows.\cf9 \
\
\f1\b0\fs22 \cf0 @\cf12 protocol\cf0 \cf4 NJDXDALParserProtocol\cf0 \cf13 <NSObject>\cf0 \
\
+ (BOOL)\cf5 isDataTypeAcceptable\cf0 :(NSString *)type; // Check if data type is appropriate.\
+ (id)\cf5 parseData\cf0 :(NSData *)aData error:(NSError *)anError; // Parse data. Using an error necessarily! \
// Return an NSArray or an NSDictionary.\
@end\
\
\
\
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural
\f0\b\fs48 \cf0 MAPPING CONFIGURATION
\b0\fs24 \
\
\fs28 For using mapping first you need to create root object of class NJDXDALMappingConfigurator. This class sets a mapping object class and mapping configuration for nesting level in data. For every level you need NJDXDALMappingConfigurator object. \
\
For create use method:
\fs24 \
\pard\tx560\pardeftab560\pardirnatural
\f1\fs22 \cf0 \CocoaLigature0 - (\cf3 id\cf0 )initForClass:(\cf14 Class\cf0 )mappingClass;\
\
\f0\fs28 If property of mapping class is some custom object, you have to set type of this property using method:
\f1\fs22 \
- (\cf3 void\cf0 )setMappingOfProperty:(\cf14 NSString\cf0 *)propertyName toType:(\cf14 NSString\cf0 *)propertyType;\
\f0\fs28 \
If property of mapping class is object, which contains another objects, you have to create \CocoaLigature1 NJDXDALMappingConfigurator object for inner level and connect it to current using method:
\f1\fs22 \CocoaLigature0 \
- (\cf3 void\cf0 )setMappingOfProperty:(\cf14 NSString\cf0 *)propertyName toMappingConfigurator:(\cf6 NJDXDALMappingConfigurator\cf0 *)configurator;
\f0\fs24 \CocoaLigature1 \
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural
\f1\fs22 \cf0 \CocoaLigature0 \
\f0\fs28 If property name is not equal to name of field in received data, you have to set correspondence manually using method:\
\pard\tx560\pardeftab560\pardirnatural
\f1\fs22 \cf0 - (\cf3 void\cf0 )setCorrespondenceOfProperty:(\cf14 NSString\cf0 *)propertyName toDataField:(\cf14 NSString\cf0 *)dataField;\
\
\f0\fs28 If property of mapping class is NSDate type, you can use following methods to configure mapping on each level:
\f1\fs22 \
- (\cf3 void\cf0 )setDateStyle:(\cf14 NSInteger\cf0 )formatterDateStyle;\
- (\cf3 void\cf0 )setTimeStyle:(\cf14 NSInteger\cf0 )formatterTimeStyle;\
- (\cf3 void\cf0 )setDateFormat:(\cf14 NSString\cf0 *)dateFormat;\
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural
\f0\fs24 \cf0 \CocoaLigature1 \
\fs28 If property of mapping class is NSDictionary or NSMutableDictionary, you have to create new NJDXDALMappingConfigurator object for class "NSDictionary" and connect it to root configuration.\
Then all your configurations are set, you can create NJDXDALMappingController object with root NJDXDALMappingConfigurator object and key path of required data in received data (if needed).\
For example, you want to map a class BookStore, which has following interface:\
\fs24 \
\pard\tx560\pardeftab560\pardirnatural
\f1\fs22 \cf3 \CocoaLigature0 @interface\cf0 BookStore : \cf14 NSObject\cf0 \
\
\cf3 @property\cf0 (\cf3 nonatomic\cf0 , \cf3 strong\cf0 ) \cf14 NSString\cf0 *name;\
\cf3 @property\cf0 (\cf3 nonatomic\cf0 , \cf3 assign\cf0 ) \cf14 NSNumber\cf0 *territory;\
\cf3 @property\cf0 (\cf3 nonatomic\cf0 , \cf3 strong\cf0 ) \cf14 NSArray\cf0 *catalogue;\
\cf3 @property\cf0 (\cf3 nonatomic\cf0 , \cf3 strong\cf0 ) \cf14 NSDictionary\cf0 *numberOfArticles;\
\
\cf3 @end\
\
\
\f0\b\fs36 \cf0 Example
\f1\b0\fs22 \cf3 \
\
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural
\f0\fs28 \cf0 \CocoaLigature1 JSON response has next form:
\fs24 \
\
\pard\tx560\pardeftab560\pardirnatural
\f1\fs22 \cf0 \CocoaLigature0 receivedData = \{\
foodstore = \{\
someInformation = @"info"\
\}\
bookstore = \
\{\
"name": "HappyBook",\
"territory": "24.56",\
"catalogue":\
[\
\{ \
"title": "RestKit Object Mapping Intro",\
"body": "This article details how to use RestKit object mapping...",\
"author": "Blake Watters",\
"publication_date": "7/4/2011",\
"copies": "1"\
\},\
\{ \
"title": "RestKit 1.0 Released",\
"body": "RestKit 1.0 has been released to much fanfare across the galaxy...",\
"author": "Blake Watters",\
"publication_date": "9/4/2011",\
"copies": "2"\
\}\
],\
"numberOf" : \
\{\
"firstKey" : "firstValue",\
"secondKey" : "secondValue",\
"thirdKey" : \
\{ \
"title": "RestKit Object Mapping Intro",\
"body": "This article details how to use RestKit object mapping...",\
"author": "Blake Watters",\
"publication_date": "7/4/2011",\
"copies": "1"\
\}\
\}\
\}\
\}\
\
\f0\fs28 Config code for it:
\f1\fs22 \
\
\cf6 NJDXDALMappingConfigurator\cf0 *rootConfigurator = [[\cf6 NJDXDALMappingConfigurator\cf0 \cf8 alloc\cf0 ] \cf10 initForClass\cf0 :[\cf6 BookStore\cf0 \cf8 class\cf0 ]]; // create rootConfigurator object\
[rootConfigurator \cf10 setMappingOfProperty\cf0 :\cf11 @"catalogue"\cf0 \cf10 toType\cf0 :\cf11 @"Article"\cf0 ]; //Set type of content property "catalogue" to custom object type "Article"\
[rootConfigurator \cf10 setCorrespondenceOfProperty\cf0 :\cf11 @"numberOfArticles"\cf0 \cf10 toDataField\cf0 :\cf11 @"numberOf"\cf0 ]; // set correspondence between property name "numberOfArticles" and field "numberOf" in received data\
\
\cf6 NJDXDALMappingConfigurator\cf0 *numberOfArticlesConfigurator = [[\cf6 NJDXDALMappingConfigurator\cf0 \cf8 alloc\cf0 ] \cf10 initForClass\cf0 :[\cf14 NSDictionary\cf0 \cf8 class\cf0 ]]; // create new configurator for property of type NSDictionary\
[numberOfArticlesConfigurator \cf10 setMappingOfProperty\cf0 :\cf11 @"thirdKey"\cf0 \cf10 toType\cf0 :\cf11 @"Article"\cf0 ]; // set type for key "third key" in NSDictionary to "Article"\
\
[rootConfigurator \cf10 setMappingOfProperty\cf0 :\cf11 @"numberOfArticles"\cf0 \cf10 toMappingConfigurator\cf0 :numberOfArticlesConfigurator]; // connect NSDictionary configurator to root configurator\
\
\cf6 NJDXDALMappingController\cf0 *mappingController = [[\cf6 NJDXDALMappingController\cf0 \cf8 alloc\cf0 ] \cf10 initWithRootMappingConfigurator\cf0 :rootConfigurator \cf10 keyPath\cf0 :\cf11 @"bookstore"\cf0 ]; // create controller object with root configurator\
}