ActiveResourceKit  v1.2 (498.0)
 All Classes Files Functions Variables Typedefs Enumerator Properties Macros Pages
ARHTTPResponse.h
Go to the documentation of this file.
1 // ActiveResourceKit ARHTTPResponse.h
2 //
3 // Copyright © 2012, Roy Ratcliffe, Pioneering Software, United Kingdom
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the “Software”), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED “AS IS,” WITHOUT WARRANTY OF ANY KIND, EITHER
16 // EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO
18 // EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
19 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22 //
23 //------------------------------------------------------------------------------
24 
25 #import <Foundation/Foundation.h>
26 
27 /*!
28  * @brief Wraps HTTP response and body.
29  * @details Apple's URL connection programming interface delivers HTTP response
30  * information in two separate pieces: a response object and a block of data for
31  * the response body. This class combines these two pieces together again. You
32  * can pass around a response, ask for its status code, header fields and
33  * body. You can also decode and replace the body if required.
34  *
35  * Can this class safely sub-class @c NSHTTPURLResponse? That may be possible
36  * since the class does not explicitly belong to a class cluster. Nevertheless,
37  * @ref ARHTTPResponse does not sub-class it because the Active Resource
38  * response presents a more Ruby-compatible interface. You can still access the
39  * underlying Cocoa response object by sending @ref URLResponse.
40  */
41 @interface ARHTTPResponse : NSObject
42 
43 /*!
44  * @brief The underlying URL response object.
45  */
46 @property(strong, NS_NONATOMIC_IOSONLY) NSHTTPURLResponse *URLResponse;
47 
48 /*!
49  * @brief The response body in some form.
50  * @details Note that you can rewrite the body, e.g. when handling
51  * decompression. Hence the body has generic object type. It always starts out
52  * as @c NSData but can become other types such as @c NSString after decoding.
53  */
54 @property(strong, NS_NONATOMIC_IOSONLY) id body;
55 
56 /*!
57  * @brief Shortcut for allocating, initialising then setting the URL response
58  * and body.
59  * @details Not the designated initialiser.
60  */
61 - (id)initWithHTTPURLResponse:(NSHTTPURLResponse *)URLResponse body:(id)body;
62 
63 /*!
64  * @brief Creates an Active Resource HTTP response based on a response-data
65  * pair, the kind typically delivered by Apple's URL connection programming
66  * interface.
67  * @result Answers a new HTTP response wrapper or @c nil if the given response
68  * is @em not a HTTP URL response. Answering @c nil is an expected response
69  * from this method if the requests from which the responses derive do not use
70  * the HTTP protocol.
71  */
72 - (id)initWithURLResponse:(NSURLResponse *)URLResponse body:(id)body;
73 
74 - (NSInteger)code;
75 - (NSDictionary *)headerFields;
76 
77 @end