GiphyModel.swift 981 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // GiphyModel.swift
  3. // LiveLikeGiphyChallenge
  4. //
  5. // Created by Arbnor Tefiki on 6.2.22.
  6. //
  7. import Foundation
  8. struct GiphyModel: Decodable {
  9. var gifs: [Gif]
  10. var pagination: Pagination?
  11. var meta: Meta?
  12. enum CodingKeys: String, CodingKey {
  13. case gifs = "data"
  14. case pagination = "pagination"
  15. case meta = "meta"
  16. }
  17. }
  18. struct Gif: Decodable {
  19. var gifSources: GifImages
  20. enum CodingKeys: String, CodingKey {
  21. case gifSources = "images"
  22. }
  23. func getGifURL() -> String{
  24. return gifSources.fixedHeight.url
  25. }
  26. }
  27. struct GifImages: Decodable {
  28. var fixedHeight: GiphyContent
  29. enum CodingKeys: String, CodingKey {
  30. case fixedHeight = "fixed_height"
  31. }
  32. }
  33. struct GiphyContent: Decodable {
  34. var url: String
  35. }
  36. struct Pagination: Decodable {
  37. var offset: Int?
  38. var totalCount: Int?
  39. var count: Int?
  40. enum CodingKeys: String, CodingKey {
  41. case totalCount = "total_count"
  42. }
  43. }
  44. struct Meta: Decodable {
  45. var msg: String
  46. var status: Int
  47. }