forked from RestKit/RestKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRKObjectManager.h
More file actions
202 lines (166 loc) · 8.14 KB
/
Copy pathRKObjectManager.h
File metadata and controls
202 lines (166 loc) · 8.14 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//
// RKObjectManager.h
// RestKit
//
// Created by Jeremy Ellison on 8/14/09.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import "../Network/Network.h"
#import "RKObjectMapper.h"
#import "RKObjectLoader.h"
#import "RKDynamicRouter.h"
// Notifications
extern NSString* const RKDidEnterOfflineModeNotification;
extern NSString* const RKDidEnterOnlineModeNotification;
typedef enum {
RKObjectManagerOnlineStateUndetermined,
RKObjectManagerOnlineStateDisconnected,
RKObjectManagerOnlineStateConnected
} RKObjectManagerOnlineState;
@class RKManagedObjectStore;
@interface RKObjectManager : NSObject {
RKClient* _client;
RKMappingFormat _format;
RKObjectMapper* _mapper;
NSObject<RKRouter>* _router;
RKManagedObjectStore* _objectStore;
RKObjectManagerOnlineState _onlineState;
}
/**
* Return the shared instance of the object manager
*/
+ (RKObjectManager*)sharedManager;
/**
* Set the shared instance of the object manager
*/
+ (void)setSharedManager:(RKObjectManager*)manager;
/**
* Create and initialize a new object manager. If this is the first instance created
* it will be set as the shared instance
*/
+ (RKObjectManager*)objectManagerWithBaseURL:(NSString*)baseURL;
/**
* Create and initialize a new object manager. If this is the first instance created
* it will be set as the shared instance
*/
+ (RKObjectManager*)objectManagerWithBaseURL:(NSString*)baseURL objectMapper:(RKObjectMapper*)mapper router:(NSObject<RKRouter>*)router;
/**
* Initialize a new model manager instance
*/
- (id)initWithBaseURL:(NSString*)baseURL;
/**
* Initialize a new model manager instance
*/
- (id)initWithBaseURL:(NSString*)baseURL objectMapper:(RKObjectMapper*)mapper router:(NSObject<RKRouter>*)router;
/**
* The wire format to use for communications. Either RKMappingFormatXML or RKMappingFormatJSON.
*
* Defaults to RKMappingFormatJSON
*/
// TODO: Replace this with setParser:forMIMEType: method.
@property(nonatomic, assign) RKMappingFormat format;
/**
* The REST client for this manager
*/
@property (nonatomic, retain) RKClient* client;
/**
* True when we are in online mode
*/
- (BOOL)isOnline;
/**
* Register a resource mapping from a domain model class to a JSON/XML element name
*/
- (void)registerClass:(Class<RKObjectMappable>)class forElementNamed:(NSString*)elementName;
/**
* Mapper object responsible for mapping remote HTTP resources to Cocoa objects
*/
@property(nonatomic, readonly) RKObjectMapper* mapper;
/**
* Routing object responsible for generating paths for objects and serializing
* representations of the object for transport.
*
* Defaults to an instance of RKDynamicRouter
*/
@property(nonatomic, retain) NSObject<RKRouter>* router;
/**
* A Core Data backed object store for persisting objects that have been fetched from the Web
*/
@property(nonatomic, retain) RKManagedObjectStore* objectStore;
////////////////////////////////////////////////////////
// Registered Object Loaders
/**
* These methods are suitable for loading remote payloads that encode type information into the payload. This enables
* the mapping of complex payloads spanning multiple types (i.e. a search operation returning Articles & Comments in
* one payload). Ruby on Rails JSON serialization is an example of such a conformant system.
*/
/**
* Create and send an asynchronous GET request to load the objects at the resource path and call back the delegate
* with the loaded objects. Remote objects will be mapped to local objects by consulting the element registrations
* set on the mapper.
*/
- (RKObjectLoader*)loadObjectsAtResourcePath:(NSString*)resourcePath delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
/**
* Create and send an asynchronous GET request to load the objects at the specified resource path with a dictionary
* of query parameters to append to the URL and call back the delegate with the loaded objects. Remote objects will be mapped to
* local objects by consulting the element registrations set on the mapper.
*/
- (RKObjectLoader*)loadObjectsAtResourcePath:(NSString *)resourcePath queryParams:(NSDictionary*)queryParams delegate:(NSObject <RKObjectLoaderDelegate>*)delegate;
////////////////////////////////////////////////////////
// Explicit Object Loaders
/**
* These methods are suitable for loading remote payloads where no type information is encoded into the payload. When
* the request is completed, the resulting payload will be mapped into instances of the specified mappable object class.
*/
/**
* Create and send an asynchronous GET request to load the objects at the resource path and call back the delegate
* with the loaded objects. Remote objects will be mapped into instances of the specified object mappable class.
*/
- (RKObjectLoader*)loadObjectsAtResourcePath:(NSString*)resourcePath objectClass:(Class<RKObjectMappable>)objectClass delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
/**
* Create and send an asynchronous GET request to load the objects at the specified resource path with a dictionary
* of query parameters to append to the URL and call back the delegate with the loaded objects. Remote objects will be mapped into
* instances of the specified object mappable class.
*/
- (RKObjectLoader*)loadObjectsAtResourcePath:(NSString *)resourcePath queryParams:(NSDictionary*)queryParams objectClass:(Class<RKObjectMappable>)objectClass delegate:(NSObject <RKObjectLoaderDelegate>*)delegate;
////////////////////////////////////////////////////////
// Mappable object helpers
/**
* Update a mappable model by loading its attributes from the web
*/
- (RKObjectLoader*)getObject:(NSObject<RKObjectMappable>*)object delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
/**
* Create a remote mappable model by POSTing the attributes to the remote resource and loading the resulting objects from the payload
*/
- (RKObjectLoader*)postObject:(NSObject<RKObjectMappable>*)object delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
/**
* Update a remote mappable model by PUTing the attributes to the remote resource and loading the resulting objects from the payload
*/
- (RKObjectLoader*)putObject:(NSObject<RKObjectMappable>*)object delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
/**
* Delete the remote instance of a mappable model by performing an HTTP DELETE on the remote resource
*/
- (RKObjectLoader*)deleteObject:(NSObject<RKObjectMappable>*)object delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
////////////////////////////////////////////////////////
// Object Loader Primitives
/**
* These methods are provided for situations where the remote system you are working with has slightly different conventions
* than the default methods provide. They return fully initialized object loaders that are ready for dispatch, but
* have not yet been sent. This can be used to add one-off params to the request body or otherwise manipulate the request
* before it is sent off to be loaded & object mapped. This can also be used to perform a synchronous object load.
*/
/**
* Return an object loader ready to be sent. The method defaults to GET and the URL is relative to the
* baseURL configured on the client. The loader is configured for an implicit objectClass load. This is
* the best place to begin work if you need to create a slightly different collection loader than what is
* provided by the loadObjects family of methods.
*/
- (RKObjectLoader*)objectLoaderWithResourcePath:(NSString*)resourcePath delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
/**
* Returns an object loader configured for transmitting an object instance across the wire. A request will be constructed
* for you with the resource path & object serialization configured for you by the Router. This is the best place to
* begin work if you need a slightly different interaction with the server than what is provided for you by get/post/put/delete
* object family of methods. Note that this should be used for one-off changes. If you need to substantially modify all your
* object loads, you are better off subclassing or implementing your own RKRouter for dryness.
*/
- (RKObjectLoader*)objectLoaderForObject:(NSObject<RKObjectMappable>*)object method:(RKRequestMethod)method delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
@end