Missing support for Story Locations
mycroftcanner opened this issue · comments
It would be nice to have support for reel.items.story_locations
I'll try to write a PR but I am not very familiar with your code yet.
/// A `StoryLocation` response.
public struct StoryLocation: IdentifiableParsedResponse {
/// Init with `rawResponse`.
public init(rawResponse: DynamicResponse) { self.rawResponse = rawResponse }
/// The `rawResponse`.
public let rawResponse: DynamicResponse
public var x: Double? { rawResponse.x.double }
public var y: Double? { rawResponse.y.double }
public var z: Double? { rawResponse.z.double }
public var height: Double? { rawResponse.height.double }
public var width: Double? { rawResponse.width.double }
public var rotation: Double? { rawResponse.rotation.double }
/// The `isHidden` value.
public var isHidden: Bool {
return rawResponse.isHidden.bool ?? false
}
/// The `isSticker` value.
public var isSticker: Bool {
return rawResponse.isSticker.bool ?? false
}
/// The `isPinned` value.
public var isPinned: Bool {
return rawResponse.isPinned.bool ?? false
}
/// The `location` value.
public var location: Location? {
return Location(rawResponse: rawResponse.location)
}
// MARK: Codable
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
self.rawResponse = try DynamicResponse(data: container.decode(Data.self))
}
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(rawResponse.data())
}
}
/// A `Location` response.
public struct Location: IdentifiableParsedResponse {
/// Init with `rawResponse`.
public init(rawResponse: DynamicResponse) { self.rawResponse = rawResponse }
/// The `rawResponse`.
public let rawResponse: DynamicResponse
/// The `city` value.
public var city: String? {
return rawResponse.city.string
}
/// The `address` value.
public var address: String? {
return rawResponse.address.string
}
/// The `lng` value.
public var lng: Double? {
return rawResponse.lng.double
}
/// The `lat` value.
public var lat: Double? {
return rawResponse.lat.double
}
public var pk: Int? {
return rawResponse.pk.int
}
/// The `shortName` value.
public var shortName: String? {
return rawResponse.shortName.string
}
/// The `name` value.
public var name: String? {
return rawResponse.name.string
}
/// The `externalSource` value.
public var externalSource: String? {
return rawResponse.externalSource.string
}
/// The `facebookPlacesId` value.
public var facebookPlacesId: Int? {
return rawResponse.facebookPlacesId.int
}
// MARK: Codable
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
self.rawResponse = try DynamicResponse(data: container.decode(Data.self))
}
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(rawResponse.data())
}
}
I am stuck...
I tried adding this to Media:
/// The `storyLocations' value.
public var storyLocations: [StoryLocation] {
return rawResponse.storyLocations.array?.compactMap { StoryLocation(rawResponse: $0) } ?? []
}
and it crashes when I try to access media.storyLocations... even though the following works perfectly:
if let sls = media.rawResponse.storyLocations.array {
let storyLocations: [StoryLocation] = sls.compactMap { StoryLocation(rawResponse: $0) }
for sl in storyLocations {
dump(sl, name: "storyLocations")
}
}
Also the x, y, z, rotation, height, width should probably all be CGFloat
Absolutely @mycroftcanner
And you're definitely in the right direction with your code 💪
I hope I manage to push a PR in the next few hours.
@sbertix amazing!!
OK, so… I've pushed a PR. It encompasses all you've mentioned in your code, except for directly including accessories for the "sticker" properties (x
, y
, z
, isSticker
, isPinned
, etc.): they're still there inside rawResponse
, just not exposed in code (SwiftyInsta
is, as of writing this, very automation oriented and adding strictly UI accessories felt like a stretch — again, they're there though if you need them).
😊