@@ -25,9 +25,6 @@ public final class Device: Model,ResponseObject,ResponseCollection {
2525 self . location = Location ( response: response, representation: representation. valueForKeyPath ( " location " ) !) !
2626 }
2727 }
28- if let dic = representation. valueForKeyPath ( " experience " ) as? NSDictionary {
29- self . experience = Experience ( response: response, representation: representation. valueForKeyPath ( " experience " ) !) !
30- }
3128 super. init ( response: response, representation: representation)
3229 }
3330
@@ -43,8 +40,24 @@ public final class Device: Model,ResponseObject,ResponseCollection {
4340 return devices
4441 }
4542
46- public func getLocation( ) -> Location ? {
47- return self . location
43+ public func getLocation( ) -> Promise < Location ? > {
44+ if let uuidLocation = self . document [ " location.uuid " ] {
45+ return Promise { fulfill, reject in
46+ Alamofire . request ( Router . getLocation ( uuidLocation as! String ) )
47+ . responseObject { ( response: Response < Location , NSError > ) in
48+ switch response. result{
49+ case . Success( let data) :
50+ fulfill ( data)
51+ case . Failure( let error) :
52+ return reject ( error)
53+ }
54+ }
55+ }
56+ }
57+ return Promise< Location?> { fulfill, reject in
58+ fulfill ( nil )
59+ }
60+
4861 }
4962
5063 public func getZones( ) -> [ Zone ] {
@@ -55,8 +68,24 @@ public final class Device: Model,ResponseObject,ResponseCollection {
5568 return zones
5669 }
5770
58- public func getExperience( ) -> Experience ? {
59- return self . experience
71+
72+ public func getExperience( ) -> Promise < Experience ? > {
73+ if let uuidExperience = self . document [ " experience.uuid " ] {
74+ return Promise { fulfill, reject in
75+ Alamofire . request ( Router . getExperience ( uuidExperience as! String ) )
76+ . responseObject { ( response: Response < Experience , NSError > ) in
77+ switch response. result{
78+ case . Success( let data) :
79+ fulfill ( data)
80+ case . Failure( let error) :
81+ return reject ( error)
82+ }
83+ }
84+ }
85+ }
86+ return Promise< Experience?> { fulfill, reject in
87+ fulfill ( nil )
88+ }
6089 }
6190
6291 /**
0 commit comments