Created
January 15, 2013 21:52
-
-
Save leftspin/4542452 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
SAMPLE JSON | |
{ | |
"event":{ | |
"name":"Gregorian", | |
"description":null, | |
"pricing":"£ 129.90 - 129.90", | |
"free":null, | |
"starts_at":"2013-04-06T20:00:00+00:00", | |
"ends_at":null, | |
"all_day":false, | |
"coordinates":"48.2021994,16.3314435", | |
"venue_id":"50ee0500844b7614c90003d8", | |
"venue_name":"Wiener Stadthalle", | |
… | |
MAPPING CODE | |
RKEntityMapping *eventMapping = [RKEntityMapping mappingForEntityForName:@"Event" inManagedObjectStore:objectManager.managedObjectStore] ; | |
eventMapping.identificationAttributes = @[@"event_id"] ; | |
[eventMapping addAttributeMappingsFromArray:@[@"name" , @"pricing" , @"free" , @"starts_at" , @"ends_at" , @"all_day" , @"coordinates" , @"venue_id" , @"venue_name" , @"time_zone" , @"organizations" , @"photos" , @"links"]] ; | |
[eventMapping addAttributeMappingsFromDictionary:@{@"id":@"event_id" , @"description":@"desc"}] ; | |
RKResponseDescriptor *eventResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:eventMapping pathPattern:[NSString stringWithFormat:@"%@/:event_id", EVENT_RESOURCE_PATH] keyPath:@"event" statusCodes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)]] ; | |
[objectManager addResponseDescriptor:eventResponseDescriptor] ; | |
FETCHING CODE | |
[_operationQueue cancelAllOperations] ; | |
NSString *query = [NSString stringWithFormat:@"%@/%@" , EVENT_RESOURCE_PATH, self.eventID] ; | |
RKObjectRequestOperation *fetchEventOperation = [[RKObjectManager sharedManager] appropriateObjectRequestOperationWithObject:nil method:RKRequestMethodGET path:query parameters:nil] ; | |
[fetchEventOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) | |
{ | |
NSLog(@"mapped objects: %@\nresponse: %@" , mappingResult.array, operation.HTTPRequestOperation.responseString) ; | |
[self fetchPostCardImageAtURLString:[self photoURLString]] ; | |
} | |
failure:^(RKObjectRequestOperation *operation, NSError *error) | |
{ | |
PROMPT_REPORT(@"Could not fetch information about that event", error.description) ; | |
NSLog(@"Error fetching event: %@, response: %@" , error, operation.HTTPRequestOperation.responseString) ; | |
}] ; | |
[_operationQueue addOperation:fetchEventOperation] ; | |
OUTPUT | |
2013-01-15 12:59:23.948 tabeso[22420:c07] mapped objects: ( | |
) | |
response: {"event":{"name":"Gregorian","description":null,"pricing":"£ 129.90 - 129.90","free":null,"starts_at":"2013-04-06T20:00:00+00:00","ends_at":null,"all_day":false,"coordinates":"48.2021994,16.3314435","venue_id":"50ee0500844b7614c90003d8","venue_name":"Wiener Stadthalle","time_zone":{"name":"UTC","utc_offset":null,"tzinfo":{"identifier":"Etc/UTC","real_timezone":{"info":{"identifier":"Etc/UTC","offsets":{"o0":{"utc_offset":0,"std_offset":0,"abbreviation":"UTC","utc_total_offset":0}},"transitions":[],"previous_offset":{"utc_offset":0,"std_offset":0,"abbreviation":"UTC","utc_total_offset":0},"transitions_index":null}}},"current_period":null},"id":"50eeae4a1ea793b70b001bcb","organizations":[{"name":"Gregorian","id":"50ee04a3a55641685e000001"}],"photos":["http://s3.evcdn.com/images/original/I0-001/001/749/458-9.jpeg_/gregorian-58.jpeg"],"links":{"self":"http://api.tabeso.com/events/50eeae4a1ea793b70b001bcb","venue":"http://api.tabeso.com/venues/50ee0500844b7614c90003d8","organizations":["http://api.tabeso.com/organizations/50ee04a3a55641685e000001"]}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment