Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Song.m
- // NeedleMusic
- //
- // Created by Davide Cenzi on 17/05/12.
- // Copyright (c) 2012 No1. All rights reserved.
- //
- #import "Song.h"
- @implementation Song
- @synthesize code = _code;
- @synthesize source = _source;
- @synthesize album_id = _album_id;
- @synthesize track_name = _track_name;
- @synthesize track_time_millis = _track_time_millis;
- @synthesize track_time = _track_time;
- @synthesize disc_number = _disc_number;
- @synthesize track_number = _track_number;
- @synthesize audios = _audios;
- @synthesize preview_url = _preview_url;
- + (RKObjectMapping*)mapping{
- RKObjectMapping* songMapping = [RKObjectMapping mappingForClass:[Song class]];
- songMapping.rootKeyPath = @"song";
- [songMapping mapKeyPath:@"id" toAttribute:@"code"];
- [songMapping mapKeyPath:@"source" toAttribute:@"source"];
- [songMapping mapKeyPath:@"album_id" toAttribute:@"album_id"];
- [songMapping mapKeyPath:@"track_name" toAttribute:@"track_name"];
- [songMapping mapKeyPath:@"track_time_millis" toAttribute:@"track_time_millis"];
- //calculated attribute
- [songMapping mapKeyPath:@"track_time" toAttribute:@"track_time"];
- [songMapping mapKeyPath:@"disc_number" toAttribute:@"disc_number"];
- [songMapping mapKeyPath:@"track_number" toAttribute:@"track_number"];
- #warning removed relationship 'audios' from song
- //[songMapping hasMany:@"audios" withMapping:[Audio mapping]];
- return songMapping;
- }
- + (RKObjectMapping*)serializationMapping{
- RKObjectMapping *songSerialization = [RKObjectMapping mappingForClass:[Song class]];
- //[songSerialization mapKeyPath:@"code" toAttribute:@"song[id]"];
- [songSerialization mapKeyPath:@"source" toAttribute:@"source"];
- [songSerialization mapKeyPath:@"album_id" toAttribute:@"album_id"];
- [songSerialization mapKeyPath:@"track_name" toAttribute:@"track_name"];
- //[songSerialization mapKeyPath:@"track_time_millis" toAttribute:@"track_time_millis"];
- //skip track_time, it's a calculated attribute
- [songSerialization mapKeyPath:@"disc_number" toAttribute:@"disc_number"];
- [songSerialization mapKeyPath:@"track_number" toAttribute:@"track_number"];
- //custom attribute used to track audio player
- //[songSerialization mapKeyPath:@"preview_url" toAttribute:@"preview_url"];
- return songSerialization;
- }
- + (void)setupMapping{
- //managerWithBaseURLString:[[BTAuth sharedObject] apiURL]
- RKObjectManager* objectManager = [RKObjectManager sharedManager];
- // Setup our object mappings
- RKObjectMapping* songMapping = [Song mapping];
- [objectManager.mappingProvider setObjectMapping:songMapping forKeyPath:@"song"];
- // Serialization mapping for user class
- RKObjectMapping* songSerialization = [Song serializationMapping];
- [objectManager.mappingProvider setSerializationMapping:songSerialization forClass:[Song class]];
- //Routes for user class
- #warning removed routes for songs, sent only within an album object
- //[objectManager.router routeClass:[Song class] toResourcePath:@"albums/:album_id/songs/:code"];
- //[objectManager.router routeClass:[Song class] toResourcePath:@"albums/:album_id/songs" forMethod:RKRequestMethodPOST];
- }
- @end
Add Comment
Please, Sign In to add comment