leal 0.0.9

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 (127) hide show
  1. checksums.yaml +7 -0
  2. data/.fern/metadata.json +10 -0
  3. data/.fernignore +1 -0
  4. data/.rubocop.yml +103 -0
  5. data/CONTRIBUTING.md +120 -0
  6. data/LICENSE +21 -0
  7. data/README.md +185 -0
  8. data/Rakefile +20 -0
  9. data/custom.gemspec.rb +16 -0
  10. data/lib/leal/cards/client.rb +193 -0
  11. data/lib/leal/cards/types/create_cards_request.rb +13 -0
  12. data/lib/leal/cards/types/create_cards_request_card.rb +33 -0
  13. data/lib/leal/cards/types/create_cards_response.rb +45 -0
  14. data/lib/leal/cards/types/get_cards_request.rb +13 -0
  15. data/lib/leal/cards/types/get_cards_response.rb +45 -0
  16. data/lib/leal/cards/types/list_cards_request.rb +13 -0
  17. data/lib/leal/cards/types/list_cards_response_item.rb +45 -0
  18. data/lib/leal/cards/types/update_cards_request.rb +15 -0
  19. data/lib/leal/cards/types/update_cards_request_card.rb +33 -0
  20. data/lib/leal/cards/types/update_cards_response.rb +45 -0
  21. data/lib/leal/client.rb +62 -0
  22. data/lib/leal/customer_cards/client.rb +203 -0
  23. data/lib/leal/customer_cards/types/get_customer_cards_request.rb +15 -0
  24. data/lib/leal/customer_cards/types/get_customer_cards_response.rb +43 -0
  25. data/lib/leal/customer_cards/types/list_customer_cards_request.rb +13 -0
  26. data/lib/leal/customer_cards/types/list_customer_cards_response_item.rb +37 -0
  27. data/lib/leal/customer_cards/types/redeem_customer_cards_request.rb +17 -0
  28. data/lib/leal/customer_cards/types/redeem_customer_cards_response.rb +13 -0
  29. data/lib/leal/customer_cards/types/redeem_customer_cards_response_redemption.rb +21 -0
  30. data/lib/leal/customer_cards/types/stamp_customer_cards_request.rb +19 -0
  31. data/lib/leal/customer_cards/types/stamp_customer_cards_response.rb +43 -0
  32. data/lib/leal/customers/client.rb +217 -0
  33. data/lib/leal/customers/types/create_customers_request.rb +17 -0
  34. data/lib/leal/customers/types/create_customers_request_customer.rb +23 -0
  35. data/lib/leal/customers/types/create_customers_response.rb +35 -0
  36. data/lib/leal/customers/types/get_customers_request.rb +13 -0
  37. data/lib/leal/customers/types/get_customers_response.rb +35 -0
  38. data/lib/leal/customers/types/list_customers_request.rb +21 -0
  39. data/lib/leal/customers/types/list_customers_response.rb +13 -0
  40. data/lib/leal/customers/types/list_customers_response_pagination.rb +17 -0
  41. data/lib/leal/customers/types/update_customers_request.rb +15 -0
  42. data/lib/leal/customers/types/update_customers_request_customer.rb +23 -0
  43. data/lib/leal/customers/types/update_customers_response.rb +35 -0
  44. data/lib/leal/environment.rb +7 -0
  45. data/lib/leal/errors/api_error.rb +8 -0
  46. data/lib/leal/errors/client_error.rb +17 -0
  47. data/lib/leal/errors/redirect_error.rb +8 -0
  48. data/lib/leal/errors/response_error.rb +42 -0
  49. data/lib/leal/errors/server_error.rb +11 -0
  50. data/lib/leal/errors/timeout_error.rb +8 -0
  51. data/lib/leal/internal/errors/constraint_error.rb +10 -0
  52. data/lib/leal/internal/errors/type_error.rb +10 -0
  53. data/lib/leal/internal/http/base_request.rb +51 -0
  54. data/lib/leal/internal/http/raw_client.rb +265 -0
  55. data/lib/leal/internal/iterators/cursor_item_iterator.rb +28 -0
  56. data/lib/leal/internal/iterators/cursor_page_iterator.rb +63 -0
  57. data/lib/leal/internal/iterators/item_iterator.rb +65 -0
  58. data/lib/leal/internal/iterators/offset_item_iterator.rb +30 -0
  59. data/lib/leal/internal/iterators/offset_page_iterator.rb +103 -0
  60. data/lib/leal/internal/json/request.rb +41 -0
  61. data/lib/leal/internal/json/serializable.rb +25 -0
  62. data/lib/leal/internal/multipart/multipart_encoder.rb +141 -0
  63. data/lib/leal/internal/multipart/multipart_form_data.rb +78 -0
  64. data/lib/leal/internal/multipart/multipart_form_data_part.rb +51 -0
  65. data/lib/leal/internal/multipart/multipart_request.rb +40 -0
  66. data/lib/leal/internal/types/array.rb +47 -0
  67. data/lib/leal/internal/types/boolean.rb +34 -0
  68. data/lib/leal/internal/types/enum.rb +56 -0
  69. data/lib/leal/internal/types/hash.rb +36 -0
  70. data/lib/leal/internal/types/model/field.rb +38 -0
  71. data/lib/leal/internal/types/model.rb +208 -0
  72. data/lib/leal/internal/types/type.rb +35 -0
  73. data/lib/leal/internal/types/union.rb +161 -0
  74. data/lib/leal/internal/types/unknown.rb +15 -0
  75. data/lib/leal/internal/types/utils.rb +116 -0
  76. data/lib/leal/locations/client.rb +225 -0
  77. data/lib/leal/locations/types/create_locations_request.rb +13 -0
  78. data/lib/leal/locations/types/create_locations_request_location.rb +13 -0
  79. data/lib/leal/locations/types/create_locations_response.rb +25 -0
  80. data/lib/leal/locations/types/delete_locations_request.rb +13 -0
  81. data/lib/leal/locations/types/get_locations_request.rb +13 -0
  82. data/lib/leal/locations/types/get_locations_response.rb +25 -0
  83. data/lib/leal/locations/types/list_locations_request.rb +11 -0
  84. data/lib/leal/locations/types/list_locations_response_item.rb +25 -0
  85. data/lib/leal/locations/types/update_locations_request.rb +15 -0
  86. data/lib/leal/locations/types/update_locations_request_location.rb +13 -0
  87. data/lib/leal/locations/types/update_locations_response.rb +25 -0
  88. data/lib/leal/posters/client.rb +232 -0
  89. data/lib/leal/posters/types/create_posters_request.rb +13 -0
  90. data/lib/leal/posters/types/create_posters_request_poster.rb +23 -0
  91. data/lib/leal/posters/types/create_posters_response.rb +37 -0
  92. data/lib/leal/posters/types/delete_posters_request.rb +13 -0
  93. data/lib/leal/posters/types/get_posters_request.rb +13 -0
  94. data/lib/leal/posters/types/get_posters_response.rb +37 -0
  95. data/lib/leal/posters/types/list_posters_request.rb +15 -0
  96. data/lib/leal/posters/types/list_posters_response_item.rb +37 -0
  97. data/lib/leal/posters/types/update_posters_request.rb +15 -0
  98. data/lib/leal/posters/types/update_posters_request_poster.rb +21 -0
  99. data/lib/leal/posters/types/update_posters_response.rb +37 -0
  100. data/lib/leal/rewards/client.rb +233 -0
  101. data/lib/leal/rewards/types/create_rewards_request.rb +13 -0
  102. data/lib/leal/rewards/types/create_rewards_request_reward.rb +21 -0
  103. data/lib/leal/rewards/types/create_rewards_response.rb +29 -0
  104. data/lib/leal/rewards/types/delete_rewards_request.rb +13 -0
  105. data/lib/leal/rewards/types/get_rewards_request.rb +13 -0
  106. data/lib/leal/rewards/types/get_rewards_response.rb +29 -0
  107. data/lib/leal/rewards/types/list_rewards_request.rb +15 -0
  108. data/lib/leal/rewards/types/list_rewards_response_item.rb +29 -0
  109. data/lib/leal/rewards/types/update_rewards_request.rb +15 -0
  110. data/lib/leal/rewards/types/update_rewards_request_reward.rb +19 -0
  111. data/lib/leal/rewards/types/update_rewards_response.rb +29 -0
  112. data/lib/leal/status/client.rb +53 -0
  113. data/lib/leal/status/types/check_status_response.rb +23 -0
  114. data/lib/leal/status/types/check_status_response_rate_limit.rb +15 -0
  115. data/lib/leal/stores/client.rb +130 -0
  116. data/lib/leal/stores/types/get_stores_request.rb +11 -0
  117. data/lib/leal/stores/types/get_stores_response.rb +31 -0
  118. data/lib/leal/stores/types/list_stores_response_item.rb +31 -0
  119. data/lib/leal/stores/types/update_stores_request.rb +13 -0
  120. data/lib/leal/stores/types/update_stores_request_account.rb +13 -0
  121. data/lib/leal/stores/types/update_stores_response.rb +31 -0
  122. data/lib/leal/types/error.rb +13 -0
  123. data/lib/leal/types/error_errors.rb +14 -0
  124. data/lib/leal/version.rb +5 -0
  125. data/lib/leal.rb +120 -0
  126. data/reference.md +2414 -0
  127. metadata +168 -0
@@ -0,0 +1,225 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leal
4
+ module Locations
5
+ class Client
6
+ # @param client [Leal::Internal::Http::RawClient]
7
+ #
8
+ # @return [void]
9
+ def initialize(client:)
10
+ @client = client
11
+ end
12
+
13
+ # Returns every physical location belonging to the specified store.
14
+ #
15
+ # @param request_options [Hash]
16
+ # @param params [Hash]
17
+ # @option request_options [String] :base_url
18
+ # @option request_options [Hash{String => Object}] :additional_headers
19
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
20
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
21
+ # @option request_options [Integer] :timeout_in_seconds
22
+ # @option params [Integer] :account_id
23
+ #
24
+ # @example
25
+ # client.locations.list(account_id: 1)
26
+ #
27
+ # @return [Array[Leal::Locations::Types::ListLocationsResponseItem]]
28
+ def list(request_options: {}, **params)
29
+ params = Leal::Internal::Types::Utils.normalize_keys(params)
30
+ request = Leal::Internal::JSON::Request.new(
31
+ base_url: request_options[:base_url],
32
+ method: "GET",
33
+ path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/locations",
34
+ request_options: request_options
35
+ )
36
+ begin
37
+ response = @client.send(request)
38
+ rescue Net::HTTPRequestTimeout
39
+ raise Leal::Errors::TimeoutError
40
+ end
41
+ code = response.code.to_i
42
+ return if code.between?(200, 299)
43
+
44
+ error_class = Leal::Errors::ResponseError.subclass_for_code(code)
45
+ raise error_class.new(response.body, code: code)
46
+ end
47
+
48
+ # Creates a new physical location for the store. The provided address is
49
+ # automatically geocoded to latitude and longitude coordinates in the background.
50
+ #
51
+ # @param request_options [Hash]
52
+ # @param params [Leal::Locations::Types::CreateLocationsRequest]
53
+ # @option request_options [String] :base_url
54
+ # @option request_options [Hash{String => Object}] :additional_headers
55
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
56
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
57
+ # @option request_options [Integer] :timeout_in_seconds
58
+ # @option params [Integer] :account_id
59
+ #
60
+ # @example
61
+ # client.locations.create(
62
+ # account_id: 1,
63
+ # location: {
64
+ # address: "address",
65
+ # name: "name"
66
+ # }
67
+ # )
68
+ #
69
+ # @return [Leal::Locations::Types::CreateLocationsResponse]
70
+ def create(request_options: {}, **params)
71
+ params = Leal::Internal::Types::Utils.normalize_keys(params)
72
+ request_data = Leal::Locations::Types::CreateLocationsRequest.new(params).to_h
73
+ non_body_param_names = %w[account_id]
74
+ body = request_data.except(*non_body_param_names)
75
+
76
+ request = Leal::Internal::JSON::Request.new(
77
+ base_url: request_options[:base_url],
78
+ method: "POST",
79
+ path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/locations",
80
+ body: body,
81
+ request_options: request_options
82
+ )
83
+ begin
84
+ response = @client.send(request)
85
+ rescue Net::HTTPRequestTimeout
86
+ raise Leal::Errors::TimeoutError
87
+ end
88
+ code = response.code.to_i
89
+ if code.between?(200, 299)
90
+ Leal::Locations::Types::CreateLocationsResponse.load(response.body)
91
+ else
92
+ error_class = Leal::Errors::ResponseError.subclass_for_code(code)
93
+ raise error_class.new(response.body, code: code)
94
+ end
95
+ end
96
+
97
+ # Returns a single location by ID.
98
+ #
99
+ # @param request_options [Hash]
100
+ # @param params [Hash]
101
+ # @option request_options [String] :base_url
102
+ # @option request_options [Hash{String => Object}] :additional_headers
103
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
104
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
105
+ # @option request_options [Integer] :timeout_in_seconds
106
+ # @option params [Integer] :account_id
107
+ # @option params [Integer] :id
108
+ #
109
+ # @example
110
+ # client.locations.get(
111
+ # account_id: 1,
112
+ # id: 1
113
+ # )
114
+ #
115
+ # @return [Leal::Locations::Types::GetLocationsResponse]
116
+ def get(request_options: {}, **params)
117
+ params = Leal::Internal::Types::Utils.normalize_keys(params)
118
+ request = Leal::Internal::JSON::Request.new(
119
+ base_url: request_options[:base_url],
120
+ method: "GET",
121
+ path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/locations/#{URI.encode_uri_component(params[:id].to_s)}",
122
+ request_options: request_options
123
+ )
124
+ begin
125
+ response = @client.send(request)
126
+ rescue Net::HTTPRequestTimeout
127
+ raise Leal::Errors::TimeoutError
128
+ end
129
+ code = response.code.to_i
130
+ if code.between?(200, 299)
131
+ Leal::Locations::Types::GetLocationsResponse.load(response.body)
132
+ else
133
+ error_class = Leal::Errors::ResponseError.subclass_for_code(code)
134
+ raise error_class.new(response.body, code: code)
135
+ end
136
+ end
137
+
138
+ # Permanently deletes a location. This action cannot be undone.
139
+ #
140
+ # @param request_options [Hash]
141
+ # @param params [Hash]
142
+ # @option request_options [String] :base_url
143
+ # @option request_options [Hash{String => Object}] :additional_headers
144
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
145
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
146
+ # @option request_options [Integer] :timeout_in_seconds
147
+ # @option params [Integer] :account_id
148
+ # @option params [Integer] :id
149
+ #
150
+ # @example
151
+ # client.locations.delete(
152
+ # account_id: 1,
153
+ # id: 1
154
+ # )
155
+ #
156
+ # @return [untyped]
157
+ def delete(request_options: {}, **params)
158
+ params = Leal::Internal::Types::Utils.normalize_keys(params)
159
+ request = Leal::Internal::JSON::Request.new(
160
+ base_url: request_options[:base_url],
161
+ method: "DELETE",
162
+ path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/locations/#{URI.encode_uri_component(params[:id].to_s)}",
163
+ request_options: request_options
164
+ )
165
+ begin
166
+ response = @client.send(request)
167
+ rescue Net::HTTPRequestTimeout
168
+ raise Leal::Errors::TimeoutError
169
+ end
170
+ code = response.code.to_i
171
+ return if code.between?(200, 299)
172
+
173
+ error_class = Leal::Errors::ResponseError.subclass_for_code(code)
174
+ raise error_class.new(response.body, code: code)
175
+ end
176
+
177
+ # Updates an existing location. If the address is changed, it will be re-geocoded automatically.
178
+ #
179
+ # @param request_options [Hash]
180
+ # @param params [Leal::Locations::Types::UpdateLocationsRequest]
181
+ # @option request_options [String] :base_url
182
+ # @option request_options [Hash{String => Object}] :additional_headers
183
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
184
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
185
+ # @option request_options [Integer] :timeout_in_seconds
186
+ # @option params [Integer] :account_id
187
+ # @option params [Integer] :id
188
+ #
189
+ # @example
190
+ # client.locations.update(
191
+ # account_id: 1,
192
+ # id: 1,
193
+ # location: {}
194
+ # )
195
+ #
196
+ # @return [Leal::Locations::Types::UpdateLocationsResponse]
197
+ def update(request_options: {}, **params)
198
+ params = Leal::Internal::Types::Utils.normalize_keys(params)
199
+ request_data = Leal::Locations::Types::UpdateLocationsRequest.new(params).to_h
200
+ non_body_param_names = %w[account_id id]
201
+ body = request_data.except(*non_body_param_names)
202
+
203
+ request = Leal::Internal::JSON::Request.new(
204
+ base_url: request_options[:base_url],
205
+ method: "PATCH",
206
+ path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/locations/#{URI.encode_uri_component(params[:id].to_s)}",
207
+ body: body,
208
+ request_options: request_options
209
+ )
210
+ begin
211
+ response = @client.send(request)
212
+ rescue Net::HTTPRequestTimeout
213
+ raise Leal::Errors::TimeoutError
214
+ end
215
+ code = response.code.to_i
216
+ if code.between?(200, 299)
217
+ Leal::Locations::Types::UpdateLocationsResponse.load(response.body)
218
+ else
219
+ error_class = Leal::Errors::ResponseError.subclass_for_code(code)
220
+ raise error_class.new(response.body, code: code)
221
+ end
222
+ end
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leal
4
+ module Locations
5
+ module Types
6
+ class CreateLocationsRequest < Internal::Types::Model
7
+ field :account_id, -> { Integer }, optional: false, nullable: false
8
+
9
+ field :location, -> { Leal::Locations::Types::CreateLocationsRequestLocation }, optional: false, nullable: false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leal
4
+ module Locations
5
+ module Types
6
+ class CreateLocationsRequestLocation < Internal::Types::Model
7
+ field :address, -> { String }, optional: false, nullable: false
8
+
9
+ field :name, -> { String }, optional: false, nullable: false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leal
4
+ module Locations
5
+ module Types
6
+ class CreateLocationsResponse < Internal::Types::Model
7
+ field :account_id, -> { Integer }, optional: false, nullable: false
8
+
9
+ field :address, -> { String }, optional: false, nullable: false
10
+
11
+ field :created_at, -> { String }, optional: false, nullable: false
12
+
13
+ field :id, -> { Integer }, optional: false, nullable: false
14
+
15
+ field :latitude, -> { Integer }, optional: false, nullable: false
16
+
17
+ field :longitude, -> { Integer }, optional: false, nullable: false
18
+
19
+ field :name, -> { String }, optional: false, nullable: false
20
+
21
+ field :updated_at, -> { String }, optional: false, nullable: false
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leal
4
+ module Locations
5
+ module Types
6
+ class DeleteLocationsRequest < Internal::Types::Model
7
+ field :account_id, -> { Integer }, optional: false, nullable: false
8
+
9
+ field :id, -> { Integer }, optional: false, nullable: false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leal
4
+ module Locations
5
+ module Types
6
+ class GetLocationsRequest < Internal::Types::Model
7
+ field :account_id, -> { Integer }, optional: false, nullable: false
8
+
9
+ field :id, -> { Integer }, optional: false, nullable: false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leal
4
+ module Locations
5
+ module Types
6
+ class GetLocationsResponse < Internal::Types::Model
7
+ field :account_id, -> { Integer }, optional: false, nullable: false
8
+
9
+ field :address, -> { String }, optional: false, nullable: false
10
+
11
+ field :created_at, -> { String }, optional: false, nullable: false
12
+
13
+ field :id, -> { Integer }, optional: false, nullable: false
14
+
15
+ field :latitude, -> { Integer }, optional: false, nullable: false
16
+
17
+ field :longitude, -> { Integer }, optional: false, nullable: false
18
+
19
+ field :name, -> { String }, optional: false, nullable: false
20
+
21
+ field :updated_at, -> { String }, optional: false, nullable: false
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leal
4
+ module Locations
5
+ module Types
6
+ class ListLocationsRequest < Internal::Types::Model
7
+ field :account_id, -> { Integer }, optional: false, nullable: false
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leal
4
+ module Locations
5
+ module Types
6
+ class ListLocationsResponseItem < Internal::Types::Model
7
+ field :account_id, -> { Integer }, optional: false, nullable: false
8
+
9
+ field :address, -> { String }, optional: false, nullable: false
10
+
11
+ field :created_at, -> { String }, optional: false, nullable: false
12
+
13
+ field :id, -> { Integer }, optional: false, nullable: false
14
+
15
+ field :latitude, -> { Integer }, optional: false, nullable: false
16
+
17
+ field :longitude, -> { Integer }, optional: false, nullable: false
18
+
19
+ field :name, -> { String }, optional: false, nullable: false
20
+
21
+ field :updated_at, -> { String }, optional: false, nullable: false
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leal
4
+ module Locations
5
+ module Types
6
+ class UpdateLocationsRequest < Internal::Types::Model
7
+ field :account_id, -> { Integer }, optional: false, nullable: false
8
+
9
+ field :id, -> { Integer }, optional: false, nullable: false
10
+
11
+ field :location, -> { Leal::Locations::Types::UpdateLocationsRequestLocation }, optional: false, nullable: false
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leal
4
+ module Locations
5
+ module Types
6
+ class UpdateLocationsRequestLocation < Internal::Types::Model
7
+ field :address, -> { String }, optional: true, nullable: false
8
+
9
+ field :name, -> { String }, optional: true, nullable: false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leal
4
+ module Locations
5
+ module Types
6
+ class UpdateLocationsResponse < Internal::Types::Model
7
+ field :account_id, -> { Integer }, optional: false, nullable: false
8
+
9
+ field :address, -> { String }, optional: false, nullable: false
10
+
11
+ field :created_at, -> { String }, optional: false, nullable: false
12
+
13
+ field :id, -> { Integer }, optional: false, nullable: false
14
+
15
+ field :latitude, -> { Integer }, optional: false, nullable: false
16
+
17
+ field :longitude, -> { Integer }, optional: false, nullable: false
18
+
19
+ field :name, -> { String }, optional: false, nullable: false
20
+
21
+ field :updated_at, -> { String }, optional: false, nullable: false
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,232 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leal
4
+ module Posters
5
+ class Client
6
+ # @param client [Leal::Internal::Http::RawClient]
7
+ #
8
+ # @return [void]
9
+ def initialize(client:)
10
+ @client = client
11
+ end
12
+
13
+ # Returns all posters for the store. Optionally filter by card or active status.
14
+ #
15
+ # @param request_options [Hash]
16
+ # @param params [Hash]
17
+ # @option request_options [String] :base_url
18
+ # @option request_options [Hash{String => Object}] :additional_headers
19
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
20
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
21
+ # @option request_options [Integer] :timeout_in_seconds
22
+ # @option params [Integer] :account_id
23
+ # @option params [Integer, nil] :card_id
24
+ # @option params [String, nil] :active
25
+ #
26
+ # @example
27
+ # client.posters.list(account_id: 1)
28
+ #
29
+ # @return [Array[Leal::Posters::Types::ListPostersResponseItem]]
30
+ def list(request_options: {}, **params)
31
+ params = Leal::Internal::Types::Utils.normalize_keys(params)
32
+ query_params = {}
33
+ query_params["card_id"] = params[:card_id] if params.key?(:card_id)
34
+ query_params["active"] = params[:active] if params.key?(:active)
35
+
36
+ request = Leal::Internal::JSON::Request.new(
37
+ base_url: request_options[:base_url],
38
+ method: "GET",
39
+ path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/posters",
40
+ query: query_params,
41
+ request_options: request_options
42
+ )
43
+ begin
44
+ response = @client.send(request)
45
+ rescue Net::HTTPRequestTimeout
46
+ raise Leal::Errors::TimeoutError
47
+ end
48
+ code = response.code.to_i
49
+ return if code.between?(200, 299)
50
+
51
+ error_class = Leal::Errors::ResponseError.subclass_for_code(code)
52
+ raise error_class.new(response.body, code: code)
53
+ end
54
+
55
+ # Creates a new printable QR code poster for customer signup. The poster will automatically
56
+ # generate a unique public signup URL and QR code. The `card_id` is required on create to
57
+ # associate the poster with a loyalty card.
58
+ #
59
+ # @param request_options [Hash]
60
+ # @param params [Leal::Posters::Types::CreatePostersRequest]
61
+ # @option request_options [String] :base_url
62
+ # @option request_options [Hash{String => Object}] :additional_headers
63
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
64
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
65
+ # @option request_options [Integer] :timeout_in_seconds
66
+ # @option params [Integer] :account_id
67
+ #
68
+ # @example
69
+ # client.posters.create(
70
+ # account_id: 1,
71
+ # poster: {
72
+ # card_id: 1
73
+ # }
74
+ # )
75
+ #
76
+ # @return [Leal::Posters::Types::CreatePostersResponse]
77
+ def create(request_options: {}, **params)
78
+ params = Leal::Internal::Types::Utils.normalize_keys(params)
79
+ request_data = Leal::Posters::Types::CreatePostersRequest.new(params).to_h
80
+ non_body_param_names = %w[account_id]
81
+ body = request_data.except(*non_body_param_names)
82
+
83
+ request = Leal::Internal::JSON::Request.new(
84
+ base_url: request_options[:base_url],
85
+ method: "POST",
86
+ path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/posters",
87
+ body: body,
88
+ request_options: request_options
89
+ )
90
+ begin
91
+ response = @client.send(request)
92
+ rescue Net::HTTPRequestTimeout
93
+ raise Leal::Errors::TimeoutError
94
+ end
95
+ code = response.code.to_i
96
+ if code.between?(200, 299)
97
+ Leal::Posters::Types::CreatePostersResponse.load(response.body)
98
+ else
99
+ error_class = Leal::Errors::ResponseError.subclass_for_code(code)
100
+ raise error_class.new(response.body, code: code)
101
+ end
102
+ end
103
+
104
+ # Returns a single poster by ID, including generated signup and display URLs.
105
+ #
106
+ # @param request_options [Hash]
107
+ # @param params [Hash]
108
+ # @option request_options [String] :base_url
109
+ # @option request_options [Hash{String => Object}] :additional_headers
110
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
111
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
112
+ # @option request_options [Integer] :timeout_in_seconds
113
+ # @option params [Integer] :account_id
114
+ # @option params [Integer] :id
115
+ #
116
+ # @example
117
+ # client.posters.get(
118
+ # account_id: 1,
119
+ # id: 1
120
+ # )
121
+ #
122
+ # @return [Leal::Posters::Types::GetPostersResponse]
123
+ def get(request_options: {}, **params)
124
+ params = Leal::Internal::Types::Utils.normalize_keys(params)
125
+ request = Leal::Internal::JSON::Request.new(
126
+ base_url: request_options[:base_url],
127
+ method: "GET",
128
+ path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/posters/#{URI.encode_uri_component(params[:id].to_s)}",
129
+ request_options: request_options
130
+ )
131
+ begin
132
+ response = @client.send(request)
133
+ rescue Net::HTTPRequestTimeout
134
+ raise Leal::Errors::TimeoutError
135
+ end
136
+ code = response.code.to_i
137
+ if code.between?(200, 299)
138
+ Leal::Posters::Types::GetPostersResponse.load(response.body)
139
+ else
140
+ error_class = Leal::Errors::ResponseError.subclass_for_code(code)
141
+ raise error_class.new(response.body, code: code)
142
+ end
143
+ end
144
+
145
+ # Permanently deletes a poster. The public signup URL will stop working.
146
+ #
147
+ # @param request_options [Hash]
148
+ # @param params [Hash]
149
+ # @option request_options [String] :base_url
150
+ # @option request_options [Hash{String => Object}] :additional_headers
151
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
152
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
153
+ # @option request_options [Integer] :timeout_in_seconds
154
+ # @option params [Integer] :account_id
155
+ # @option params [Integer] :id
156
+ #
157
+ # @example
158
+ # client.posters.delete(
159
+ # account_id: 1,
160
+ # id: 1
161
+ # )
162
+ #
163
+ # @return [untyped]
164
+ def delete(request_options: {}, **params)
165
+ params = Leal::Internal::Types::Utils.normalize_keys(params)
166
+ request = Leal::Internal::JSON::Request.new(
167
+ base_url: request_options[:base_url],
168
+ method: "DELETE",
169
+ path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/posters/#{URI.encode_uri_component(params[:id].to_s)}",
170
+ request_options: request_options
171
+ )
172
+ begin
173
+ response = @client.send(request)
174
+ rescue Net::HTTPRequestTimeout
175
+ raise Leal::Errors::TimeoutError
176
+ end
177
+ code = response.code.to_i
178
+ return if code.between?(200, 299)
179
+
180
+ error_class = Leal::Errors::ResponseError.subclass_for_code(code)
181
+ raise error_class.new(response.body, code: code)
182
+ end
183
+
184
+ # Updates an existing poster. The `card_id` cannot be changed after creation.
185
+ #
186
+ # @param request_options [Hash]
187
+ # @param params [Leal::Posters::Types::UpdatePostersRequest]
188
+ # @option request_options [String] :base_url
189
+ # @option request_options [Hash{String => Object}] :additional_headers
190
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
191
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
192
+ # @option request_options [Integer] :timeout_in_seconds
193
+ # @option params [Integer] :account_id
194
+ # @option params [Integer] :id
195
+ #
196
+ # @example
197
+ # client.posters.update(
198
+ # account_id: 1,
199
+ # id: 1,
200
+ # poster: {}
201
+ # )
202
+ #
203
+ # @return [Leal::Posters::Types::UpdatePostersResponse]
204
+ def update(request_options: {}, **params)
205
+ params = Leal::Internal::Types::Utils.normalize_keys(params)
206
+ request_data = Leal::Posters::Types::UpdatePostersRequest.new(params).to_h
207
+ non_body_param_names = %w[account_id id]
208
+ body = request_data.except(*non_body_param_names)
209
+
210
+ request = Leal::Internal::JSON::Request.new(
211
+ base_url: request_options[:base_url],
212
+ method: "PATCH",
213
+ path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/posters/#{URI.encode_uri_component(params[:id].to_s)}",
214
+ body: body,
215
+ request_options: request_options
216
+ )
217
+ begin
218
+ response = @client.send(request)
219
+ rescue Net::HTTPRequestTimeout
220
+ raise Leal::Errors::TimeoutError
221
+ end
222
+ code = response.code.to_i
223
+ if code.between?(200, 299)
224
+ Leal::Posters::Types::UpdatePostersResponse.load(response.body)
225
+ else
226
+ error_class = Leal::Errors::ResponseError.subclass_for_code(code)
227
+ raise error_class.new(response.body, code: code)
228
+ end
229
+ end
230
+ end
231
+ end
232
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leal
4
+ module Posters
5
+ module Types
6
+ class CreatePostersRequest < Internal::Types::Model
7
+ field :account_id, -> { Integer }, optional: false, nullable: false
8
+
9
+ field :poster, -> { Leal::Posters::Types::CreatePostersRequestPoster }, optional: false, nullable: false
10
+ end
11
+ end
12
+ end
13
+ end