-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOTRestResponse.h
More file actions
182 lines (146 loc) · 3.46 KB
/
OTRestResponse.h
File metadata and controls
182 lines (146 loc) · 3.46 KB
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
//
// OTRestResponse.h
// OTRestFramework
//
// Created by Blake Watters on 7/28/09.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "OTRestRequest.h"
#import "DocumentRoot.h"
@interface OTRestResponse : NSObject {
OTRestRequest* _request;
NSHTTPURLResponse* _httpURLResponse;
NSMutableData* _payload;
NSError* _failureError;
}
/**
* The request that generated this response
*/
@property(nonatomic, readonly) OTRestRequest* request;
/**
* The URL the response was loaded from
*/
@property(nonatomic, readonly) NSURL* URL;
/**
* The MIME Type of the response payload
*/
@property(nonatomic, readonly) NSString* MIMEType;
/**
* The status code of the HTTP response
*/
@property(nonatomic, readonly) NSInteger statusCode;
/**
* Return a dictionary of headers sent with the HTTP response
*/
@property(nonatomic, readonly) NSDictionary* allHeaderFields;
/**
* The data returned as the response payload
*/
@property(nonatomic, readonly) NSData* payload;
/**
* The error returned if the URL connection fails
*/
@property(nonatomic, readonly) NSError* failureError;
/**
* Initialize a new response object for a REST request
*/
- (id)initWithRestRequest:(OTRestRequest*)request;
/**
* Return the localized human readable representation of the HTTP Status Code returned
*/
- (NSString*)localizedStatusCodeString;
/**
* Return the response payload as an NSString
*/
- (NSString*)payloadString;
/**
* Parse the response payload into an XML Document via ElementParser
*/
- (DocumentRoot*)payloadXMLDocument;
/**
* Parse the response into a dictionary from JSON
*/
- (NSDictionary*)payloadJSONDictionary;
/**
* Will determine if there is an error object and use it's localized message
*/
- (NSString*)failureErrorDescription;
/**
* Indicates that the connection failed to reach the remote server. The details of the failure
* are available on the failureError reader.
*/
- (BOOL)isFailure;
/**
* Indicates an invalid HTTP response code less than 100 or greater than 600
*/
- (BOOL)isInvalid;
/**
* Indicates an HTTP response code between 100 and 199
*/
- (BOOL)isInformational;
/**
* Indicates an HTTP response code between 200 and 299
*/
- (BOOL)isSuccessful;
/**
* Indicates an HTTP response code between 300 and 399
*/
- (BOOL)isRedirection;
/**
* Indicates an HTTP response code between 400 and 499
*/
- (BOOL)isClientError;
/**
* Indicates an HTTP response code between 500 and 599
*/
- (BOOL)isServerError;
/**
* Indicates that the response is either a server or a client error
*/
- (BOOL)isError;
/**
* Indicates an HTTP response code of 200
*/
- (BOOL)isOK;
/**
* Indicates an HTTP response code of 201
*/
- (BOOL)isCreated;
/**
* Indicates an HTTP response code of 403
*/
- (BOOL)isForbidden;
/**
* Indicates an HTTP response code of 404
*/
- (BOOL)isNotFound;
/**
* Indicates an HTTP response code of 301, 302, 303 or 307
*/
- (BOOL)isRedirect;
/**
* Indicates an empty HTTP response code of 201, 204, or 304
*/
- (BOOL)isEmpty;
/**
* Returns the value of 'Content-Type' HTTP header
*/
- (NSString*)contentType;
/**
* Returns the value of the 'Content-Length' HTTP header
*/
- (NSString*)contentLength;
/**
* Returns the value of the 'Location' HTTP Header
*/
- (NSString*)location;
/**
* True when the server turned an XML response (MIME type is application/xml)
*/
- (BOOL)isXML;
/**
* True when the server turned an XML response (MIME type is application/json)
*/
- (BOOL)isJSON;
@end