-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for additional Giphy APIs, and a small bit of refactoring…
… for the API layer.
- Loading branch information
1 parent
aa7fbdc
commit ab7201e
Showing
12 changed files
with
847 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// | ||
// GiphySimpleItem.swift | ||
// Pods | ||
// | ||
// Created by Brendan Lee on 3/15/17. | ||
// | ||
// | ||
|
||
import Foundation | ||
import ObjectMapper | ||
|
||
public struct GiphySimpleItem: Mappable { | ||
|
||
public fileprivate(set) var type: String = "gif" | ||
|
||
public fileprivate(set) var identifier: String = "" | ||
|
||
public fileprivate(set) var url: URL? | ||
|
||
// Any of these could be nil | ||
public fileprivate(set) var imageOriginalURL: URL? | ||
public fileprivate(set) var imageURL: URL? | ||
public fileprivate(set) var imagemp4URL: URL? | ||
public fileprivate(set) var imageFrameCount: Int = 0 | ||
public fileprivate(set) var imageWidth: Int = 0 | ||
public fileprivate(set) var imageHeight: Int = 0 | ||
|
||
public fileprivate(set) var fixedHeightDownsampledURL: URL? | ||
public fileprivate(set) var fixedHeightDownsampledWidth: Int = 0 | ||
public fileprivate(set) var fixedHeightDownsampledHeight: Int = 0 | ||
|
||
public fileprivate(set) var fixedWidthDownsampledURL: URL? | ||
public fileprivate(set) var fixedWidthDownsampledWidth: Int = 0 | ||
public fileprivate(set) var fixedWidthDownsampledHeight: Int = 0 | ||
|
||
public fileprivate(set) var fixedHeightSmallURL: URL? | ||
public fileprivate(set) var fixedHeightSmallStillURL: URL? | ||
public fileprivate(set) var fixedHeightSmallWidth: Int = 0 | ||
public fileprivate(set) var fixedHeightSmallHeight: Int = 0 | ||
|
||
public fileprivate(set) var fixedWidthSmallURL: URL? | ||
public fileprivate(set) var fixedWidthSmallStillURL: URL? | ||
public fileprivate(set) var fixedWidthSmallWidth: Int = 0 | ||
public fileprivate(set) var fixedWidthSmallHeight: Int = 0 | ||
|
||
public init?(map: Map) | ||
{ | ||
|
||
} | ||
|
||
public mutating func mapping(map: Map) { | ||
|
||
let dateFormatter = DateFormatter() | ||
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" | ||
dateFormatter.timeZone = TimeZone(abbreviation: "UTC") | ||
|
||
let dateTransformer = DateFormatterTransform(dateFormatter: dateFormatter) | ||
|
||
type <- map["type"] | ||
identifier <- map["id"] | ||
url <- (map["url"], URLTransform()) | ||
|
||
imageOriginalURL <- (map["image_original_url"], URLTransform()) | ||
imageURL <- (map["image_url"], URLTransform()) | ||
imagemp4URL <- (map["image_mp4_url"], URLTransform()) | ||
imageFrameCount <- (map["image_frames"], stringToIntTransform) | ||
imageWidth <- (map["image_width"], stringToIntTransform) | ||
imageHeight <- (map["image_height"], stringToIntTransform) | ||
|
||
fixedHeightDownsampledURL <- (map["fixed_height_downsampled_url"], URLTransform()) | ||
fixedHeightDownsampledWidth <- (map["fixed_height_downsampled_width"], stringToIntTransform) | ||
fixedHeightDownsampledHeight <- (map["fixed_height_downsampled_height"], stringToIntTransform) | ||
|
||
fixedWidthDownsampledURL <- (map["fixed_width_downsampled_url"], URLTransform()) | ||
fixedWidthDownsampledHeight <- (map["fixed_width_downsampled_height"], stringToIntTransform) | ||
fixedWidthDownsampledWidth <- (map["fixed_width_downsampled_width"], stringToIntTransform) | ||
|
||
fixedHeightSmallURL <- (map["fixed_height_small_url"], URLTransform()) | ||
fixedHeightSmallStillURL <- (map["fixed_height_small_still_url"], URLTransform()) | ||
fixedHeightSmallWidth <- (map["fixed_height_small_width"], stringToIntTransform) | ||
fixedHeightSmallHeight <- (map["fixed_height_small_height"], stringToIntTransform) | ||
|
||
fixedWidthSmallURL <- (map["fixed_width_small_url"], URLTransform()) | ||
fixedWidthSmallStillURL <- (map["fixed_width_small_still_url"], URLTransform()) | ||
fixedWidthSmallWidth <- (map["fixed_width_small_width"], stringToIntTransform) | ||
fixedWidthSmallHeight <- (map["fixed_width_small_height"], stringToIntTransform) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// GiphySimpleSingleGIFResponse.swift | ||
// Pods | ||
// | ||
// Created by Brendan Lee on 3/15/17. | ||
// | ||
// | ||
|
||
import Foundation | ||
import ObjectMapper | ||
|
||
public struct GiphySimpleSingleGIFResponse: Mappable { | ||
|
||
public fileprivate(set) var gif: GiphySimpleItem? | ||
|
||
public fileprivate(set) var meta: GiphyMeta? | ||
|
||
public init?(map: Map) | ||
{ | ||
|
||
} | ||
|
||
mutating public func mapping(map: Map) { | ||
|
||
gif <- map["data"] | ||
meta <- map["meta"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// GiphySingleGIFResponse.swift | ||
// Pods | ||
// | ||
// Created by Brendan Lee on 3/15/17. | ||
// | ||
// | ||
|
||
import Foundation | ||
import ObjectMapper | ||
|
||
public struct GiphySingleGIFResponse: Mappable { | ||
|
||
public fileprivate(set) var gif: GiphyItem? | ||
|
||
public fileprivate(set) var meta: GiphyMeta? | ||
|
||
public init?(map: Map) | ||
{ | ||
|
||
} | ||
|
||
mutating public func mapping(map: Map) { | ||
|
||
gif <- map["data"] | ||
meta <- map["meta"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// GiphyUser.swift | ||
// Pods | ||
// | ||
// Created by Brendan Lee on 3/15/17. | ||
// | ||
// | ||
|
||
import Foundation | ||
import ObjectMapper | ||
|
||
public struct GiphyUser: Mappable { | ||
|
||
public fileprivate(set) var avatarURL: URL? | ||
public fileprivate(set) var bannerURL: URL? | ||
public fileprivate(set) var profileURL: URL? | ||
public fileprivate(set) var username: String = "" | ||
public fileprivate(set) var displayName: String = "" | ||
public fileprivate(set) var twitterHandle: String? | ||
|
||
public init?(map: Map) | ||
{ | ||
|
||
} | ||
|
||
mutating public func mapping(map: Map) { | ||
|
||
avatarURL <- (map["avatar_url"], URLTransform()) | ||
bannerURL <- (map["banner_url"], URLTransform()) | ||
profileURL <- (map["profile_url"], URLTransform()) | ||
username <- map["username"] | ||
displayName <- map["display_name"] | ||
twitterHandle <- map["twitter"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// ParsingTransforms.swift | ||
// Pods | ||
// | ||
// Created by Brendan Lee on 3/15/17. | ||
// | ||
// | ||
|
||
import Foundation | ||
import ObjectMapper | ||
|
||
let stringToIntTransform = TransformOf<Int, String>(fromJSON: { (value: String?) -> Int in | ||
|
||
return Int(value ?? "0") ?? 0 | ||
}, toJSON: { (value: Int?) -> String? in | ||
// transform value from Int? to String? | ||
if let value = value { | ||
return String(value) | ||
} | ||
return nil | ||
}) |
Oops, something went wrong.