3
3
4
4
/* *
5
5
* A key for `NSError` user info dictionaries.
6
- *
6
+ *
7
7
* The corresponding value is the parsed response body for an HTTP error.
8
8
*/
9
9
extern NSString *const SWGResponseObjectErrorKey;
@@ -20,56 +20,197 @@ extern NSString *const SWGResponseObjectErrorKey;
20
20
@property (nonatomic , assign ) BOOL logHTTP;
21
21
@property (nonatomic , readonly ) NSOperationQueue * queue;
22
22
23
+ /* *
24
+ * Get the Api Client instance from pool
25
+ *
26
+ * @param baseUrl The base url of api client.
27
+ *
28
+ * @return The SWGApiClient instance.
29
+ */
23
30
+(SWGApiClient *)sharedClientFromPool : (NSString *)baseUrl ;
24
31
32
+ /* *
33
+ * Get the operations queue
34
+ *
35
+ * @return The `shardQueue` static variable.
36
+ */
25
37
+(NSOperationQueue *) sharedQueue ;
26
38
39
+ /* *
40
+ * Turn on logging
41
+ *
42
+ * @param state logging state, must be `YES` or `NO`
43
+ */
27
44
+(void )setLoggingEnabled : (bool ) state ;
28
45
46
+ /* *
47
+ * Clear Cache
48
+ */
29
49
+(void )clearCache ;
30
50
51
+ /* *
52
+ * Turn on cache
53
+ *
54
+ * @param enabled If the cached is enable, must be `YES` or `NO`
55
+ */
31
56
+(void )setCacheEnabled : (BOOL ) enabled ;
32
57
58
+ /* *
59
+ * Get the request queue size
60
+ *
61
+ * @return The size of `queuedRequests` static variable.
62
+ */
33
63
+(unsigned long )requestQueueSize ;
34
64
65
+ /* *
66
+ * Set the client unreachable
67
+ *
68
+ * @param state off line state, must be `YES` or `NO`
69
+ */
35
70
+(void ) setOfflineState : (BOOL ) state ;
36
71
72
+ /* *
73
+ * Get the client reachability
74
+ *
75
+ * @return The client reachability.
76
+ */
37
77
+(AFNetworkReachabilityStatus) getReachabilityStatus ;
38
78
79
+ /* *
80
+ * Get the next request id
81
+ *
82
+ * @return The next executed request id.
83
+ */
39
84
+(NSNumber *) nextRequestId ;
40
85
86
+ /* *
87
+ * Generate request id and add it to the queue
88
+ *
89
+ * @return The next executed request id.
90
+ */
41
91
+(NSNumber *) queueRequest ;
42
92
93
+ /* *
94
+ * Remove request id from the queue
95
+ *
96
+ * @param requestId The request which will be removed.
97
+ */
43
98
+(void ) cancelRequest : (NSNumber *)requestId ;
44
99
100
+ /* *
101
+ * URL encode NSString
102
+ *
103
+ * @param unescaped The string which will be escaped.
104
+ *
105
+ * @return The escaped string.
106
+ */
45
107
+(NSString *) escape : (id )unescaped ;
46
108
109
+ /* *
110
+ * Customize the behavior when the reachability changed
111
+ *
112
+ * @param changeBlock The block will be executed when the reachability changed.
113
+ */
47
114
+(void ) setReachabilityChangeBlock : (void (^)(int ))changeBlock ;
48
115
116
+ /* *
117
+ * Set the client reachability strategy
118
+ *
119
+ * @param host The host of SWGApiClient.
120
+ */
49
121
+(void ) configureCacheReachibilityForHost : (NSString *)host ;
50
122
123
+ /* *
124
+ * Detect Accept header from accepts NSArray
125
+ *
126
+ * @param accepts NSArray of header
127
+ *
128
+ * @return The Accept header
129
+ */
51
130
+(NSString *) selectHeaderAccept : (NSArray *)accepts ;
131
+
132
+ /* *
133
+ * Detect Content-Type header from contentTypes NSArray
134
+ *
135
+ * @param contentTypes NSArray of header
136
+ *
137
+ * @return The Content-Type header
138
+ */
52
139
+(NSString *) selectHeaderContentType : (NSArray *)contentTypes ;
53
140
141
+ /* *
142
+ * Set header for request
143
+ *
144
+ * @param value The header value
145
+ * @param forKey The header key
146
+ */
54
147
-(void )setHeaderValue : (NSString *) value
55
- forKey : (NSString *) forKey ;
148
+ forKey : (NSString *) forKey ;
149
+
150
+ /* *
151
+ * Update header parameters and query parameters for authentication
152
+ *
153
+ * @param headers The header parameter will be udpated, passed by pointer to pointer.
154
+ * @param querys The query parameters will be updated, passed by pointer to pointer.
155
+ * @param authSettings The authentication names NSArray.
156
+ */
157
+ - (void ) updateHeaderParams : (NSDictionary **)headers
158
+ queryParams : (NSDictionary **)querys
159
+ WithAuthSettings : (NSArray *)authSettings ;
56
160
161
+ /* *
162
+ * Perform request
163
+ *
164
+ * Request with non-empty response
165
+ *
166
+ * @param path Request url.
167
+ * @param method Request method.
168
+ * @param queryParams Request query parameters.
169
+ * @param body Request body.
170
+ * @param headerParams Request header parameters.
171
+ * @param authSettings Request authentication names.
172
+ * @param requestContentType Request content-type.
173
+ * @param responseContentType Response content-type.
174
+ * @param completionBlock The block will be executed when the request completed.
175
+ *
176
+ * @return The request id.
177
+ */
57
178
-(NSNumber *) dictionary : (NSString *) path
58
179
method : (NSString *) method
59
180
queryParams : (NSDictionary *) queryParams
60
181
body : (id ) body
61
182
headerParams : (NSDictionary *) headerParams
183
+ authSettings : (NSArray *) authSettings
62
184
requestContentType : (NSString *) requestContentType
63
185
responseContentType : (NSString *) responseContentType
64
186
completionBlock : (void (^)(NSDictionary *, NSError *))completionBlock ;
65
187
188
+ /* *
189
+ * Perform request
190
+ *
191
+ * Request with empty response
192
+ *
193
+ * @param path Request url.
194
+ * @param method Request method.
195
+ * @param queryParams Request query parameters.
196
+ * @param body Request body.
197
+ * @param headerParams Request header parameters.
198
+ * @param authSettings Request authentication names.
199
+ * @param requestContentType Request content-type.
200
+ * @param responseContentType Response content-type.
201
+ * @param completionBlock The block will be executed when the request completed.
202
+ *
203
+ * @return The request id.
204
+ */
66
205
-(NSNumber *) stringWithCompletionBlock : (NSString *) path
67
206
method : (NSString *) method
68
207
queryParams : (NSDictionary *) queryParams
69
208
body : (id ) body
70
209
headerParams : (NSDictionary *) headerParams
210
+ authSettings : (NSArray *) authSettings
71
211
requestContentType : (NSString *) requestContentType
72
212
responseContentType : (NSString *) responseContentType
73
213
completionBlock : (void (^)(NSString *, NSError *))completionBlock ;
74
214
@end
75
215
216
+
0 commit comments