Skip to content

Commit

Permalink
Change attachment payload parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Koray Koska committed Jul 16, 2017
1 parent deb2a45 commit 40484d4
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ public final class FacebookAttachmentPayload: JSONConvertible {
self.url = url
}

public init(coordinatesLat: Double, coordinatesLong: Double) {
public init(coordinatesLat: Double, coordinatesLong: Double, url: String? = nil) {
self.coordinatesLat = coordinatesLat
self.coordinatesLong = coordinatesLong
self.url = url
}

public convenience init(json: JSON) throws {
let url = json["url"]?.string
let coordinatesLat = json["coordinates"]?["lat"]?.double
let coordinatesLong = json["coordinates"]?["long"]?.double

if let url = url, coordinatesLat == nil, coordinatesLong == nil {
if let coordinatesLat = coordinatesLat, let coordinatesLong = coordinatesLong {
self.init(coordinatesLat: coordinatesLat, coordinatesLong: coordinatesLong, url: url)
} else if let url = url {
self.init(url: url)
} else if let coordinatesLat = coordinatesLat, let coordinatesLong = coordinatesLong {
self.init(coordinatesLat: coordinatesLat, coordinatesLong: coordinatesLong)
} else {
throw Abort(.badRequest, metadata: "FacebookAttachmentPayload must contain either a url or coordinates.lat and coordinates.long")
}
Expand Down

0 comments on commit 40484d4

Please sign in to comment.