Guest User

Untitled

a guest
Nov 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. //
  2. // Song.m
  3. // NeedleMusic
  4. //
  5. // Created by Davide Cenzi on 17/05/12.
  6. // Copyright (c) 2012 No1. All rights reserved.
  7. //
  8.  
  9. #import "Song.h"
  10.  
  11.  
  12. @implementation Song
  13. @synthesize code = _code;
  14. @synthesize source = _source;
  15. @synthesize album_id = _album_id;
  16. @synthesize track_name = _track_name;
  17. @synthesize track_time_millis = _track_time_millis;
  18. @synthesize track_time = _track_time;
  19. @synthesize disc_number = _disc_number;
  20. @synthesize track_number = _track_number;
  21. @synthesize audios = _audios;
  22.  
  23. @synthesize preview_url = _preview_url;
  24.  
  25. + (RKObjectMapping*)mapping{
  26.  
  27. RKObjectMapping* songMapping = [RKObjectMapping mappingForClass:[Song class]];
  28. songMapping.rootKeyPath = @"song";
  29. [songMapping mapKeyPath:@"id" toAttribute:@"code"];
  30. [songMapping mapKeyPath:@"source" toAttribute:@"source"];
  31. [songMapping mapKeyPath:@"album_id" toAttribute:@"album_id"];
  32. [songMapping mapKeyPath:@"track_name" toAttribute:@"track_name"];
  33. [songMapping mapKeyPath:@"track_time_millis" toAttribute:@"track_time_millis"];
  34. //calculated attribute
  35. [songMapping mapKeyPath:@"track_time" toAttribute:@"track_time"];
  36.  
  37. [songMapping mapKeyPath:@"disc_number" toAttribute:@"disc_number"];
  38. [songMapping mapKeyPath:@"track_number" toAttribute:@"track_number"];
  39.  
  40. #warning removed relationship 'audios' from song
  41. //[songMapping hasMany:@"audios" withMapping:[Audio mapping]];
  42.  
  43. return songMapping;
  44. }
  45.  
  46. + (RKObjectMapping*)serializationMapping{
  47.  
  48. RKObjectMapping *songSerialization = [RKObjectMapping mappingForClass:[Song class]];
  49. //[songSerialization mapKeyPath:@"code" toAttribute:@"song[id]"];
  50. [songSerialization mapKeyPath:@"source" toAttribute:@"source"];
  51. [songSerialization mapKeyPath:@"album_id" toAttribute:@"album_id"];
  52. [songSerialization mapKeyPath:@"track_name" toAttribute:@"track_name"];
  53. //[songSerialization mapKeyPath:@"track_time_millis" toAttribute:@"track_time_millis"];
  54.  
  55. //skip track_time, it's a calculated attribute
  56. [songSerialization mapKeyPath:@"disc_number" toAttribute:@"disc_number"];
  57. [songSerialization mapKeyPath:@"track_number" toAttribute:@"track_number"];
  58.  
  59. //custom attribute used to track audio player
  60. //[songSerialization mapKeyPath:@"preview_url" toAttribute:@"preview_url"];
  61.  
  62. return songSerialization;
  63. }
  64.  
  65.  
  66. + (void)setupMapping{
  67. //managerWithBaseURLString:[[BTAuth sharedObject] apiURL]
  68. RKObjectManager* objectManager = [RKObjectManager sharedManager];
  69.  
  70. // Setup our object mappings
  71. RKObjectMapping* songMapping = [Song mapping];
  72. [objectManager.mappingProvider setObjectMapping:songMapping forKeyPath:@"song"];
  73.  
  74. // Serialization mapping for user class
  75. RKObjectMapping* songSerialization = [Song serializationMapping];
  76. [objectManager.mappingProvider setSerializationMapping:songSerialization forClass:[Song class]];
  77.  
  78. //Routes for user class
  79. #warning removed routes for songs, sent only within an album object
  80. //[objectManager.router routeClass:[Song class] toResourcePath:@"albums/:album_id/songs/:code"];
  81. //[objectManager.router routeClass:[Song class] toResourcePath:@"albums/:album_id/songs" forMethod:RKRequestMethodPOST];
  82.  
  83. }
  84.  
  85.  
  86.  
  87. @end
Add Comment
Please, Sign In to add comment