Skip to content

Commit 862d2e8

Browse files
Merge pull request #33 from ScalaInc/fix/device-model
EXP-3025 EXP-3028 update device model for getLocation and getExperience
2 parents 55e0d47 + 5e00962 commit 862d2e8

File tree

3 files changed

+38
-23
lines changed

3 files changed

+38
-23
lines changed

Pod/Classes/Device.swift

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/**

Pod/Classes/Experience.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,7 @@ public final class Experience: Model,ResponseObject,ResponseCollection {
5959
*/
6060
public func getCurrentExperience() -> Promise<Experience?>{
6161
return Device.getCurrentDevice().then{ (device:Device?) -> Promise<Experience?> in
62-
return Promise<Experience?> { fulfill, reject in
63-
if let experience:Experience = device?.getExperience(){
64-
fulfill(experience)
65-
}else{
66-
fulfill(nil)
67-
expLogging("Experience - getCurrentExperience NULL")
68-
}
69-
}
62+
return (device?.getExperience())!
7063
}
7164
}
7265

Pod/Classes/Location.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,7 @@ public final class Location: Model,ResponseObject,ResponseCollection {
8989
*/
9090
public func getCurrentLocation() -> Promise<Location?>{
9191
return Device.getCurrentDevice().then{ (device:Device?) -> Promise<Location?> in
92-
return Promise<Location?> { fulfill, reject in
93-
if let location:Location = device?.getLocation(){
94-
fulfill(location)
95-
}else{
96-
fulfill(nil)
97-
expLogging("Location - getCurrentLocation NULL")
98-
}
99-
}
92+
return (device?.getLocation())!
10093
}
10194
}
10295

0 commit comments

Comments
 (0)