terminal-shop 0.1.0.pre.alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +127 -0
  3. data/lib/terminal-shop/base_client.rb +452 -0
  4. data/lib/terminal-shop/base_model.rb +1189 -0
  5. data/lib/terminal-shop/base_page.rb +44 -0
  6. data/lib/terminal-shop/client.rb +135 -0
  7. data/lib/terminal-shop/errors.rb +187 -0
  8. data/lib/terminal-shop/extern.rb +10 -0
  9. data/lib/terminal-shop/models/address.rb +101 -0
  10. data/lib/terminal-shop/models/address_create_params.rb +86 -0
  11. data/lib/terminal-shop/models/address_create_response.rb +26 -0
  12. data/lib/terminal-shop/models/address_delete_params.rb +18 -0
  13. data/lib/terminal-shop/models/address_delete_response.rb +25 -0
  14. data/lib/terminal-shop/models/address_list_params.rb +18 -0
  15. data/lib/terminal-shop/models/address_list_response.rb +26 -0
  16. data/lib/terminal-shop/models/app.rb +44 -0
  17. data/lib/terminal-shop/models/app_create_params.rb +18 -0
  18. data/lib/terminal-shop/models/app_create_response.rb +54 -0
  19. data/lib/terminal-shop/models/app_delete_params.rb +18 -0
  20. data/lib/terminal-shop/models/app_delete_response.rb +25 -0
  21. data/lib/terminal-shop/models/app_get_params.rb +18 -0
  22. data/lib/terminal-shop/models/app_get_response.rb +26 -0
  23. data/lib/terminal-shop/models/app_list_params.rb +18 -0
  24. data/lib/terminal-shop/models/app_list_response.rb +26 -0
  25. data/lib/terminal-shop/models/card.rb +83 -0
  26. data/lib/terminal-shop/models/card_collect_params.rb +18 -0
  27. data/lib/terminal-shop/models/card_collect_response.rb +50 -0
  28. data/lib/terminal-shop/models/card_create_params.rb +26 -0
  29. data/lib/terminal-shop/models/card_create_response.rb +26 -0
  30. data/lib/terminal-shop/models/card_delete_params.rb +18 -0
  31. data/lib/terminal-shop/models/card_delete_response.rb +25 -0
  32. data/lib/terminal-shop/models/card_list_params.rb +18 -0
  33. data/lib/terminal-shop/models/card_list_response.rb +26 -0
  34. data/lib/terminal-shop/models/cart.rb +200 -0
  35. data/lib/terminal-shop/models/cart_convert_params.rb +18 -0
  36. data/lib/terminal-shop/models/cart_convert_response.rb +26 -0
  37. data/lib/terminal-shop/models/cart_get_params.rb +18 -0
  38. data/lib/terminal-shop/models/cart_get_response.rb +26 -0
  39. data/lib/terminal-shop/models/cart_set_address_params.rb +25 -0
  40. data/lib/terminal-shop/models/cart_set_address_response.rb +25 -0
  41. data/lib/terminal-shop/models/cart_set_card_params.rb +25 -0
  42. data/lib/terminal-shop/models/cart_set_card_response.rb +25 -0
  43. data/lib/terminal-shop/models/cart_set_item_params.rb +32 -0
  44. data/lib/terminal-shop/models/cart_set_item_response.rb +26 -0
  45. data/lib/terminal-shop/models/email_create_params.rb +25 -0
  46. data/lib/terminal-shop/models/email_create_response.rb +25 -0
  47. data/lib/terminal-shop/models/order.rb +303 -0
  48. data/lib/terminal-shop/models/order_get_params.rb +18 -0
  49. data/lib/terminal-shop/models/order_get_response.rb +26 -0
  50. data/lib/terminal-shop/models/order_list_params.rb +18 -0
  51. data/lib/terminal-shop/models/order_list_response.rb +26 -0
  52. data/lib/terminal-shop/models/product.rb +141 -0
  53. data/lib/terminal-shop/models/product_list_params.rb +18 -0
  54. data/lib/terminal-shop/models/product_list_response.rb +26 -0
  55. data/lib/terminal-shop/models/product_variant.rb +44 -0
  56. data/lib/terminal-shop/models/profile.rb +83 -0
  57. data/lib/terminal-shop/models/profile_me_params.rb +18 -0
  58. data/lib/terminal-shop/models/profile_me_response.rb +26 -0
  59. data/lib/terminal-shop/models/profile_update_params.rb +32 -0
  60. data/lib/terminal-shop/models/profile_update_response.rb +26 -0
  61. data/lib/terminal-shop/models/subscription.rb +113 -0
  62. data/lib/terminal-shop/models/subscription_create_params.rb +18 -0
  63. data/lib/terminal-shop/models/subscription_create_response.rb +25 -0
  64. data/lib/terminal-shop/models/subscription_delete_params.rb +18 -0
  65. data/lib/terminal-shop/models/subscription_delete_response.rb +25 -0
  66. data/lib/terminal-shop/models/subscription_list_params.rb +18 -0
  67. data/lib/terminal-shop/models/subscription_list_response.rb +26 -0
  68. data/lib/terminal-shop/models/token.rb +68 -0
  69. data/lib/terminal-shop/models/token_create_params.rb +18 -0
  70. data/lib/terminal-shop/models/token_create_response.rb +55 -0
  71. data/lib/terminal-shop/models/token_delete_params.rb +18 -0
  72. data/lib/terminal-shop/models/token_delete_response.rb +25 -0
  73. data/lib/terminal-shop/models/token_get_params.rb +18 -0
  74. data/lib/terminal-shop/models/token_get_response.rb +27 -0
  75. data/lib/terminal-shop/models/token_list_params.rb +18 -0
  76. data/lib/terminal-shop/models/token_list_response.rb +26 -0
  77. data/lib/terminal-shop/models/view_init_params.rb +18 -0
  78. data/lib/terminal-shop/models/view_init_response.rb +103 -0
  79. data/lib/terminal-shop/pooled_net_requester.rb +94 -0
  80. data/lib/terminal-shop/request_options.rb +115 -0
  81. data/lib/terminal-shop/resources/address.rb +84 -0
  82. data/lib/terminal-shop/resources/app.rb +93 -0
  83. data/lib/terminal-shop/resources/card.rb +89 -0
  84. data/lib/terminal-shop/resources/cart.rb +112 -0
  85. data/lib/terminal-shop/resources/email.rb +34 -0
  86. data/lib/terminal-shop/resources/order.rb +49 -0
  87. data/lib/terminal-shop/resources/product.rb +30 -0
  88. data/lib/terminal-shop/resources/profile.rb +53 -0
  89. data/lib/terminal-shop/resources/subscription.rb +82 -0
  90. data/lib/terminal-shop/resources/token.rb +85 -0
  91. data/lib/terminal-shop/resources/view.rb +31 -0
  92. data/lib/terminal-shop/util.rb +460 -0
  93. data/lib/terminal-shop/version.rb +5 -0
  94. data/lib/terminal-shop.rb +110 -0
  95. data/manifest.yaml +12 -0
  96. data/rbi/lib/terminal-shop/base_client.rbi +145 -0
  97. data/rbi/lib/terminal-shop/base_model.rbi +514 -0
  98. data/rbi/lib/terminal-shop/base_page.rbi +38 -0
  99. data/rbi/lib/terminal-shop/client.rbi +80 -0
  100. data/rbi/lib/terminal-shop/errors.rbi +133 -0
  101. data/rbi/lib/terminal-shop/extern.rbi +7 -0
  102. data/rbi/lib/terminal-shop/models/address.rbi +77 -0
  103. data/rbi/lib/terminal-shop/models/address_create_params.rbi +87 -0
  104. data/rbi/lib/terminal-shop/models/address_create_response.rbi +18 -0
  105. data/rbi/lib/terminal-shop/models/address_delete_params.rbi +18 -0
  106. data/rbi/lib/terminal-shop/models/address_delete_response.rbi +18 -0
  107. data/rbi/lib/terminal-shop/models/address_list_params.rbi +18 -0
  108. data/rbi/lib/terminal-shop/models/address_list_response.rbi +18 -0
  109. data/rbi/lib/terminal-shop/models/app.rbi +24 -0
  110. data/rbi/lib/terminal-shop/models/app_create_params.rbi +18 -0
  111. data/rbi/lib/terminal-shop/models/app_create_response.rbi +34 -0
  112. data/rbi/lib/terminal-shop/models/app_delete_params.rbi +18 -0
  113. data/rbi/lib/terminal-shop/models/app_delete_response.rbi +18 -0
  114. data/rbi/lib/terminal-shop/models/app_get_params.rbi +18 -0
  115. data/rbi/lib/terminal-shop/models/app_get_response.rbi +18 -0
  116. data/rbi/lib/terminal-shop/models/app_list_params.rbi +18 -0
  117. data/rbi/lib/terminal-shop/models/app_list_response.rbi +18 -0
  118. data/rbi/lib/terminal-shop/models/card.rbi +59 -0
  119. data/rbi/lib/terminal-shop/models/card_collect_params.rbi +18 -0
  120. data/rbi/lib/terminal-shop/models/card_collect_response.rbi +31 -0
  121. data/rbi/lib/terminal-shop/models/card_create_params.rbi +26 -0
  122. data/rbi/lib/terminal-shop/models/card_create_response.rbi +18 -0
  123. data/rbi/lib/terminal-shop/models/card_delete_params.rbi +18 -0
  124. data/rbi/lib/terminal-shop/models/card_delete_response.rbi +18 -0
  125. data/rbi/lib/terminal-shop/models/card_list_params.rbi +18 -0
  126. data/rbi/lib/terminal-shop/models/card_list_response.rbi +18 -0
  127. data/rbi/lib/terminal-shop/models/cart.rbi +127 -0
  128. data/rbi/lib/terminal-shop/models/cart_convert_params.rbi +18 -0
  129. data/rbi/lib/terminal-shop/models/cart_convert_response.rbi +18 -0
  130. data/rbi/lib/terminal-shop/models/cart_get_params.rbi +18 -0
  131. data/rbi/lib/terminal-shop/models/cart_get_response.rbi +18 -0
  132. data/rbi/lib/terminal-shop/models/cart_set_address_params.rbi +26 -0
  133. data/rbi/lib/terminal-shop/models/cart_set_address_response.rbi +18 -0
  134. data/rbi/lib/terminal-shop/models/cart_set_card_params.rbi +26 -0
  135. data/rbi/lib/terminal-shop/models/cart_set_card_response.rbi +18 -0
  136. data/rbi/lib/terminal-shop/models/cart_set_item_params.rbi +38 -0
  137. data/rbi/lib/terminal-shop/models/cart_set_item_response.rbi +18 -0
  138. data/rbi/lib/terminal-shop/models/email_create_params.rbi +26 -0
  139. data/rbi/lib/terminal-shop/models/email_create_response.rbi +18 -0
  140. data/rbi/lib/terminal-shop/models/order.rbi +216 -0
  141. data/rbi/lib/terminal-shop/models/order_get_params.rbi +18 -0
  142. data/rbi/lib/terminal-shop/models/order_get_response.rbi +18 -0
  143. data/rbi/lib/terminal-shop/models/order_list_params.rbi +18 -0
  144. data/rbi/lib/terminal-shop/models/order_list_response.rbi +18 -0
  145. data/rbi/lib/terminal-shop/models/product.rbi +94 -0
  146. data/rbi/lib/terminal-shop/models/product_list_params.rbi +18 -0
  147. data/rbi/lib/terminal-shop/models/product_list_response.rbi +18 -0
  148. data/rbi/lib/terminal-shop/models/product_variant.rbi +24 -0
  149. data/rbi/lib/terminal-shop/models/profile.rbi +61 -0
  150. data/rbi/lib/terminal-shop/models/profile_me_params.rbi +18 -0
  151. data/rbi/lib/terminal-shop/models/profile_me_response.rbi +18 -0
  152. data/rbi/lib/terminal-shop/models/profile_update_params.rbi +38 -0
  153. data/rbi/lib/terminal-shop/models/profile_update_response.rbi +18 -0
  154. data/rbi/lib/terminal-shop/models/subscription.rbi +75 -0
  155. data/rbi/lib/terminal-shop/models/subscription_create_params.rbi +18 -0
  156. data/rbi/lib/terminal-shop/models/subscription_create_response.rbi +18 -0
  157. data/rbi/lib/terminal-shop/models/subscription_delete_params.rbi +18 -0
  158. data/rbi/lib/terminal-shop/models/subscription_delete_response.rbi +18 -0
  159. data/rbi/lib/terminal-shop/models/subscription_list_params.rbi +18 -0
  160. data/rbi/lib/terminal-shop/models/subscription_list_response.rbi +18 -0
  161. data/rbi/lib/terminal-shop/models/token.rbi +37 -0
  162. data/rbi/lib/terminal-shop/models/token_create_params.rbi +18 -0
  163. data/rbi/lib/terminal-shop/models/token_create_response.rbi +34 -0
  164. data/rbi/lib/terminal-shop/models/token_delete_params.rbi +18 -0
  165. data/rbi/lib/terminal-shop/models/token_delete_response.rbi +18 -0
  166. data/rbi/lib/terminal-shop/models/token_get_params.rbi +18 -0
  167. data/rbi/lib/terminal-shop/models/token_get_response.rbi +18 -0
  168. data/rbi/lib/terminal-shop/models/token_list_params.rbi +18 -0
  169. data/rbi/lib/terminal-shop/models/token_list_response.rbi +18 -0
  170. data/rbi/lib/terminal-shop/models/view_init_params.rbi +18 -0
  171. data/rbi/lib/terminal-shop/models/view_init_response.rbi +91 -0
  172. data/rbi/lib/terminal-shop/request_options.rbi +40 -0
  173. data/rbi/lib/terminal-shop/resources/address.rbi +60 -0
  174. data/rbi/lib/terminal-shop/resources/app.rbi +54 -0
  175. data/rbi/lib/terminal-shop/resources/card.rbi +57 -0
  176. data/rbi/lib/terminal-shop/resources/cart.rbi +67 -0
  177. data/rbi/lib/terminal-shop/resources/email.rbi +20 -0
  178. data/rbi/lib/terminal-shop/resources/order.rbi +34 -0
  179. data/rbi/lib/terminal-shop/resources/product.rbi +25 -0
  180. data/rbi/lib/terminal-shop/resources/profile.rbi +35 -0
  181. data/rbi/lib/terminal-shop/resources/subscription.rbi +58 -0
  182. data/rbi/lib/terminal-shop/resources/token.rbi +57 -0
  183. data/rbi/lib/terminal-shop/resources/view.rbi +25 -0
  184. data/rbi/lib/terminal-shop/util.rbi +128 -0
  185. data/rbi/lib/terminal-shop/version.rbi +5 -0
  186. data/sig/terminal-shop/base_client.rbs +100 -0
  187. data/sig/terminal-shop/base_model.rbs +246 -0
  188. data/sig/terminal-shop/base_page.rbs +20 -0
  189. data/sig/terminal-shop/client.rbs +52 -0
  190. data/sig/terminal-shop/errors.rbs +98 -0
  191. data/sig/terminal-shop/extern.rbs +4 -0
  192. data/sig/terminal-shop/models/address.rbs +60 -0
  193. data/sig/terminal-shop/models/address_create_params.rbs +62 -0
  194. data/sig/terminal-shop/models/address_create_response.rbs +18 -0
  195. data/sig/terminal-shop/models/address_delete_params.rbs +19 -0
  196. data/sig/terminal-shop/models/address_delete_response.rbs +18 -0
  197. data/sig/terminal-shop/models/address_list_params.rbs +19 -0
  198. data/sig/terminal-shop/models/address_list_response.rbs +19 -0
  199. data/sig/terminal-shop/models/app.rbs +21 -0
  200. data/sig/terminal-shop/models/app_create_params.rbs +19 -0
  201. data/sig/terminal-shop/models/app_create_response.rbs +36 -0
  202. data/sig/terminal-shop/models/app_delete_params.rbs +19 -0
  203. data/sig/terminal-shop/models/app_delete_response.rbs +18 -0
  204. data/sig/terminal-shop/models/app_get_params.rbs +18 -0
  205. data/sig/terminal-shop/models/app_get_response.rbs +17 -0
  206. data/sig/terminal-shop/models/app_list_params.rbs +18 -0
  207. data/sig/terminal-shop/models/app_list_response.rbs +18 -0
  208. data/sig/terminal-shop/models/card.rbs +51 -0
  209. data/sig/terminal-shop/models/card_collect_params.rbs +19 -0
  210. data/sig/terminal-shop/models/card_collect_response.rbs +34 -0
  211. data/sig/terminal-shop/models/card_create_params.rbs +22 -0
  212. data/sig/terminal-shop/models/card_create_response.rbs +18 -0
  213. data/sig/terminal-shop/models/card_delete_params.rbs +19 -0
  214. data/sig/terminal-shop/models/card_delete_response.rbs +18 -0
  215. data/sig/terminal-shop/models/card_list_params.rbs +18 -0
  216. data/sig/terminal-shop/models/card_list_response.rbs +18 -0
  217. data/sig/terminal-shop/models/cart.rbs +119 -0
  218. data/sig/terminal-shop/models/cart_convert_params.rbs +19 -0
  219. data/sig/terminal-shop/models/cart_convert_response.rbs +18 -0
  220. data/sig/terminal-shop/models/cart_get_params.rbs +18 -0
  221. data/sig/terminal-shop/models/cart_get_response.rbs +18 -0
  222. data/sig/terminal-shop/models/cart_set_address_params.rbs +25 -0
  223. data/sig/terminal-shop/models/cart_set_address_response.rbs +18 -0
  224. data/sig/terminal-shop/models/cart_set_card_params.rbs +22 -0
  225. data/sig/terminal-shop/models/cart_set_card_response.rbs +18 -0
  226. data/sig/terminal-shop/models/cart_set_item_params.rbs +29 -0
  227. data/sig/terminal-shop/models/cart_set_item_response.rbs +18 -0
  228. data/sig/terminal-shop/models/email_create_params.rbs +22 -0
  229. data/sig/terminal-shop/models/email_create_response.rbs +18 -0
  230. data/sig/terminal-shop/models/order.rbs +179 -0
  231. data/sig/terminal-shop/models/order_get_params.rbs +18 -0
  232. data/sig/terminal-shop/models/order_get_response.rbs +18 -0
  233. data/sig/terminal-shop/models/order_list_params.rbs +19 -0
  234. data/sig/terminal-shop/models/order_list_response.rbs +18 -0
  235. data/sig/terminal-shop/models/product.rbs +76 -0
  236. data/sig/terminal-shop/models/product_list_params.rbs +19 -0
  237. data/sig/terminal-shop/models/product_list_response.rbs +19 -0
  238. data/sig/terminal-shop/models/product_variant.rbs +21 -0
  239. data/sig/terminal-shop/models/profile.rbs +53 -0
  240. data/sig/terminal-shop/models/profile_me_params.rbs +19 -0
  241. data/sig/terminal-shop/models/profile_me_response.rbs +18 -0
  242. data/sig/terminal-shop/models/profile_update_params.rbs +28 -0
  243. data/sig/terminal-shop/models/profile_update_response.rbs +18 -0
  244. data/sig/terminal-shop/models/subscription.rbs +60 -0
  245. data/sig/terminal-shop/models/subscription_create_params.rbs +19 -0
  246. data/sig/terminal-shop/models/subscription_create_response.rbs +18 -0
  247. data/sig/terminal-shop/models/subscription_delete_params.rbs +19 -0
  248. data/sig/terminal-shop/models/subscription_delete_response.rbs +18 -0
  249. data/sig/terminal-shop/models/subscription_list_params.rbs +19 -0
  250. data/sig/terminal-shop/models/subscription_list_response.rbs +19 -0
  251. data/sig/terminal-shop/models/token.rbs +40 -0
  252. data/sig/terminal-shop/models/token_create_params.rbs +19 -0
  253. data/sig/terminal-shop/models/token_create_response.rbs +36 -0
  254. data/sig/terminal-shop/models/token_delete_params.rbs +19 -0
  255. data/sig/terminal-shop/models/token_delete_response.rbs +18 -0
  256. data/sig/terminal-shop/models/token_get_params.rbs +18 -0
  257. data/sig/terminal-shop/models/token_get_response.rbs +18 -0
  258. data/sig/terminal-shop/models/token_list_params.rbs +19 -0
  259. data/sig/terminal-shop/models/token_list_response.rbs +18 -0
  260. data/sig/terminal-shop/models/view_init_params.rbs +18 -0
  261. data/sig/terminal-shop/models/view_init_response.rbs +71 -0
  262. data/sig/terminal-shop/request_options.rbs +42 -0
  263. data/sig/terminal-shop/resources/address.rbs +41 -0
  264. data/sig/terminal-shop/resources/app.rbs +46 -0
  265. data/sig/terminal-shop/resources/card.rbs +42 -0
  266. data/sig/terminal-shop/resources/cart.rbs +51 -0
  267. data/sig/terminal-shop/resources/email.rbs +16 -0
  268. data/sig/terminal-shop/resources/order.rbs +25 -0
  269. data/sig/terminal-shop/resources/product.rbs +15 -0
  270. data/sig/terminal-shop/resources/profile.rbs +25 -0
  271. data/sig/terminal-shop/resources/subscription.rbs +43 -0
  272. data/sig/terminal-shop/resources/token.rbs +43 -0
  273. data/sig/terminal-shop/resources/view.rbs +15 -0
  274. data/sig/terminal-shop/util.rbs +85 -0
  275. data/sig/terminal-shop/version.rbs +3 -0
  276. metadata +333 -0
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TerminalShop
4
+ # @private
5
+ #
6
+ # @abstract
7
+ #
8
+ module BasePage
9
+ # rubocop:disable Lint/UnusedMethodArgument
10
+
11
+ # @return [Boolean]
12
+ #
13
+ def next_page? = (raise NotImplementedError)
14
+
15
+ # @raise [TerminalShop::APIError]
16
+ # @return [TerminalShop::BasePage]
17
+ #
18
+ def next_page = (raise NotImplementedError)
19
+
20
+ # @param blk [Proc]
21
+ #
22
+ # @return [void]
23
+ #
24
+ def auto_paging_each(&blk) = (raise NotImplementedError)
25
+
26
+ # @return [Enumerable]
27
+ #
28
+ def to_enum = super(:auto_paging_each)
29
+
30
+ alias_method :enum_for, :to_enum
31
+
32
+ # @!parse
33
+ # # @private
34
+ # #
35
+ # # @param client [TerminalShop::BaseClient]
36
+ # # @param req [Hash{Symbol=>Object}]
37
+ # # @param headers [Hash{String=>String}]
38
+ # # @param unwrapped [Object]
39
+ # #
40
+ # def initialize(client:, req:, headers:, unwrapped:); end
41
+
42
+ # rubocop:enable Lint/UnusedMethodArgument
43
+ end
44
+ end
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TerminalShop
4
+ class Client < TerminalShop::BaseClient
5
+ # Default max number of retries to attempt after a failed retryable request.
6
+ DEFAULT_MAX_RETRIES = 2
7
+
8
+ # Default per-request timeout.
9
+ DEFAULT_TIMEOUT_IN_SECONDS = 60.0
10
+
11
+ # Default initial retry delay in seconds.
12
+ # Overall delay is calculated using exponential backoff + jitter.
13
+ DEFAULT_INITIAL_RETRY_DELAY = 0.5
14
+
15
+ # Default max retry delay in seconds.
16
+ DEFAULT_MAX_RETRY_DELAY = 8.0
17
+
18
+ # rubocop:disable Style/MutableConstant
19
+ ENVIRONMENTS = {production: "https://api.terminal.shop/", sandbox: "https://sandbox.terminal.shop/"}
20
+ # rubocop:enable Style/MutableConstant
21
+
22
+ # Client option
23
+ # @return [String]
24
+ attr_reader :bearer_token
25
+
26
+ # @return [TerminalShop::Resources::Product]
27
+ attr_reader :product
28
+
29
+ # @return [TerminalShop::Resources::Profile]
30
+ attr_reader :profile
31
+
32
+ # @return [TerminalShop::Resources::Address]
33
+ attr_reader :address
34
+
35
+ # @return [TerminalShop::Resources::Card]
36
+ attr_reader :card
37
+
38
+ # @return [TerminalShop::Resources::Cart]
39
+ attr_reader :cart
40
+
41
+ # @return [TerminalShop::Resources::Order]
42
+ attr_reader :order
43
+
44
+ # @return [TerminalShop::Resources::Subscription]
45
+ attr_reader :subscription
46
+
47
+ # @return [TerminalShop::Resources::Token]
48
+ attr_reader :token
49
+
50
+ # @return [TerminalShop::Resources::App]
51
+ attr_reader :app
52
+
53
+ # @return [TerminalShop::Resources::Email]
54
+ attr_reader :email
55
+
56
+ # @return [TerminalShop::Resources::View]
57
+ attr_reader :view
58
+
59
+ # @private
60
+ #
61
+ # @return [Hash{String=>String}]
62
+ #
63
+ private def auth_headers
64
+ {"Authorization" => "Bearer #{@bearer_token}"}
65
+ end
66
+
67
+ # Creates and returns a new client for interacting with the API.
68
+ #
69
+ # @param environment [:production, :sandbox, nil] Specifies the environment to use for the API.
70
+ #
71
+ # Each environment maps to a different base URL:
72
+ #
73
+ # - `production` corresponds to `https://api.terminal.shop/`
74
+ # - `sandbox` corresponds to `https://sandbox.terminal.shop/`
75
+ #
76
+ # @param base_url [String, nil] Override the default base URL for the API, e.g., `"https://api.example.com/v2/"`
77
+ #
78
+ # @param bearer_token [String, nil] Defaults to `ENV["TERMINAL_BEARER_TOKEN"]`
79
+ #
80
+ # @param max_retries [Integer] Max number of retries to attempt after a failed retryable request.
81
+ #
82
+ # @param timeout [Float]
83
+ #
84
+ # @param initial_retry_delay [Float]
85
+ #
86
+ # @param max_retry_delay [Float]
87
+ #
88
+ def initialize(
89
+ environment: nil,
90
+ base_url: nil,
91
+ bearer_token: ENV["TERMINAL_BEARER_TOKEN"],
92
+ max_retries: DEFAULT_MAX_RETRIES,
93
+ timeout: DEFAULT_TIMEOUT_IN_SECONDS,
94
+ initial_retry_delay: DEFAULT_INITIAL_RETRY_DELAY,
95
+ max_retry_delay: DEFAULT_MAX_RETRY_DELAY
96
+ )
97
+ case [environment, base_url]
98
+ in [Symbol | String, String]
99
+ raise ArgumentError.new("both environment and base_url given, expected only one")
100
+ in [Symbol | String, nil]
101
+ base_url = ENVIRONMENTS.fetch(environment.to_sym) do
102
+ raise ArgumentError.new("environment must be one of #{ENVIRONMENTS.keys}, got #{environment}")
103
+ end
104
+ else
105
+ base_url ||= ENVIRONMENTS.fetch(:production)
106
+ end
107
+
108
+ if bearer_token.nil?
109
+ raise ArgumentError.new("bearer_token is required")
110
+ end
111
+
112
+ @bearer_token = bearer_token.to_s
113
+
114
+ super(
115
+ base_url: base_url,
116
+ timeout: timeout,
117
+ max_retries: max_retries,
118
+ initial_retry_delay: initial_retry_delay,
119
+ max_retry_delay: max_retry_delay
120
+ )
121
+
122
+ @product = TerminalShop::Resources::Product.new(client: self)
123
+ @profile = TerminalShop::Resources::Profile.new(client: self)
124
+ @address = TerminalShop::Resources::Address.new(client: self)
125
+ @card = TerminalShop::Resources::Card.new(client: self)
126
+ @cart = TerminalShop::Resources::Cart.new(client: self)
127
+ @order = TerminalShop::Resources::Order.new(client: self)
128
+ @subscription = TerminalShop::Resources::Subscription.new(client: self)
129
+ @token = TerminalShop::Resources::Token.new(client: self)
130
+ @app = TerminalShop::Resources::App.new(client: self)
131
+ @email = TerminalShop::Resources::Email.new(client: self)
132
+ @view = TerminalShop::Resources::View.new(client: self)
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,187 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TerminalShop
4
+ class Error < StandardError
5
+ # @!parse
6
+ # # @return [StandardError, nil]
7
+ # attr_reader :cause
8
+ end
9
+
10
+ class ConversionError < TerminalShop::Error
11
+ end
12
+
13
+ class APIError < TerminalShop::Error
14
+ # @return [URI::Generic]
15
+ attr_reader :url
16
+
17
+ # @return [Integer, nil]
18
+ attr_reader :status
19
+
20
+ # @return [Object, nil]
21
+ attr_reader :body
22
+
23
+ # @private
24
+ #
25
+ # @param url [URI::Generic]
26
+ # @param status [Integer, nil]
27
+ # @param body [Object, nil]
28
+ # @param request [nil]
29
+ # @param response [nil]
30
+ # @param message [String, nil]
31
+ #
32
+ def initialize(url:, status: nil, body: nil, request: nil, response: nil, message: nil)
33
+ @url = url
34
+ @status = status
35
+ @body = body
36
+ @request = request
37
+ @response = response
38
+ super(message)
39
+ end
40
+ end
41
+
42
+ class APIConnectionError < TerminalShop::APIError
43
+ # @!parse
44
+ # # @return [nil]
45
+ # attr_reader :status
46
+
47
+ # @!parse
48
+ # # @return [nil]
49
+ # attr_reader :body
50
+
51
+ # @private
52
+ #
53
+ # @param url [URI::Generic]
54
+ # @param status [nil]
55
+ # @param body [nil]
56
+ # @param request [nil]
57
+ # @param response [nil]
58
+ # @param message [String, nil]
59
+ #
60
+ def initialize(
61
+ url:,
62
+ status: nil,
63
+ body: nil,
64
+ request: nil,
65
+ response: nil,
66
+ message: "Connection error."
67
+ )
68
+ super
69
+ end
70
+ end
71
+
72
+ class APITimeoutError < TerminalShop::APIConnectionError
73
+ # @private
74
+ #
75
+ # @param url [URI::Generic]
76
+ # @param status [nil]
77
+ # @param body [nil]
78
+ # @param request [nil]
79
+ # @param response [nil]
80
+ # @param message [String, nil]
81
+ #
82
+ def initialize(
83
+ url:,
84
+ status: nil,
85
+ body: nil,
86
+ request: nil,
87
+ response: nil,
88
+ message: "Request timed out."
89
+ )
90
+ super
91
+ end
92
+ end
93
+
94
+ class APIStatusError < TerminalShop::APIError
95
+ # @private
96
+ #
97
+ # @param url [URI::Generic]
98
+ # @param status [Integer]
99
+ # @param body [Object, nil]
100
+ # @param request [nil]
101
+ # @param response [nil]
102
+ #
103
+ # @return [TerminalShop::APIStatusError]
104
+ #
105
+ def self.for(url:, status:, body:, request:, response:)
106
+ kwargs = {url: url, status: status, body: body, request: request, response: response}
107
+
108
+ case status
109
+ in 400
110
+ TerminalShop::BadRequestError.new(**kwargs)
111
+ in 401
112
+ TerminalShop::AuthenticationError.new(**kwargs)
113
+ in 403
114
+ TerminalShop::PermissionDeniedError.new(**kwargs)
115
+ in 404
116
+ TerminalShop::NotFoundError.new(**kwargs)
117
+ in 409
118
+ TerminalShop::ConflictError.new(**kwargs)
119
+ in 422
120
+ TerminalShop::UnprocessableEntityError.new(**kwargs)
121
+ in 429
122
+ TerminalShop::RateLimitError.new(**kwargs)
123
+ in (500..)
124
+ TerminalShop::InternalServerError.new(**kwargs)
125
+ else
126
+ TerminalShop::APIStatusError.new(**kwargs)
127
+ end
128
+ end
129
+
130
+ # @!parse
131
+ # # @return [Integer]
132
+ # attr_reader :status
133
+
134
+ # @private
135
+ #
136
+ # @param url [URI::Generic]
137
+ # @param status [Integer]
138
+ # @param body [Object, nil]
139
+ # @param request [nil]
140
+ # @param response [nil]
141
+ # @param message [String, nil]
142
+ #
143
+ def initialize(url:, status:, body:, request:, response:, message: nil)
144
+ message ||= {url: url.to_s, status: status, body: body}
145
+ super(
146
+ url: url,
147
+ status: status,
148
+ body: body,
149
+ request: request,
150
+ response: response,
151
+ message: message&.to_s
152
+ )
153
+ end
154
+ end
155
+
156
+ class BadRequestError < TerminalShop::APIStatusError
157
+ HTTP_STATUS = 400
158
+ end
159
+
160
+ class AuthenticationError < TerminalShop::APIStatusError
161
+ HTTP_STATUS = 401
162
+ end
163
+
164
+ class PermissionDeniedError < TerminalShop::APIStatusError
165
+ HTTP_STATUS = 403
166
+ end
167
+
168
+ class NotFoundError < TerminalShop::APIStatusError
169
+ HTTP_STATUS = 404
170
+ end
171
+
172
+ class ConflictError < TerminalShop::APIStatusError
173
+ HTTP_STATUS = 409
174
+ end
175
+
176
+ class UnprocessableEntityError < TerminalShop::APIStatusError
177
+ HTTP_STATUS = 422
178
+ end
179
+
180
+ class RateLimitError < TerminalShop::APIStatusError
181
+ HTTP_STATUS = 429
182
+ end
183
+
184
+ class InternalServerError < TerminalShop::APIStatusError
185
+ HTTP_STATUS = (500..)
186
+ end
187
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TerminalShop
4
+ # @private
5
+ #
6
+ # @abstract
7
+ #
8
+ module Extern
9
+ end
10
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TerminalShop
4
+ module Models
5
+ # @example
6
+ # ```ruby
7
+ # address_api => {
8
+ # id: String,
9
+ # city: String,
10
+ # country: String,
11
+ # name: String,
12
+ # street1: String,
13
+ # **_
14
+ # }
15
+ # ```
16
+ class AddressAPI < TerminalShop::BaseModel
17
+ # @!attribute id
18
+ # Unique object identifier. The format and length of IDs may change over time.
19
+ #
20
+ # @return [String]
21
+ required :id, String
22
+
23
+ # @!attribute city
24
+ # City of the address.
25
+ #
26
+ # @return [String]
27
+ required :city, String
28
+
29
+ # @!attribute country
30
+ # ISO 3166-1 alpha-2 country code of the address.
31
+ #
32
+ # @return [String]
33
+ required :country, String
34
+
35
+ # @!attribute name
36
+ # The recipient's name.
37
+ #
38
+ # @return [String]
39
+ required :name, String
40
+
41
+ # @!attribute street1
42
+ # Street of the address.
43
+ #
44
+ # @return [String]
45
+ required :street1, String
46
+
47
+ # @!attribute zip
48
+ # Zip code of the address.
49
+ #
50
+ # @return [String]
51
+ required :zip, String
52
+
53
+ # @!attribute [r] phone
54
+ # Phone number of the recipient.
55
+ #
56
+ # @return [String, nil]
57
+ optional :phone, String
58
+
59
+ # @!parse
60
+ # # @return [String]
61
+ # attr_writer :phone
62
+
63
+ # @!attribute [r] province
64
+ # Province or state of the address.
65
+ #
66
+ # @return [String, nil]
67
+ optional :province, String
68
+
69
+ # @!parse
70
+ # # @return [String]
71
+ # attr_writer :province
72
+
73
+ # @!attribute [r] street2
74
+ # Apartment, suite, etc. of the address.
75
+ #
76
+ # @return [String, nil]
77
+ optional :street2, String
78
+
79
+ # @!parse
80
+ # # @return [String]
81
+ # attr_writer :street2
82
+
83
+ # @!parse
84
+ # # Physical address associated with a Terminal shop user.
85
+ # #
86
+ # # @param id [String]
87
+ # # @param city [String]
88
+ # # @param country [String]
89
+ # # @param name [String]
90
+ # # @param street1 [String]
91
+ # # @param zip [String]
92
+ # # @param phone [String]
93
+ # # @param province [String]
94
+ # # @param street2 [String]
95
+ # #
96
+ # def initialize(id:, city:, country:, name:, street1:, zip:, phone: nil, province: nil, street2: nil, **) = super
97
+
98
+ # def initialize: (Hash | TerminalShop::BaseModel) -> void
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TerminalShop
4
+ module Models
5
+ class AddressCreateParams < TerminalShop::BaseModel
6
+ # @!parse
7
+ # extend TerminalShop::RequestParameters::Converter
8
+ include TerminalShop::RequestParameters
9
+
10
+ # @!attribute city
11
+ # City of the address.
12
+ #
13
+ # @return [String]
14
+ required :city, String
15
+
16
+ # @!attribute country
17
+ # ISO 3166-1 alpha-2 country code of the address.
18
+ #
19
+ # @return [String]
20
+ required :country, String
21
+
22
+ # @!attribute name
23
+ # The recipient's name.
24
+ #
25
+ # @return [String]
26
+ required :name, String
27
+
28
+ # @!attribute street1
29
+ # Street of the address.
30
+ #
31
+ # @return [String]
32
+ required :street1, String
33
+
34
+ # @!attribute zip
35
+ # Zip code of the address.
36
+ #
37
+ # @return [String]
38
+ required :zip, String
39
+
40
+ # @!attribute [r] phone
41
+ # Phone number of the recipient.
42
+ #
43
+ # @return [String, nil]
44
+ optional :phone, String
45
+
46
+ # @!parse
47
+ # # @return [String]
48
+ # attr_writer :phone
49
+
50
+ # @!attribute [r] province
51
+ # Province or state of the address.
52
+ #
53
+ # @return [String, nil]
54
+ optional :province, String
55
+
56
+ # @!parse
57
+ # # @return [String]
58
+ # attr_writer :province
59
+
60
+ # @!attribute [r] street2
61
+ # Apartment, suite, etc. of the address.
62
+ #
63
+ # @return [String, nil]
64
+ optional :street2, String
65
+
66
+ # @!parse
67
+ # # @return [String]
68
+ # attr_writer :street2
69
+
70
+ # @!parse
71
+ # # @param city [String]
72
+ # # @param country [String]
73
+ # # @param name [String]
74
+ # # @param street1 [String]
75
+ # # @param zip [String]
76
+ # # @param phone [String]
77
+ # # @param province [String]
78
+ # # @param street2 [String]
79
+ # # @param request_options [TerminalShop::RequestOptions, Hash{Symbol=>Object}]
80
+ # #
81
+ # def initialize(city:, country:, name:, street1:, zip:, phone: nil, province: nil, street2: nil, request_options: {}, **) = super
82
+
83
+ # def initialize: (Hash | TerminalShop::BaseModel) -> void
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TerminalShop
4
+ module Models
5
+ # @example
6
+ # ```ruby
7
+ # address_create_response => {
8
+ # data: String
9
+ # }
10
+ # ```
11
+ class AddressCreateResponse < TerminalShop::BaseModel
12
+ # @!attribute data
13
+ # Shipping address ID.
14
+ #
15
+ # @return [String]
16
+ required :data, String
17
+
18
+ # @!parse
19
+ # # @param data [String]
20
+ # #
21
+ # def initialize(data:, **) = super
22
+
23
+ # def initialize: (Hash | TerminalShop::BaseModel) -> void
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TerminalShop
4
+ module Models
5
+ class AddressDeleteParams < TerminalShop::BaseModel
6
+ # @!parse
7
+ # extend TerminalShop::RequestParameters::Converter
8
+ include TerminalShop::RequestParameters
9
+
10
+ # @!parse
11
+ # # @param request_options [TerminalShop::RequestOptions, Hash{Symbol=>Object}]
12
+ # #
13
+ # def initialize(request_options: {}, **) = super
14
+
15
+ # def initialize: (Hash | TerminalShop::BaseModel) -> void
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TerminalShop
4
+ module Models
5
+ # @example
6
+ # ```ruby
7
+ # address_delete_response => {
8
+ # data: :ok
9
+ # }
10
+ # ```
11
+ class AddressDeleteResponse < TerminalShop::BaseModel
12
+ # @!attribute data
13
+ #
14
+ # @return [Symbol, :ok]
15
+ required :data, const: :ok
16
+
17
+ # @!parse
18
+ # # @param data [Symbol, :ok]
19
+ # #
20
+ # def initialize(data: :ok, **) = super
21
+
22
+ # def initialize: (Hash | TerminalShop::BaseModel) -> void
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TerminalShop
4
+ module Models
5
+ class AddressListParams < TerminalShop::BaseModel
6
+ # @!parse
7
+ # extend TerminalShop::RequestParameters::Converter
8
+ include TerminalShop::RequestParameters
9
+
10
+ # @!parse
11
+ # # @param request_options [TerminalShop::RequestOptions, Hash{Symbol=>Object}]
12
+ # #
13
+ # def initialize(request_options: {}, **) = super
14
+
15
+ # def initialize: (Hash | TerminalShop::BaseModel) -> void
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TerminalShop
4
+ module Models
5
+ # @example
6
+ # ```ruby
7
+ # address_list_response => {
8
+ # data: -> { TerminalShop::ArrayOf[TerminalShop::Models::AddressAPI] === _1 }
9
+ # }
10
+ # ```
11
+ class AddressListResponse < TerminalShop::BaseModel
12
+ # @!attribute data
13
+ # Shipping addresses.
14
+ #
15
+ # @return [Array<TerminalShop::Models::AddressAPI>]
16
+ required :data, -> { TerminalShop::ArrayOf[TerminalShop::Models::AddressAPI] }
17
+
18
+ # @!parse
19
+ # # @param data [Array<TerminalShop::Models::AddressAPI>]
20
+ # #
21
+ # def initialize(data:, **) = super
22
+
23
+ # def initialize: (Hash | TerminalShop::BaseModel) -> void
24
+ end
25
+ end
26
+ end