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.
- checksums.yaml +7 -0
- data/README.md +127 -0
- data/lib/terminal-shop/base_client.rb +452 -0
- data/lib/terminal-shop/base_model.rb +1189 -0
- data/lib/terminal-shop/base_page.rb +44 -0
- data/lib/terminal-shop/client.rb +135 -0
- data/lib/terminal-shop/errors.rb +187 -0
- data/lib/terminal-shop/extern.rb +10 -0
- data/lib/terminal-shop/models/address.rb +101 -0
- data/lib/terminal-shop/models/address_create_params.rb +86 -0
- data/lib/terminal-shop/models/address_create_response.rb +26 -0
- data/lib/terminal-shop/models/address_delete_params.rb +18 -0
- data/lib/terminal-shop/models/address_delete_response.rb +25 -0
- data/lib/terminal-shop/models/address_list_params.rb +18 -0
- data/lib/terminal-shop/models/address_list_response.rb +26 -0
- data/lib/terminal-shop/models/app.rb +44 -0
- data/lib/terminal-shop/models/app_create_params.rb +18 -0
- data/lib/terminal-shop/models/app_create_response.rb +54 -0
- data/lib/terminal-shop/models/app_delete_params.rb +18 -0
- data/lib/terminal-shop/models/app_delete_response.rb +25 -0
- data/lib/terminal-shop/models/app_get_params.rb +18 -0
- data/lib/terminal-shop/models/app_get_response.rb +26 -0
- data/lib/terminal-shop/models/app_list_params.rb +18 -0
- data/lib/terminal-shop/models/app_list_response.rb +26 -0
- data/lib/terminal-shop/models/card.rb +83 -0
- data/lib/terminal-shop/models/card_collect_params.rb +18 -0
- data/lib/terminal-shop/models/card_collect_response.rb +50 -0
- data/lib/terminal-shop/models/card_create_params.rb +26 -0
- data/lib/terminal-shop/models/card_create_response.rb +26 -0
- data/lib/terminal-shop/models/card_delete_params.rb +18 -0
- data/lib/terminal-shop/models/card_delete_response.rb +25 -0
- data/lib/terminal-shop/models/card_list_params.rb +18 -0
- data/lib/terminal-shop/models/card_list_response.rb +26 -0
- data/lib/terminal-shop/models/cart.rb +200 -0
- data/lib/terminal-shop/models/cart_convert_params.rb +18 -0
- data/lib/terminal-shop/models/cart_convert_response.rb +26 -0
- data/lib/terminal-shop/models/cart_get_params.rb +18 -0
- data/lib/terminal-shop/models/cart_get_response.rb +26 -0
- data/lib/terminal-shop/models/cart_set_address_params.rb +25 -0
- data/lib/terminal-shop/models/cart_set_address_response.rb +25 -0
- data/lib/terminal-shop/models/cart_set_card_params.rb +25 -0
- data/lib/terminal-shop/models/cart_set_card_response.rb +25 -0
- data/lib/terminal-shop/models/cart_set_item_params.rb +32 -0
- data/lib/terminal-shop/models/cart_set_item_response.rb +26 -0
- data/lib/terminal-shop/models/email_create_params.rb +25 -0
- data/lib/terminal-shop/models/email_create_response.rb +25 -0
- data/lib/terminal-shop/models/order.rb +303 -0
- data/lib/terminal-shop/models/order_get_params.rb +18 -0
- data/lib/terminal-shop/models/order_get_response.rb +26 -0
- data/lib/terminal-shop/models/order_list_params.rb +18 -0
- data/lib/terminal-shop/models/order_list_response.rb +26 -0
- data/lib/terminal-shop/models/product.rb +141 -0
- data/lib/terminal-shop/models/product_list_params.rb +18 -0
- data/lib/terminal-shop/models/product_list_response.rb +26 -0
- data/lib/terminal-shop/models/product_variant.rb +44 -0
- data/lib/terminal-shop/models/profile.rb +83 -0
- data/lib/terminal-shop/models/profile_me_params.rb +18 -0
- data/lib/terminal-shop/models/profile_me_response.rb +26 -0
- data/lib/terminal-shop/models/profile_update_params.rb +32 -0
- data/lib/terminal-shop/models/profile_update_response.rb +26 -0
- data/lib/terminal-shop/models/subscription.rb +113 -0
- data/lib/terminal-shop/models/subscription_create_params.rb +18 -0
- data/lib/terminal-shop/models/subscription_create_response.rb +25 -0
- data/lib/terminal-shop/models/subscription_delete_params.rb +18 -0
- data/lib/terminal-shop/models/subscription_delete_response.rb +25 -0
- data/lib/terminal-shop/models/subscription_list_params.rb +18 -0
- data/lib/terminal-shop/models/subscription_list_response.rb +26 -0
- data/lib/terminal-shop/models/token.rb +68 -0
- data/lib/terminal-shop/models/token_create_params.rb +18 -0
- data/lib/terminal-shop/models/token_create_response.rb +55 -0
- data/lib/terminal-shop/models/token_delete_params.rb +18 -0
- data/lib/terminal-shop/models/token_delete_response.rb +25 -0
- data/lib/terminal-shop/models/token_get_params.rb +18 -0
- data/lib/terminal-shop/models/token_get_response.rb +27 -0
- data/lib/terminal-shop/models/token_list_params.rb +18 -0
- data/lib/terminal-shop/models/token_list_response.rb +26 -0
- data/lib/terminal-shop/models/view_init_params.rb +18 -0
- data/lib/terminal-shop/models/view_init_response.rb +103 -0
- data/lib/terminal-shop/pooled_net_requester.rb +94 -0
- data/lib/terminal-shop/request_options.rb +115 -0
- data/lib/terminal-shop/resources/address.rb +84 -0
- data/lib/terminal-shop/resources/app.rb +93 -0
- data/lib/terminal-shop/resources/card.rb +89 -0
- data/lib/terminal-shop/resources/cart.rb +112 -0
- data/lib/terminal-shop/resources/email.rb +34 -0
- data/lib/terminal-shop/resources/order.rb +49 -0
- data/lib/terminal-shop/resources/product.rb +30 -0
- data/lib/terminal-shop/resources/profile.rb +53 -0
- data/lib/terminal-shop/resources/subscription.rb +82 -0
- data/lib/terminal-shop/resources/token.rb +85 -0
- data/lib/terminal-shop/resources/view.rb +31 -0
- data/lib/terminal-shop/util.rb +460 -0
- data/lib/terminal-shop/version.rb +5 -0
- data/lib/terminal-shop.rb +110 -0
- data/manifest.yaml +12 -0
- data/rbi/lib/terminal-shop/base_client.rbi +145 -0
- data/rbi/lib/terminal-shop/base_model.rbi +514 -0
- data/rbi/lib/terminal-shop/base_page.rbi +38 -0
- data/rbi/lib/terminal-shop/client.rbi +80 -0
- data/rbi/lib/terminal-shop/errors.rbi +133 -0
- data/rbi/lib/terminal-shop/extern.rbi +7 -0
- data/rbi/lib/terminal-shop/models/address.rbi +77 -0
- data/rbi/lib/terminal-shop/models/address_create_params.rbi +87 -0
- data/rbi/lib/terminal-shop/models/address_create_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/address_delete_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/address_delete_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/address_list_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/address_list_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/app.rbi +24 -0
- data/rbi/lib/terminal-shop/models/app_create_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/app_create_response.rbi +34 -0
- data/rbi/lib/terminal-shop/models/app_delete_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/app_delete_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/app_get_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/app_get_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/app_list_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/app_list_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/card.rbi +59 -0
- data/rbi/lib/terminal-shop/models/card_collect_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/card_collect_response.rbi +31 -0
- data/rbi/lib/terminal-shop/models/card_create_params.rbi +26 -0
- data/rbi/lib/terminal-shop/models/card_create_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/card_delete_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/card_delete_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/card_list_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/card_list_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/cart.rbi +127 -0
- data/rbi/lib/terminal-shop/models/cart_convert_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/cart_convert_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/cart_get_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/cart_get_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/cart_set_address_params.rbi +26 -0
- data/rbi/lib/terminal-shop/models/cart_set_address_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/cart_set_card_params.rbi +26 -0
- data/rbi/lib/terminal-shop/models/cart_set_card_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/cart_set_item_params.rbi +38 -0
- data/rbi/lib/terminal-shop/models/cart_set_item_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/email_create_params.rbi +26 -0
- data/rbi/lib/terminal-shop/models/email_create_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/order.rbi +216 -0
- data/rbi/lib/terminal-shop/models/order_get_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/order_get_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/order_list_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/order_list_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/product.rbi +94 -0
- data/rbi/lib/terminal-shop/models/product_list_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/product_list_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/product_variant.rbi +24 -0
- data/rbi/lib/terminal-shop/models/profile.rbi +61 -0
- data/rbi/lib/terminal-shop/models/profile_me_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/profile_me_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/profile_update_params.rbi +38 -0
- data/rbi/lib/terminal-shop/models/profile_update_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/subscription.rbi +75 -0
- data/rbi/lib/terminal-shop/models/subscription_create_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/subscription_create_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/subscription_delete_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/subscription_delete_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/subscription_list_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/subscription_list_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/token.rbi +37 -0
- data/rbi/lib/terminal-shop/models/token_create_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/token_create_response.rbi +34 -0
- data/rbi/lib/terminal-shop/models/token_delete_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/token_delete_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/token_get_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/token_get_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/token_list_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/token_list_response.rbi +18 -0
- data/rbi/lib/terminal-shop/models/view_init_params.rbi +18 -0
- data/rbi/lib/terminal-shop/models/view_init_response.rbi +91 -0
- data/rbi/lib/terminal-shop/request_options.rbi +40 -0
- data/rbi/lib/terminal-shop/resources/address.rbi +60 -0
- data/rbi/lib/terminal-shop/resources/app.rbi +54 -0
- data/rbi/lib/terminal-shop/resources/card.rbi +57 -0
- data/rbi/lib/terminal-shop/resources/cart.rbi +67 -0
- data/rbi/lib/terminal-shop/resources/email.rbi +20 -0
- data/rbi/lib/terminal-shop/resources/order.rbi +34 -0
- data/rbi/lib/terminal-shop/resources/product.rbi +25 -0
- data/rbi/lib/terminal-shop/resources/profile.rbi +35 -0
- data/rbi/lib/terminal-shop/resources/subscription.rbi +58 -0
- data/rbi/lib/terminal-shop/resources/token.rbi +57 -0
- data/rbi/lib/terminal-shop/resources/view.rbi +25 -0
- data/rbi/lib/terminal-shop/util.rbi +128 -0
- data/rbi/lib/terminal-shop/version.rbi +5 -0
- data/sig/terminal-shop/base_client.rbs +100 -0
- data/sig/terminal-shop/base_model.rbs +246 -0
- data/sig/terminal-shop/base_page.rbs +20 -0
- data/sig/terminal-shop/client.rbs +52 -0
- data/sig/terminal-shop/errors.rbs +98 -0
- data/sig/terminal-shop/extern.rbs +4 -0
- data/sig/terminal-shop/models/address.rbs +60 -0
- data/sig/terminal-shop/models/address_create_params.rbs +62 -0
- data/sig/terminal-shop/models/address_create_response.rbs +18 -0
- data/sig/terminal-shop/models/address_delete_params.rbs +19 -0
- data/sig/terminal-shop/models/address_delete_response.rbs +18 -0
- data/sig/terminal-shop/models/address_list_params.rbs +19 -0
- data/sig/terminal-shop/models/address_list_response.rbs +19 -0
- data/sig/terminal-shop/models/app.rbs +21 -0
- data/sig/terminal-shop/models/app_create_params.rbs +19 -0
- data/sig/terminal-shop/models/app_create_response.rbs +36 -0
- data/sig/terminal-shop/models/app_delete_params.rbs +19 -0
- data/sig/terminal-shop/models/app_delete_response.rbs +18 -0
- data/sig/terminal-shop/models/app_get_params.rbs +18 -0
- data/sig/terminal-shop/models/app_get_response.rbs +17 -0
- data/sig/terminal-shop/models/app_list_params.rbs +18 -0
- data/sig/terminal-shop/models/app_list_response.rbs +18 -0
- data/sig/terminal-shop/models/card.rbs +51 -0
- data/sig/terminal-shop/models/card_collect_params.rbs +19 -0
- data/sig/terminal-shop/models/card_collect_response.rbs +34 -0
- data/sig/terminal-shop/models/card_create_params.rbs +22 -0
- data/sig/terminal-shop/models/card_create_response.rbs +18 -0
- data/sig/terminal-shop/models/card_delete_params.rbs +19 -0
- data/sig/terminal-shop/models/card_delete_response.rbs +18 -0
- data/sig/terminal-shop/models/card_list_params.rbs +18 -0
- data/sig/terminal-shop/models/card_list_response.rbs +18 -0
- data/sig/terminal-shop/models/cart.rbs +119 -0
- data/sig/terminal-shop/models/cart_convert_params.rbs +19 -0
- data/sig/terminal-shop/models/cart_convert_response.rbs +18 -0
- data/sig/terminal-shop/models/cart_get_params.rbs +18 -0
- data/sig/terminal-shop/models/cart_get_response.rbs +18 -0
- data/sig/terminal-shop/models/cart_set_address_params.rbs +25 -0
- data/sig/terminal-shop/models/cart_set_address_response.rbs +18 -0
- data/sig/terminal-shop/models/cart_set_card_params.rbs +22 -0
- data/sig/terminal-shop/models/cart_set_card_response.rbs +18 -0
- data/sig/terminal-shop/models/cart_set_item_params.rbs +29 -0
- data/sig/terminal-shop/models/cart_set_item_response.rbs +18 -0
- data/sig/terminal-shop/models/email_create_params.rbs +22 -0
- data/sig/terminal-shop/models/email_create_response.rbs +18 -0
- data/sig/terminal-shop/models/order.rbs +179 -0
- data/sig/terminal-shop/models/order_get_params.rbs +18 -0
- data/sig/terminal-shop/models/order_get_response.rbs +18 -0
- data/sig/terminal-shop/models/order_list_params.rbs +19 -0
- data/sig/terminal-shop/models/order_list_response.rbs +18 -0
- data/sig/terminal-shop/models/product.rbs +76 -0
- data/sig/terminal-shop/models/product_list_params.rbs +19 -0
- data/sig/terminal-shop/models/product_list_response.rbs +19 -0
- data/sig/terminal-shop/models/product_variant.rbs +21 -0
- data/sig/terminal-shop/models/profile.rbs +53 -0
- data/sig/terminal-shop/models/profile_me_params.rbs +19 -0
- data/sig/terminal-shop/models/profile_me_response.rbs +18 -0
- data/sig/terminal-shop/models/profile_update_params.rbs +28 -0
- data/sig/terminal-shop/models/profile_update_response.rbs +18 -0
- data/sig/terminal-shop/models/subscription.rbs +60 -0
- data/sig/terminal-shop/models/subscription_create_params.rbs +19 -0
- data/sig/terminal-shop/models/subscription_create_response.rbs +18 -0
- data/sig/terminal-shop/models/subscription_delete_params.rbs +19 -0
- data/sig/terminal-shop/models/subscription_delete_response.rbs +18 -0
- data/sig/terminal-shop/models/subscription_list_params.rbs +19 -0
- data/sig/terminal-shop/models/subscription_list_response.rbs +19 -0
- data/sig/terminal-shop/models/token.rbs +40 -0
- data/sig/terminal-shop/models/token_create_params.rbs +19 -0
- data/sig/terminal-shop/models/token_create_response.rbs +36 -0
- data/sig/terminal-shop/models/token_delete_params.rbs +19 -0
- data/sig/terminal-shop/models/token_delete_response.rbs +18 -0
- data/sig/terminal-shop/models/token_get_params.rbs +18 -0
- data/sig/terminal-shop/models/token_get_response.rbs +18 -0
- data/sig/terminal-shop/models/token_list_params.rbs +19 -0
- data/sig/terminal-shop/models/token_list_response.rbs +18 -0
- data/sig/terminal-shop/models/view_init_params.rbs +18 -0
- data/sig/terminal-shop/models/view_init_response.rbs +71 -0
- data/sig/terminal-shop/request_options.rbs +42 -0
- data/sig/terminal-shop/resources/address.rbs +41 -0
- data/sig/terminal-shop/resources/app.rbs +46 -0
- data/sig/terminal-shop/resources/card.rbs +42 -0
- data/sig/terminal-shop/resources/cart.rbs +51 -0
- data/sig/terminal-shop/resources/email.rbs +16 -0
- data/sig/terminal-shop/resources/order.rbs +25 -0
- data/sig/terminal-shop/resources/product.rbs +15 -0
- data/sig/terminal-shop/resources/profile.rbs +25 -0
- data/sig/terminal-shop/resources/subscription.rbs +43 -0
- data/sig/terminal-shop/resources/token.rbs +43 -0
- data/sig/terminal-shop/resources/view.rbs +15 -0
- data/sig/terminal-shop/util.rbs +85 -0
- data/sig/terminal-shop/version.rbs +3 -0
- metadata +333 -0
@@ -0,0 +1,460 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TerminalShop
|
4
|
+
# rubocop:disable Metrics/ModuleLength
|
5
|
+
|
6
|
+
# @private
|
7
|
+
#
|
8
|
+
module Util
|
9
|
+
# @private
|
10
|
+
#
|
11
|
+
# @param input [Object]
|
12
|
+
#
|
13
|
+
# @return [Boolean, Object]
|
14
|
+
#
|
15
|
+
def self.primitive?(input)
|
16
|
+
case input
|
17
|
+
in true | false | Integer | Float | Symbol | String
|
18
|
+
true
|
19
|
+
else
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# @private
|
25
|
+
#
|
26
|
+
# @param input [Object]
|
27
|
+
#
|
28
|
+
# @return [Boolean, Object]
|
29
|
+
#
|
30
|
+
def self.coerce_boolean(input)
|
31
|
+
case input.is_a?(String) ? input.downcase : input
|
32
|
+
in Numeric
|
33
|
+
!input.zero?
|
34
|
+
in "true"
|
35
|
+
true
|
36
|
+
in "false"
|
37
|
+
false
|
38
|
+
else
|
39
|
+
input
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# @private
|
44
|
+
#
|
45
|
+
# @param input [Object]
|
46
|
+
#
|
47
|
+
# @raise [ArgumentError]
|
48
|
+
# @return [Boolean, nil]
|
49
|
+
#
|
50
|
+
def self.coerce_boolean!(input)
|
51
|
+
case (coerced = coerce_boolean(input))
|
52
|
+
in true | false | nil
|
53
|
+
coerced
|
54
|
+
else
|
55
|
+
raise ArgumentError.new("Unable to coerce #{input.inspect} into boolean value")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# @private
|
60
|
+
#
|
61
|
+
# @param input [Object]
|
62
|
+
#
|
63
|
+
# @return [Integer, Object]
|
64
|
+
#
|
65
|
+
def self.coerce_integer(input)
|
66
|
+
case input
|
67
|
+
in true
|
68
|
+
1
|
69
|
+
in false
|
70
|
+
0
|
71
|
+
else
|
72
|
+
Integer(input, exception: false) || input
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# @private
|
77
|
+
#
|
78
|
+
# @param input [Object]
|
79
|
+
#
|
80
|
+
# @return [Float, Object]
|
81
|
+
#
|
82
|
+
def self.coerce_float(input)
|
83
|
+
case input
|
84
|
+
in true
|
85
|
+
1.0
|
86
|
+
in false
|
87
|
+
0.0
|
88
|
+
else
|
89
|
+
Float(input, exception: false) || input
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# @private
|
94
|
+
#
|
95
|
+
# @param input [Object]
|
96
|
+
#
|
97
|
+
# @return [Hash{Object=>Object}, Object]
|
98
|
+
#
|
99
|
+
def self.coerce_hash(input)
|
100
|
+
case input
|
101
|
+
in NilClass | Array | Set | Enumerator
|
102
|
+
input
|
103
|
+
else
|
104
|
+
input.respond_to?(:to_h) ? input.to_h : input
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# @private
|
109
|
+
#
|
110
|
+
# @param exceptions [Array<Exception>]
|
111
|
+
# @param sentinel [Object, nil]
|
112
|
+
# @param blk [Proc, nil]
|
113
|
+
#
|
114
|
+
# @return [Object, nil]
|
115
|
+
#
|
116
|
+
def self.suppress(*exceptions, sentinel: nil, &blk)
|
117
|
+
blk.call
|
118
|
+
rescue *exceptions
|
119
|
+
sentinel
|
120
|
+
end
|
121
|
+
|
122
|
+
# Use this to indicate that a value should be explicitly removed from a data
|
123
|
+
# structure when using `TerminalShop::Util.deep_merge`.
|
124
|
+
#
|
125
|
+
# e.g. merging `{a: 1}` and `{a: OMIT}` should produce `{}`, where merging
|
126
|
+
# `{a: 1}` and `{}` would produce `{a: 1}`.
|
127
|
+
OMIT = Object.new.freeze
|
128
|
+
|
129
|
+
# @private
|
130
|
+
#
|
131
|
+
# Recursively merge one hash with another. If the values at a given key are not
|
132
|
+
# both hashes, just take the new value.
|
133
|
+
#
|
134
|
+
# @param values [Array<Object>]
|
135
|
+
#
|
136
|
+
# @param sentinel [Object, nil] the value to return if no values are provided.
|
137
|
+
#
|
138
|
+
# @param concat [Boolean] whether to merge sequences by concatenation.
|
139
|
+
#
|
140
|
+
# @return [Object]
|
141
|
+
#
|
142
|
+
def self.deep_merge(*values, sentinel: nil, concat: false)
|
143
|
+
case values
|
144
|
+
in [value, *values]
|
145
|
+
values.reduce(value) do |acc, val|
|
146
|
+
deep_merge_lr(acc, val, concat: concat)
|
147
|
+
end
|
148
|
+
else
|
149
|
+
sentinel
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# @private
|
154
|
+
#
|
155
|
+
# @param lhs [Object]
|
156
|
+
# @param rhs [Object]
|
157
|
+
# @param concat [Boolean]
|
158
|
+
#
|
159
|
+
# @return [Object]
|
160
|
+
#
|
161
|
+
private_class_method def self.deep_merge_lr(lhs, rhs, concat: false)
|
162
|
+
rhs_cleaned =
|
163
|
+
case rhs
|
164
|
+
in Hash
|
165
|
+
rhs.reject { |_, value| value == OMIT }
|
166
|
+
else
|
167
|
+
rhs
|
168
|
+
end
|
169
|
+
|
170
|
+
case [lhs, rhs_cleaned, concat]
|
171
|
+
in [Hash, Hash, _]
|
172
|
+
lhs
|
173
|
+
.reject { |key, _| rhs[key] == OMIT }
|
174
|
+
.merge(rhs_cleaned) do |_, old_val, new_val|
|
175
|
+
deep_merge_lr(old_val, new_val, concat: concat)
|
176
|
+
end
|
177
|
+
in [Array, Array, true]
|
178
|
+
lhs.concat(rhs_cleaned)
|
179
|
+
else
|
180
|
+
rhs_cleaned
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
# @private
|
185
|
+
#
|
186
|
+
# @param data [Hash{Symbol=>Object}, Array<Object>, Object]
|
187
|
+
# @param pick [Symbol, Integer, Array<Symbol, Integer>, nil]
|
188
|
+
# @param sentinel [Object, nil]
|
189
|
+
# @param blk [Proc, nil]
|
190
|
+
#
|
191
|
+
# @return [Object, nil]
|
192
|
+
#
|
193
|
+
def self.dig(data, pick, sentinel = nil, &blk)
|
194
|
+
case [data, pick, blk]
|
195
|
+
in [_, nil, nil]
|
196
|
+
data
|
197
|
+
in [Hash, Symbol, _] | [Array, Integer, _]
|
198
|
+
blk.nil? ? data.fetch(pick, sentinel) : data.fetch(pick, &blk)
|
199
|
+
in [Hash | Array, Array, _]
|
200
|
+
pick.reduce(data) do |acc, key|
|
201
|
+
case acc
|
202
|
+
in Hash if acc.key?(key)
|
203
|
+
acc.fetch(key)
|
204
|
+
in Array if key.is_a?(Integer) && key < acc.length
|
205
|
+
acc[key]
|
206
|
+
else
|
207
|
+
return blk.nil? ? sentinel : blk.call
|
208
|
+
end
|
209
|
+
end
|
210
|
+
in _
|
211
|
+
blk.nil? ? sentinel : blk.call
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
# @private
|
216
|
+
#
|
217
|
+
# @param uri [URI::Generic]
|
218
|
+
#
|
219
|
+
# @return [String]
|
220
|
+
#
|
221
|
+
def self.uri_origin(uri)
|
222
|
+
"#{uri.scheme}://#{uri.host}#{uri.port == uri.default_port ? '' : ":#{uri.port}"}"
|
223
|
+
end
|
224
|
+
|
225
|
+
# @private
|
226
|
+
#
|
227
|
+
# @param path [String, Array<String>]
|
228
|
+
#
|
229
|
+
# @return [String]
|
230
|
+
#
|
231
|
+
def self.interpolate_path(path)
|
232
|
+
case path
|
233
|
+
in String
|
234
|
+
path
|
235
|
+
in []
|
236
|
+
""
|
237
|
+
in [String, *interpolations]
|
238
|
+
encoded = interpolations.map { |v| ERB::Util.url_encode(v) }
|
239
|
+
path.first % encoded
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
# @private
|
244
|
+
#
|
245
|
+
# @param url [URI::Generic, String]
|
246
|
+
#
|
247
|
+
# @return [Hash{Symbol=>String, Integer, nil}]
|
248
|
+
#
|
249
|
+
def self.parse_uri(url)
|
250
|
+
parsed = URI::Generic.component.zip(URI.split(url)).to_h
|
251
|
+
{**parsed, query: decode_query(parsed.fetch(:query))}
|
252
|
+
end
|
253
|
+
|
254
|
+
# @private
|
255
|
+
#
|
256
|
+
# @param parsed [Hash{Symbol=>String, Integer, nil}] .
|
257
|
+
#
|
258
|
+
# @option parsed [String, nil] :scheme
|
259
|
+
#
|
260
|
+
# @option parsed [String, nil] :host
|
261
|
+
#
|
262
|
+
# @option parsed [Integer, nil] :port
|
263
|
+
#
|
264
|
+
# @option parsed [String, nil] :path
|
265
|
+
#
|
266
|
+
# @option parsed [Hash{String=>Array<String>}] :query
|
267
|
+
#
|
268
|
+
# @return [URI::Generic]
|
269
|
+
#
|
270
|
+
def self.unparse_uri(parsed)
|
271
|
+
URI::Generic.build(**parsed, query: encode_query(parsed.fetch(:query)))
|
272
|
+
end
|
273
|
+
|
274
|
+
# @private
|
275
|
+
#
|
276
|
+
# @param lhs [Hash{Symbol=>String, Integer, nil}] .
|
277
|
+
#
|
278
|
+
# @option lhs [String, nil] :scheme
|
279
|
+
#
|
280
|
+
# @option lhs [String, nil] :host
|
281
|
+
#
|
282
|
+
# @option lhs [Integer, nil] :port
|
283
|
+
#
|
284
|
+
# @option lhs [String, nil] :path
|
285
|
+
#
|
286
|
+
# @option lhs [Hash{String=>Array<String>}] :query
|
287
|
+
#
|
288
|
+
# @param rhs [Hash{Symbol=>String, Integer, nil}] .
|
289
|
+
#
|
290
|
+
# @option rhs [String, nil] :scheme
|
291
|
+
#
|
292
|
+
# @option rhs [String, nil] :host
|
293
|
+
#
|
294
|
+
# @option rhs [Integer, nil] :port
|
295
|
+
#
|
296
|
+
# @option rhs [String, nil] :path
|
297
|
+
#
|
298
|
+
# @option rhs [Hash{String=>Array<String>}] :query
|
299
|
+
#
|
300
|
+
# @option rhs [Hash{String=>Array<String>}] :extra_query
|
301
|
+
#
|
302
|
+
# @return [URI::Generic]
|
303
|
+
#
|
304
|
+
def self.join_parsed_uri(lhs, rhs)
|
305
|
+
base_path, base_query = lhs.fetch_values(:path, :query)
|
306
|
+
slashed = base_path.end_with?("/") ? base_path : "#{base_path}/"
|
307
|
+
|
308
|
+
parsed_path, parsed_query = parse_uri(rhs.fetch(:path)).fetch_values(:path, :query)
|
309
|
+
override = URI::Generic.build(**rhs.slice(:scheme, :host, :port), path: parsed_path)
|
310
|
+
|
311
|
+
joined = URI.join(URI::Generic.build(lhs.except(:path, :query)), slashed, override)
|
312
|
+
query = deep_merge(
|
313
|
+
joined.path == base_path ? base_query : {},
|
314
|
+
parsed_query,
|
315
|
+
*rhs.values_at(:query, :extra_query).compact,
|
316
|
+
concat: true
|
317
|
+
)
|
318
|
+
|
319
|
+
joined.query = encode_query(query)
|
320
|
+
joined
|
321
|
+
end
|
322
|
+
|
323
|
+
# @private
|
324
|
+
#
|
325
|
+
# @param query [String, nil]
|
326
|
+
#
|
327
|
+
# @return [Hash{String=>Array<String>}]
|
328
|
+
#
|
329
|
+
def self.decode_query(query)
|
330
|
+
CGI.parse(query.to_s)
|
331
|
+
end
|
332
|
+
|
333
|
+
# @private
|
334
|
+
#
|
335
|
+
# @param query [Hash{String=>Array<String>, String, nil}]
|
336
|
+
#
|
337
|
+
# @return [String, nil]
|
338
|
+
#
|
339
|
+
def self.encode_query(query)
|
340
|
+
query.empty? ? nil : URI.encode_www_form(query)
|
341
|
+
end
|
342
|
+
|
343
|
+
# @private
|
344
|
+
#
|
345
|
+
# @param headers [Array<Hash{String=>String, Integer, nil}>]
|
346
|
+
#
|
347
|
+
# @return [Hash{String=>String}]
|
348
|
+
#
|
349
|
+
def self.normalized_headers(*headers)
|
350
|
+
{}.merge(*headers.compact).to_h do |key, val|
|
351
|
+
[key.downcase, val&.to_s&.strip]
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
# @private
|
356
|
+
#
|
357
|
+
# @param headers [Hash{String=>String}]
|
358
|
+
# @param body [Object]
|
359
|
+
#
|
360
|
+
# @return [Object]
|
361
|
+
#
|
362
|
+
def self.encode_content(headers, body)
|
363
|
+
content_type = headers["content-type"]
|
364
|
+
case [content_type, body]
|
365
|
+
in ["application/json", Hash | Array]
|
366
|
+
[headers, JSON.fast_generate(body)]
|
367
|
+
in [%r{^multipart/form-data}, Hash | IO | StringIO]
|
368
|
+
boundary = SecureRandom.urlsafe_base64(60)
|
369
|
+
strio = StringIO.new.tap do |io|
|
370
|
+
case body
|
371
|
+
in Hash
|
372
|
+
body.each do |key, val|
|
373
|
+
case val
|
374
|
+
in Array if val.all? { primitive?(_1) }
|
375
|
+
val.each do |v|
|
376
|
+
encode_multipart_formdata(io, boundary: boundary, key: key, val: v)
|
377
|
+
end
|
378
|
+
else
|
379
|
+
encode_multipart_formdata(io, boundary: boundary, key: key, val: val)
|
380
|
+
end
|
381
|
+
end
|
382
|
+
else
|
383
|
+
encode_multipart_formdata(io, boundary: boundary, key: nil, val: body)
|
384
|
+
end
|
385
|
+
io << "--#{boundary}--\r\n"
|
386
|
+
io.rewind
|
387
|
+
end
|
388
|
+
headers = {
|
389
|
+
**headers,
|
390
|
+
"content-type" => "#{content_type}; boundary=#{boundary}",
|
391
|
+
"transfer-encoding" => "chunked"
|
392
|
+
}
|
393
|
+
[headers, strio]
|
394
|
+
else
|
395
|
+
[headers, body]
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
# @private
|
400
|
+
#
|
401
|
+
# @param response [Net::HTTPResponse]
|
402
|
+
# @param suppress_error [Boolean]
|
403
|
+
#
|
404
|
+
# @raise [JSON::ParserError]
|
405
|
+
# @return [Object]
|
406
|
+
#
|
407
|
+
def self.decode_content(response, suppress_error: false)
|
408
|
+
case response.content_type
|
409
|
+
in "application/json"
|
410
|
+
begin
|
411
|
+
JSON.parse(response.body, symbolize_names: true)
|
412
|
+
rescue JSON::ParserError => e
|
413
|
+
raise e unless suppress_error
|
414
|
+
response.body
|
415
|
+
end
|
416
|
+
else
|
417
|
+
# TODO: parsing other response types
|
418
|
+
response.body
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
# @private
|
423
|
+
#
|
424
|
+
# @param io [StringIO]
|
425
|
+
# @param boundary [String]
|
426
|
+
# @param key [Symbol, String]
|
427
|
+
# @param val [Object]
|
428
|
+
#
|
429
|
+
private_class_method def self.encode_multipart_formdata(io, boundary:, key:, val:)
|
430
|
+
io << "--#{boundary}\r\n"
|
431
|
+
io << "Content-Disposition: form-data"
|
432
|
+
unless key.nil?
|
433
|
+
name = ERB::Util.url_encode(key.to_s)
|
434
|
+
io << "; name=\"#{name}\""
|
435
|
+
end
|
436
|
+
if val.is_a?(IO)
|
437
|
+
filename = ERB::Util.url_encode(File.basename(val.to_path))
|
438
|
+
io << "; filename=\"#{filename}\""
|
439
|
+
end
|
440
|
+
io << "\r\n"
|
441
|
+
case val
|
442
|
+
in IO | StringIO
|
443
|
+
io << "Content-Type: application/octet-stream\r\n\r\n"
|
444
|
+
IO.copy_stream(val, io)
|
445
|
+
in String
|
446
|
+
io << "Content-Type: application/octet-stream\r\n\r\n"
|
447
|
+
io << val.to_s
|
448
|
+
in true | false | Integer | Float | Symbol
|
449
|
+
io << "Content-Type: text/plain\r\n\r\n"
|
450
|
+
io << val.to_s
|
451
|
+
else
|
452
|
+
io << "Content-Type: application/json\r\n\r\n"
|
453
|
+
io << JSON.fast_generate(val)
|
454
|
+
end
|
455
|
+
io << "\r\n"
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
# rubocop:enable Metrics/ModuleLength
|
460
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Standard libraries.
|
4
|
+
require "cgi"
|
5
|
+
require "date"
|
6
|
+
require "erb"
|
7
|
+
require "etc"
|
8
|
+
require "json"
|
9
|
+
require "net/http"
|
10
|
+
require "securerandom"
|
11
|
+
require "set"
|
12
|
+
require "stringio"
|
13
|
+
require "time"
|
14
|
+
require "uri"
|
15
|
+
|
16
|
+
# Gems.
|
17
|
+
require "connection_pool"
|
18
|
+
|
19
|
+
# Package files.
|
20
|
+
require_relative "terminal-shop/pooled_net_requester"
|
21
|
+
require_relative "terminal-shop/version"
|
22
|
+
require_relative "terminal-shop/util"
|
23
|
+
require_relative "terminal-shop/extern"
|
24
|
+
require_relative "terminal-shop/base_model"
|
25
|
+
require_relative "terminal-shop/base_page"
|
26
|
+
require_relative "terminal-shop/request_options"
|
27
|
+
require_relative "terminal-shop/base_client"
|
28
|
+
require_relative "terminal-shop/errors"
|
29
|
+
require_relative "terminal-shop/models/product"
|
30
|
+
require_relative "terminal-shop/models/product_variant"
|
31
|
+
require_relative "terminal-shop/models/product_list_response"
|
32
|
+
require_relative "terminal-shop/models/profile"
|
33
|
+
require_relative "terminal-shop/models/profile_update_response"
|
34
|
+
require_relative "terminal-shop/models/profile_me_response"
|
35
|
+
require_relative "terminal-shop/models/address"
|
36
|
+
require_relative "terminal-shop/models/address_create_response"
|
37
|
+
require_relative "terminal-shop/models/address_list_response"
|
38
|
+
require_relative "terminal-shop/models/address_delete_response"
|
39
|
+
require_relative "terminal-shop/models/card"
|
40
|
+
require_relative "terminal-shop/models/card_create_response"
|
41
|
+
require_relative "terminal-shop/models/card_list_response"
|
42
|
+
require_relative "terminal-shop/models/card_delete_response"
|
43
|
+
require_relative "terminal-shop/models/card_collect_response"
|
44
|
+
require_relative "terminal-shop/models/cart"
|
45
|
+
require_relative "terminal-shop/models/cart_convert_response"
|
46
|
+
require_relative "terminal-shop/models/cart_get_response"
|
47
|
+
require_relative "terminal-shop/models/cart_set_address_response"
|
48
|
+
require_relative "terminal-shop/models/cart_set_card_response"
|
49
|
+
require_relative "terminal-shop/models/cart_set_item_response"
|
50
|
+
require_relative "terminal-shop/models/order"
|
51
|
+
require_relative "terminal-shop/models/order_list_response"
|
52
|
+
require_relative "terminal-shop/models/order_get_response"
|
53
|
+
require_relative "terminal-shop/models/subscription"
|
54
|
+
require_relative "terminal-shop/models/subscription_create_response"
|
55
|
+
require_relative "terminal-shop/models/subscription_list_response"
|
56
|
+
require_relative "terminal-shop/models/subscription_delete_response"
|
57
|
+
require_relative "terminal-shop/models/token"
|
58
|
+
require_relative "terminal-shop/models/token_create_response"
|
59
|
+
require_relative "terminal-shop/models/token_list_response"
|
60
|
+
require_relative "terminal-shop/models/token_delete_response"
|
61
|
+
require_relative "terminal-shop/models/token_get_response"
|
62
|
+
require_relative "terminal-shop/models/app"
|
63
|
+
require_relative "terminal-shop/models/app_create_response"
|
64
|
+
require_relative "terminal-shop/models/app_list_response"
|
65
|
+
require_relative "terminal-shop/models/app_delete_response"
|
66
|
+
require_relative "terminal-shop/models/app_get_response"
|
67
|
+
require_relative "terminal-shop/models/email_create_response"
|
68
|
+
require_relative "terminal-shop/models/view_init_response"
|
69
|
+
require_relative "terminal-shop/models/product_list_params"
|
70
|
+
require_relative "terminal-shop/models/profile_update_params"
|
71
|
+
require_relative "terminal-shop/models/profile_me_params"
|
72
|
+
require_relative "terminal-shop/models/address_create_params"
|
73
|
+
require_relative "terminal-shop/models/address_list_params"
|
74
|
+
require_relative "terminal-shop/models/address_delete_params"
|
75
|
+
require_relative "terminal-shop/models/card_create_params"
|
76
|
+
require_relative "terminal-shop/models/card_list_params"
|
77
|
+
require_relative "terminal-shop/models/card_delete_params"
|
78
|
+
require_relative "terminal-shop/models/card_collect_params"
|
79
|
+
require_relative "terminal-shop/models/cart_convert_params"
|
80
|
+
require_relative "terminal-shop/models/cart_get_params"
|
81
|
+
require_relative "terminal-shop/models/cart_set_address_params"
|
82
|
+
require_relative "terminal-shop/models/cart_set_card_params"
|
83
|
+
require_relative "terminal-shop/models/cart_set_item_params"
|
84
|
+
require_relative "terminal-shop/models/order_list_params"
|
85
|
+
require_relative "terminal-shop/models/order_get_params"
|
86
|
+
require_relative "terminal-shop/models/subscription_create_params"
|
87
|
+
require_relative "terminal-shop/models/subscription_list_params"
|
88
|
+
require_relative "terminal-shop/models/subscription_delete_params"
|
89
|
+
require_relative "terminal-shop/models/token_create_params"
|
90
|
+
require_relative "terminal-shop/models/token_list_params"
|
91
|
+
require_relative "terminal-shop/models/token_delete_params"
|
92
|
+
require_relative "terminal-shop/models/token_get_params"
|
93
|
+
require_relative "terminal-shop/models/app_create_params"
|
94
|
+
require_relative "terminal-shop/models/app_list_params"
|
95
|
+
require_relative "terminal-shop/models/app_delete_params"
|
96
|
+
require_relative "terminal-shop/models/app_get_params"
|
97
|
+
require_relative "terminal-shop/models/email_create_params"
|
98
|
+
require_relative "terminal-shop/models/view_init_params"
|
99
|
+
require_relative "terminal-shop/client"
|
100
|
+
require_relative "terminal-shop/resources/product"
|
101
|
+
require_relative "terminal-shop/resources/profile"
|
102
|
+
require_relative "terminal-shop/resources/address"
|
103
|
+
require_relative "terminal-shop/resources/card"
|
104
|
+
require_relative "terminal-shop/resources/cart"
|
105
|
+
require_relative "terminal-shop/resources/order"
|
106
|
+
require_relative "terminal-shop/resources/subscription"
|
107
|
+
require_relative "terminal-shop/resources/token"
|
108
|
+
require_relative "terminal-shop/resources/app"
|
109
|
+
require_relative "terminal-shop/resources/email"
|
110
|
+
require_relative "terminal-shop/resources/view"
|