ASObject Class Reference
Inherits from | NSObject |
Declared in | ASObject.h |
Overview
Base class all Audiosocket data models subclass. Since most models have both a ‘name’ and an ID attribute they are defined here.
This class interfaces with the underlying RestKit library which handles the object mapping and underlying transport. This class is the only class which exposes any RestKit classes. By doing so it more advanced scenarios can be implemented.
Tasks
Accessing ASObject data model Properties
-
ID
Primary ID of this ASObject instance.
property -
name
Name of this ASObject instance, e.g. “Don’t Stop Believing”
property
Mapping response data to object proproperties
-
+ objectManager
Return the RestKit object manager singleton.
-
+ initializeMappings:
Initializes the RestKit mapping for this class. Defaults to calling only [ASObject addInstanceResponseDescriptor]. It is overridden by classes that contain associated entities.
-
+ addInstanceResponseDescriptor
Adds an RKResponseDescriptor descriptor as an instance descriptor. You should not have to make changes to this class, but it is exposed should you decide to override. See (RestKit object mapping)[https://github.com/RestKit/RestKit/wiki/Object-mapping] for details should you need them.
-
+ collectionResponseDescriptor
Adds an RKResponseDescriptor descriptor as an collection descriptor. You should not have to make changes to this class, but it is exposed should you decide to override. See (RestKit object mapping)[https://github.com/RestKit/RestKit/wiki/Object-mapping] for details should you need them.
-
+ instanceObjectMapping
Returns an RKObjectMapping instance to map the properties of this object. Defaults to ID and name mapping. Override to map attributes.
Defining destination endpoints.
-
+ endpointRoot
For and endpoint like “https://api.audiosocket.com/v5/moods/345” this method should return “moods”.
-
+ instanceGetEndpoint
Return the endpoint path, not including the baseURL portion, used to fetch an instance of this class. It defaults ‘<endpoint-root>/:id’. When actually fetching instances ‘:id’ is replaced with the actual id of the object.
Creating a new instance
-
– initWithID:
Initialize an instance of this class with the ID provided.
-
– loadWithSuccess:failure:
Loads an instance from the server. If you only have an ID for a instance you can do something like the following:
-
– loadFromPath:parameters:success:failure:
Loads an instance from the server using the endpoint supplied. This is useful for classes that don’t have an ID, e.g. ASContext
-
– resolve:
Return ‘self’ if targetID is equal self.ID. Overriden in subclasses that contain children.
Class Methods
addInstanceResponseDescriptor
Adds an RKResponseDescriptor descriptor as an instance descriptor. You should not have to make changes to this class, but it is exposed should you decide to override. See (RestKit object mapping)[https://github.com/RestKit/RestKit/wiki/Object-mapping] for details should you need them.
+ (RKResponseDescriptor *)addInstanceResponseDescriptor
Declared In
ASObject.h
collectionResponseDescriptor
Adds an RKResponseDescriptor descriptor as an collection descriptor. You should not have to make changes to this class, but it is exposed should you decide to override. See (RestKit object mapping)[https://github.com/RestKit/RestKit/wiki/Object-mapping] for details should you need them.
+ (RKResponseDescriptor *)collectionResponseDescriptor
Declared In
ASObject.h
endpointRoot
For and endpoint like “https://api.audiosocket.com/v5/moods/345” this method should return “moods”.
+ (NSString *)endpointRoot
Discussion
Note: must be overridden by subclass.
Declared In
ASObject.h
initializeMappings:
Initializes the RestKit mapping for this class. Defaults to calling only [ASObject addInstanceResponseDescriptor]. It is overridden by classes that contain associated entities.
+ (void)initializeMappings:(RKObjectManager *)objectManager
Parameters
- objectManager
RestKit RKObjectManager to add the mapping to.
Declared In
ASObject.h
instanceGetEndpoint
Return the endpoint path, not including the baseURL portion, used to fetch an instance of this class. It defaults ‘<endpoint-root>/:id’. When actually fetching instances ‘:id’ is replaced with the actual id of the object.
+ (NSString *)instanceGetEndpoint
Declared In
ASObject.h
Instance Methods
initWithID:
Initialize an instance of this class with the ID provided.
- (ASObject *)initWithID:(NSInteger)ID
Parameters
- ID
Primary ID of this instance.
Declared In
ASObject.h
loadFromPath:parameters:success:failure:
Loads an instance from the server using the endpoint supplied. This is useful for classes that don’t have an ID, e.g. ASContext
- (void)loadFromPath:(NSString *)path parameters:(NSDictionary *)params success:(void ( ^ ) ( id ))success failure:(void ( ^ ) ( NSError *))failure
Parameters
- path
Path specifying endpoint that will an instance of this class. It does not include the baseURL portion of the path.
- params
Optional query parameters that added to the request path.
- success
Called when the request returns successfully. The retrieved instance is passed to this block.
- failure
If supplied called when an error occurs during the request.
Declared In
ASObject.h
loadWithSuccess:failure:
Loads an instance from the server. If you only have an ID for a instance you can do something like the following:
- (void)loadWithSuccess:(void ( ^ ) ( id asObject ))success failure:(void ( ^ ) ( NSError *error ))failure
Parameters
- success
Invoked when the request has completed successfully. ‘self’ is
passed to the block.
- failure
Invoked, if supplied, when an error occurs during the request or
subsequent data mapping.
Discussion
ASTrack *track = [[ASTrack alloc] initWithID:20];
[track loadWithSuccess:^(ASTrack *loadTrack) {
// Do something with the newly loaded track...
}
failure:^(NSError *error) {
// Handle error condition...
}
];
Declared In
ASObject.h