This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# channels controller | |
def index | |
@channels = Channel.all | |
respond_to do |format| | |
format.html # index.html.erb | |
format.json { render :json => { :channels => @channels } } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"channels":{"78":{"id":78,"name":"Zombie Bass","num_of_listeners":1,"created_at":"2012-03-21T04:04:36Z","updated_at":"2012-04-20T01:21:12Z"},"82":{"id":82,"name":"The Beatles123","num_of_listeners":1,"created_at":"2012-03-22T20:28:34Z","updated_at":"2012-04-17T04:34:07Z"},"125":{"id":125,"name":"New!","num_of_listeners":1,"created_at":"2012-04-19T04:05:47Z","updated_at":"2012-04-19T04:05:47Z"},"132":{"id":132,"name":"Test!","num_of_listeners":1,"created_at":"2012-04-26T21:00:30Z","updated_at":"2012-04-26T21:00:30Z"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)setupObjectMapping { | |
RKObjectMapping* channelMapping = [RKObjectMapping mappingForClass:[Channel class]]; | |
[channelMapping mapKeyPath:@"id" toAttribute:@"identifier"]; | |
[channelMapping mapKeyPath:@"name" toAttribute:@"name"]; | |
//[channelMapping mapKeyPath:@"created_at" toAttribute:@"createdAt"]; | |
//[channelMapping mapKeyPath:@"updated_at" toAttribute:@"updatedAt"]; | |
[channelMapping mapKeyPath:@"num_of_listeners" toAttribute:@"numOfListeners"]; | |
//object mapping for GETs | |
[[RKObjectManager sharedManager].mappingProvider setMapping:channelMapping forKeyPath:@"channels"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"channels": { | |
"78": { | |
"id": 78, | |
"name": "Zombie Bass", | |
"num_of_listeners": 1, | |
"created_at": "2012-03-21T04:04:36Z", | |
"updated_at": "2012-04-20T01:21:12Z" | |
}, | |
"82": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Channel.h | |
@interface Channel : NSObject <RKRequestDelegate, RKObjectLoaderDelegate> { | |
NSNumber *identifier; | |
NSString *name; | |
NSNumber *numOfListeners; | |
} | |
//AppDelegate.m | |
- (void)setupObjectMapping { | |
RKObjectMapping* channelMapping = [RKObjectMapping mappingForClass:[Channel class]]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"channels": [ | |
{ | |
"number": 78, | |
"name": "Zombie Bass", | |
"num_of_listeners": 1, | |
"created_at": "2012-03-21T04:04:36Z", | |
"updated_at": "2012-04-20T01:21:12Z" | |
}, | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"channels": { | |
"78": { | |
"name": "Zombie Bass", | |
"num_of_listeners": 1, | |
"created_at": "2012-03-21T04:04:36Z", | |
"updated_at": "2012-04-20T01:21:12Z" | |
}, | |
"82": { | |
"name": "The Beatles123", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"channels": [ | |
{ | |
"number": 78, | |
"name": "Zombie Bass", | |
"num_of_listeners": 1, | |
"created_at": "2012-03-21T04:04:36Z", | |
"updated_at": "2012-04-20T01:21:12Z" | |
}, | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RKObjectMapping* channelMapping = [RKObjectMapping mappingForClass:[Channel class]]; | |
[channelMapping mapKeyPath:@"id" toAttribute:@"identifier"]; | |
[channelMapping mapKeyPath:@"name" toAttribute:@"name"]; | |
[channelMapping mapKeyPath:@"num_of_listeners" toAttribute:@"numOfListeners"]; | |
//object mapping for GETs | |
[[RKObjectManager sharedManager].mappingProvider setMapping:channelMapping forKeyPath:@"channels"]; | |
//set up object serialization for POSTing back to rails | |
RKObjectMapping* channelSerializationMapping = [channelMapping inverseMapping]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"channels": { | |
"channel_78": { | |
"name": "Zombie Bass", | |
"num_of_listeners": 1, | |
"created_at": "2012-03-21T04:04:36Z", | |
"updated_at": "2012-04-20T01:21:12Z" | |
}, | |
"channel_82": { | |
"name": "The Beatles123", |