square.rb 3.3.0.20191217

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 (51) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +10 -0
  3. data/README.md +285 -0
  4. data/lib/square/api/apple_pay_api.rb +50 -0
  5. data/lib/square/api/base_api.rb +43 -0
  6. data/lib/square/api/cash_drawers_api.rb +150 -0
  7. data/lib/square/api/catalog_api.rb +545 -0
  8. data/lib/square/api/checkout_api.rb +49 -0
  9. data/lib/square/api/customers_api.rb +327 -0
  10. data/lib/square/api/employees_api.rb +86 -0
  11. data/lib/square/api/inventory_api.rb +295 -0
  12. data/lib/square/api/labor_api.rb +553 -0
  13. data/lib/square/api/locations_api.rb +146 -0
  14. data/lib/square/api/merchants_api.rb +82 -0
  15. data/lib/square/api/mobile_authorization_api.rb +52 -0
  16. data/lib/square/api/o_auth_api.rb +163 -0
  17. data/lib/square/api/orders_api.rb +266 -0
  18. data/lib/square/api/payments_api.rb +277 -0
  19. data/lib/square/api/refunds_api.rb +144 -0
  20. data/lib/square/api/reporting_api.rb +138 -0
  21. data/lib/square/api/transactions_api.rb +377 -0
  22. data/lib/square/api/v1_employees_api.rb +715 -0
  23. data/lib/square/api/v1_items_api.rb +2046 -0
  24. data/lib/square/api/v1_locations_api.rb +83 -0
  25. data/lib/square/api/v1_transactions_api.rb +568 -0
  26. data/lib/square/api_helper.rb +276 -0
  27. data/lib/square/client.rb +156 -0
  28. data/lib/square/configuration.rb +93 -0
  29. data/lib/square/exceptions/api_exception.rb +15 -0
  30. data/lib/square/http/api_response.rb +45 -0
  31. data/lib/square/http/auth/o_auth2.rb +12 -0
  32. data/lib/square/http/faraday_client.rb +59 -0
  33. data/lib/square/http/http_call_back.rb +19 -0
  34. data/lib/square/http/http_client.rb +99 -0
  35. data/lib/square/http/http_method_enum.rb +8 -0
  36. data/lib/square/http/http_request.rb +45 -0
  37. data/lib/square/http/http_response.rb +24 -0
  38. data/lib/square.rb +49 -0
  39. data/spec/user_journey_spec.rb +145 -0
  40. data/test/api/api_test_base.rb +24 -0
  41. data/test/api/test_catalog_api.rb +59 -0
  42. data/test/api/test_customers_api.rb +45 -0
  43. data/test/api/test_employees_api.rb +36 -0
  44. data/test/api/test_labor_api.rb +74 -0
  45. data/test/api/test_locations_api.rb +35 -0
  46. data/test/api/test_merchants_api.rb +40 -0
  47. data/test/api/test_payments_api.rb +42 -0
  48. data/test/api/test_refunds_api.rb +41 -0
  49. data/test/http_response_catcher.rb +19 -0
  50. data/test/test_helper.rb +94 -0
  51. metadata +190 -0
@@ -0,0 +1,327 @@
1
+ module Square
2
+ # CustomersApi
3
+ class CustomersApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Lists a business's customers.
9
+ # @param [String] cursor Optional parameter: A pagination cursor returned by
10
+ # a previous call to this endpoint. Provide this to retrieve the next set of
11
+ # results for your original query. See the [Pagination
12
+ # guide](https://developer.squareup.com/docs/working-with-apis/pagination)
13
+ # for more information.
14
+ # @param [CustomerSortField] sort_field Optional parameter: Indicates how
15
+ # Customers should be sorted. Default: `DEFAULT`.
16
+ # @param [SortOrder] sort_order Optional parameter: Indicates whether
17
+ # Customers should be sorted in ascending (`ASC`) or descending (`DESC`)
18
+ # order. Default: `ASC`.
19
+ # @return [ListCustomersResponse Hash] response from the API call
20
+ def list_customers(cursor: nil,
21
+ sort_field: nil,
22
+ sort_order: nil)
23
+ # Prepare query url.
24
+ _query_builder = config.get_base_uri
25
+ _query_builder << '/v2/customers'
26
+ _query_builder = APIHelper.append_url_with_query_parameters(
27
+ _query_builder,
28
+ 'cursor' => cursor,
29
+ 'sort_field' => sort_field,
30
+ 'sort_order' => sort_order
31
+ )
32
+ _query_url = APIHelper.clean_url _query_builder
33
+
34
+ # Prepare headers.
35
+ _headers = {
36
+ 'accept' => 'application/json'
37
+ }
38
+
39
+ # Prepare and execute HttpRequest.
40
+ _request = config.http_client.get(
41
+ _query_url,
42
+ headers: _headers
43
+ )
44
+ OAuth2.apply(config, _request)
45
+ _response = execute_request(_request)
46
+
47
+ # Return appropriate response type.
48
+ decoded = APIHelper.json_deserialize(_response.raw_body)
49
+ _errors = APIHelper.map_response(decoded, ['errors'])
50
+ ApiResponse.new(_response, data: decoded, errors: _errors)
51
+ end
52
+
53
+ # Creates a new customer for a business, which can have associated cards on
54
+ # file.
55
+ # You must provide __at least one__ of the following values in your request
56
+ # to this
57
+ # endpoint:
58
+ # - `given_name`
59
+ # - `family_name`
60
+ # - `company_name`
61
+ # - `email_address`
62
+ # - `phone_number`
63
+ # @param [CreateCustomerRequest] body Required parameter: An object
64
+ # containing the fields to POST for the request. See the corresponding
65
+ # object definition for field details.
66
+ # @return [CreateCustomerResponse Hash] response from the API call
67
+ def create_customer(body:)
68
+ # Prepare query url.
69
+ _query_builder = config.get_base_uri
70
+ _query_builder << '/v2/customers'
71
+ _query_url = APIHelper.clean_url _query_builder
72
+
73
+ # Prepare headers.
74
+ _headers = {
75
+ 'accept' => 'application/json',
76
+ 'content-type' => 'application/json; charset=utf-8'
77
+ }
78
+
79
+ # Prepare and execute HttpRequest.
80
+ _request = config.http_client.post(
81
+ _query_url,
82
+ headers: _headers,
83
+ parameters: body.to_json
84
+ )
85
+ OAuth2.apply(config, _request)
86
+ _response = execute_request(_request)
87
+
88
+ # Return appropriate response type.
89
+ decoded = APIHelper.json_deserialize(_response.raw_body)
90
+ _errors = APIHelper.map_response(decoded, ['errors'])
91
+ ApiResponse.new(_response, data: decoded, errors: _errors)
92
+ end
93
+
94
+ # Searches the customer profiles associated with a Square account.
95
+ # Calling SearchCustomers without an explicit query parameter returns all
96
+ # customer profiles ordered alphabetically based on `given_name` and
97
+ # `family_name`.
98
+ # @param [SearchCustomersRequest] body Required parameter: An object
99
+ # containing the fields to POST for the request. See the corresponding
100
+ # object definition for field details.
101
+ # @return [SearchCustomersResponse Hash] response from the API call
102
+ def search_customers(body:)
103
+ # Prepare query url.
104
+ _query_builder = config.get_base_uri
105
+ _query_builder << '/v2/customers/search'
106
+ _query_url = APIHelper.clean_url _query_builder
107
+
108
+ # Prepare headers.
109
+ _headers = {
110
+ 'accept' => 'application/json',
111
+ 'content-type' => 'application/json; charset=utf-8'
112
+ }
113
+
114
+ # Prepare and execute HttpRequest.
115
+ _request = config.http_client.post(
116
+ _query_url,
117
+ headers: _headers,
118
+ parameters: body.to_json
119
+ )
120
+ OAuth2.apply(config, _request)
121
+ _response = execute_request(_request)
122
+
123
+ # Return appropriate response type.
124
+ decoded = APIHelper.json_deserialize(_response.raw_body)
125
+ _errors = APIHelper.map_response(decoded, ['errors'])
126
+ ApiResponse.new(_response, data: decoded, errors: _errors)
127
+ end
128
+
129
+ # Deletes a customer from a business, along with any linked cards on file.
130
+ # When two profiles
131
+ # are merged into a single profile, that profile is assigned a new
132
+ # `customer_id`. You must use the
133
+ # new `customer_id` to delete merged profiles.
134
+ # @param [String] customer_id Required parameter: The ID of the customer to
135
+ # delete.
136
+ # @return [DeleteCustomerResponse Hash] response from the API call
137
+ def delete_customer(customer_id:)
138
+ # Prepare query url.
139
+ _query_builder = config.get_base_uri
140
+ _query_builder << '/v2/customers/{customer_id}'
141
+ _query_builder = APIHelper.append_url_with_template_parameters(
142
+ _query_builder,
143
+ 'customer_id' => customer_id
144
+ )
145
+ _query_url = APIHelper.clean_url _query_builder
146
+
147
+ # Prepare headers.
148
+ _headers = {
149
+ 'accept' => 'application/json'
150
+ }
151
+
152
+ # Prepare and execute HttpRequest.
153
+ _request = config.http_client.delete(
154
+ _query_url,
155
+ headers: _headers
156
+ )
157
+ OAuth2.apply(config, _request)
158
+ _response = execute_request(_request)
159
+
160
+ # Return appropriate response type.
161
+ decoded = APIHelper.json_deserialize(_response.raw_body)
162
+ _errors = APIHelper.map_response(decoded, ['errors'])
163
+ ApiResponse.new(_response, data: decoded, errors: _errors)
164
+ end
165
+
166
+ # Returns details for a single customer.
167
+ # @param [String] customer_id Required parameter: The ID of the customer to
168
+ # retrieve.
169
+ # @return [RetrieveCustomerResponse Hash] response from the API call
170
+ def retrieve_customer(customer_id:)
171
+ # Prepare query url.
172
+ _query_builder = config.get_base_uri
173
+ _query_builder << '/v2/customers/{customer_id}'
174
+ _query_builder = APIHelper.append_url_with_template_parameters(
175
+ _query_builder,
176
+ 'customer_id' => customer_id
177
+ )
178
+ _query_url = APIHelper.clean_url _query_builder
179
+
180
+ # Prepare headers.
181
+ _headers = {
182
+ 'accept' => 'application/json'
183
+ }
184
+
185
+ # Prepare and execute HttpRequest.
186
+ _request = config.http_client.get(
187
+ _query_url,
188
+ headers: _headers
189
+ )
190
+ OAuth2.apply(config, _request)
191
+ _response = execute_request(_request)
192
+
193
+ # Return appropriate response type.
194
+ decoded = APIHelper.json_deserialize(_response.raw_body)
195
+ _errors = APIHelper.map_response(decoded, ['errors'])
196
+ ApiResponse.new(_response, data: decoded, errors: _errors)
197
+ end
198
+
199
+ # Updates the details of an existing customer. When two profiles are merged
200
+ # into a single profile, that profile is assigned a new `customer_id`. You
201
+ # must use
202
+ # the new `customer_id` to update merged profiles.
203
+ # You cannot edit a customer's cards on file with this endpoint. To make
204
+ # changes
205
+ # to a card on file, you must delete the existing card on file with the
206
+ # [DeleteCustomerCard](#endpoint-deletecustomercard) endpoint, then create a
207
+ # new one with the
208
+ # [CreateCustomerCard](#endpoint-createcustomercard) endpoint.
209
+ # @param [String] customer_id Required parameter: The ID of the customer to
210
+ # update.
211
+ # @param [UpdateCustomerRequest] body Required parameter: An object
212
+ # containing the fields to POST for the request. See the corresponding
213
+ # object definition for field details.
214
+ # @return [UpdateCustomerResponse Hash] response from the API call
215
+ def update_customer(customer_id:,
216
+ body:)
217
+ # Prepare query url.
218
+ _query_builder = config.get_base_uri
219
+ _query_builder << '/v2/customers/{customer_id}'
220
+ _query_builder = APIHelper.append_url_with_template_parameters(
221
+ _query_builder,
222
+ 'customer_id' => customer_id
223
+ )
224
+ _query_url = APIHelper.clean_url _query_builder
225
+
226
+ # Prepare headers.
227
+ _headers = {
228
+ 'accept' => 'application/json',
229
+ 'content-type' => 'application/json; charset=utf-8'
230
+ }
231
+
232
+ # Prepare and execute HttpRequest.
233
+ _request = config.http_client.put(
234
+ _query_url,
235
+ headers: _headers,
236
+ parameters: body.to_json
237
+ )
238
+ OAuth2.apply(config, _request)
239
+ _response = execute_request(_request)
240
+
241
+ # Return appropriate response type.
242
+ decoded = APIHelper.json_deserialize(_response.raw_body)
243
+ _errors = APIHelper.map_response(decoded, ['errors'])
244
+ ApiResponse.new(_response, data: decoded, errors: _errors)
245
+ end
246
+
247
+ # Adds a card on file to an existing customer.
248
+ # As with charges, calls to `CreateCustomerCard` are idempotent. Multiple
249
+ # calls with the same card nonce return the same card record that was
250
+ # created
251
+ # with the provided nonce during the _first_ call.
252
+ # @param [String] customer_id Required parameter: The Square ID of the
253
+ # customer profile the card is linked to.
254
+ # @param [CreateCustomerCardRequest] body Required parameter: An object
255
+ # containing the fields to POST for the request. See the corresponding
256
+ # object definition for field details.
257
+ # @return [CreateCustomerCardResponse Hash] response from the API call
258
+ def create_customer_card(customer_id:,
259
+ body:)
260
+ # Prepare query url.
261
+ _query_builder = config.get_base_uri
262
+ _query_builder << '/v2/customers/{customer_id}/cards'
263
+ _query_builder = APIHelper.append_url_with_template_parameters(
264
+ _query_builder,
265
+ 'customer_id' => customer_id
266
+ )
267
+ _query_url = APIHelper.clean_url _query_builder
268
+
269
+ # Prepare headers.
270
+ _headers = {
271
+ 'accept' => 'application/json',
272
+ 'content-type' => 'application/json; charset=utf-8'
273
+ }
274
+
275
+ # Prepare and execute HttpRequest.
276
+ _request = config.http_client.post(
277
+ _query_url,
278
+ headers: _headers,
279
+ parameters: body.to_json
280
+ )
281
+ OAuth2.apply(config, _request)
282
+ _response = execute_request(_request)
283
+
284
+ # Return appropriate response type.
285
+ decoded = APIHelper.json_deserialize(_response.raw_body)
286
+ _errors = APIHelper.map_response(decoded, ['errors'])
287
+ ApiResponse.new(_response, data: decoded, errors: _errors)
288
+ end
289
+
290
+ # Removes a card on file from a customer.
291
+ # @param [String] customer_id Required parameter: The ID of the customer
292
+ # that the card on file belongs to.
293
+ # @param [String] card_id Required parameter: The ID of the card on file to
294
+ # delete.
295
+ # @return [DeleteCustomerCardResponse Hash] response from the API call
296
+ def delete_customer_card(customer_id:,
297
+ card_id:)
298
+ # Prepare query url.
299
+ _query_builder = config.get_base_uri
300
+ _query_builder << '/v2/customers/{customer_id}/cards/{card_id}'
301
+ _query_builder = APIHelper.append_url_with_template_parameters(
302
+ _query_builder,
303
+ 'customer_id' => customer_id,
304
+ 'card_id' => card_id
305
+ )
306
+ _query_url = APIHelper.clean_url _query_builder
307
+
308
+ # Prepare headers.
309
+ _headers = {
310
+ 'accept' => 'application/json'
311
+ }
312
+
313
+ # Prepare and execute HttpRequest.
314
+ _request = config.http_client.delete(
315
+ _query_url,
316
+ headers: _headers
317
+ )
318
+ OAuth2.apply(config, _request)
319
+ _response = execute_request(_request)
320
+
321
+ # Return appropriate response type.
322
+ decoded = APIHelper.json_deserialize(_response.raw_body)
323
+ _errors = APIHelper.map_response(decoded, ['errors'])
324
+ ApiResponse.new(_response, data: decoded, errors: _errors)
325
+ end
326
+ end
327
+ end
@@ -0,0 +1,86 @@
1
+ module Square
2
+ # EmployeesApi
3
+ class EmployeesApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # ListEmployees
9
+ # @param [String] location_id Optional parameter: Filter employees returned
10
+ # to only those that are associated with the specified location.
11
+ # @param [EmployeeStatus] status Optional parameter: Specifies the
12
+ # EmployeeStatus to filter the employee by.
13
+ # @param [Integer] limit Optional parameter: The number of employees to be
14
+ # returned on each page.
15
+ # @param [String] cursor Optional parameter: The token required to retrieve
16
+ # the specified page of results.
17
+ # @return [ListEmployeesResponse Hash] response from the API call
18
+ def list_employees(location_id: nil,
19
+ status: nil,
20
+ limit: nil,
21
+ cursor: nil)
22
+ # Prepare query url.
23
+ _query_builder = config.get_base_uri
24
+ _query_builder << '/v2/employees'
25
+ _query_builder = APIHelper.append_url_with_query_parameters(
26
+ _query_builder,
27
+ 'location_id' => location_id,
28
+ 'status' => status,
29
+ 'limit' => limit,
30
+ 'cursor' => cursor
31
+ )
32
+ _query_url = APIHelper.clean_url _query_builder
33
+
34
+ # Prepare headers.
35
+ _headers = {
36
+ 'accept' => 'application/json'
37
+ }
38
+
39
+ # Prepare and execute HttpRequest.
40
+ _request = config.http_client.get(
41
+ _query_url,
42
+ headers: _headers
43
+ )
44
+ OAuth2.apply(config, _request)
45
+ _response = execute_request(_request)
46
+
47
+ # Return appropriate response type.
48
+ decoded = APIHelper.json_deserialize(_response.raw_body)
49
+ _errors = APIHelper.map_response(decoded, ['errors'])
50
+ ApiResponse.new(_response, data: decoded, errors: _errors)
51
+ end
52
+
53
+ # RetrieveEmployee
54
+ # @param [String] id Required parameter: UUID for the employee that was
55
+ # requested.
56
+ # @return [RetrieveEmployeeResponse Hash] response from the API call
57
+ def retrieve_employee(id:)
58
+ # Prepare query url.
59
+ _query_builder = config.get_base_uri
60
+ _query_builder << '/v2/employees/{id}'
61
+ _query_builder = APIHelper.append_url_with_template_parameters(
62
+ _query_builder,
63
+ 'id' => id
64
+ )
65
+ _query_url = APIHelper.clean_url _query_builder
66
+
67
+ # Prepare headers.
68
+ _headers = {
69
+ 'accept' => 'application/json'
70
+ }
71
+
72
+ # Prepare and execute HttpRequest.
73
+ _request = config.http_client.get(
74
+ _query_url,
75
+ headers: _headers
76
+ )
77
+ OAuth2.apply(config, _request)
78
+ _response = execute_request(_request)
79
+
80
+ # Return appropriate response type.
81
+ decoded = APIHelper.json_deserialize(_response.raw_body)
82
+ _errors = APIHelper.map_response(decoded, ['errors'])
83
+ ApiResponse.new(_response, data: decoded, errors: _errors)
84
+ end
85
+ end
86
+ end