unifiedcard.nim 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import options, tables
  2. from ../../types import VideoType, VideoVariant
  3. type
  4. UnifiedCard* = object
  5. componentObjects*: Table[string, Component]
  6. destinationObjects*: Table[string, Destination]
  7. mediaEntities*: Table[string, MediaEntity]
  8. appStoreData*: Table[string, seq[AppStoreData]]
  9. ComponentType* = enum
  10. details
  11. media
  12. swipeableMedia
  13. buttonGroup
  14. appStoreDetails
  15. twitterListDetails
  16. communityDetails
  17. mediaWithDetailsHorizontal
  18. hidden
  19. unknown
  20. Component* = object
  21. kind*: ComponentType
  22. data*: ComponentData
  23. ComponentData* = object
  24. id*: string
  25. appId*: string
  26. mediaId*: string
  27. destination*: string
  28. title*: Text
  29. subtitle*: Text
  30. name*: Text
  31. memberCount*: int
  32. mediaList*: seq[MediaItem]
  33. topicDetail*: tuple[title: Text]
  34. MediaItem* = object
  35. id*: string
  36. destination*: string
  37. Destination* = object
  38. kind*: string
  39. data*: tuple[urlData: UrlData]
  40. UrlData* = object
  41. url*: string
  42. vanity*: string
  43. MediaType* = enum
  44. photo, video, model3d
  45. MediaEntity* = object
  46. kind*: MediaType
  47. mediaUrlHttps*: string
  48. videoInfo*: Option[VideoInfo]
  49. VideoInfo* = object
  50. durationMillis*: int
  51. variants*: seq[VideoVariant]
  52. AppType* = enum
  53. androidApp, iPhoneApp, iPadApp
  54. AppStoreData* = object
  55. kind*: AppType
  56. id*: string
  57. title*: Text
  58. category*: Text
  59. Text = object
  60. content: string
  61. TypeField = Component | Destination | MediaEntity | AppStoreData
  62. converter fromText*(text: Text): string = text.content
  63. proc renameHook*(v: var TypeField; fieldName: var string) =
  64. if fieldName == "type":
  65. fieldName = "kind"
  66. proc enumHook*(s: string; v: var ComponentType) =
  67. v = case s
  68. of "details": details
  69. of "media": media
  70. of "swipeable_media": swipeableMedia
  71. of "button_group": buttonGroup
  72. of "app_store_details": appStoreDetails
  73. of "twitter_list_details": twitterListDetails
  74. of "community_details": communityDetails
  75. of "media_with_details_horizontal": mediaWithDetailsHorizontal
  76. of "commerce_drop_details": hidden
  77. else: echo "ERROR: Unknown enum value (ComponentType): ", s; unknown
  78. proc enumHook*(s: string; v: var AppType) =
  79. v = case s
  80. of "android_app": androidApp
  81. of "iphone_app": iPhoneApp
  82. of "ipad_app": iPadApp
  83. else: echo "ERROR: Unknown enum value (AppType): ", s; androidApp
  84. proc enumHook*(s: string; v: var MediaType) =
  85. v = case s
  86. of "video": video
  87. of "photo": photo
  88. of "model3d": model3d
  89. else: echo "ERROR: Unknown enum value (MediaType): ", s; photo