square.rb 26.0.0.20221214 → 26.2.0.20230315

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/lib/square/api/apple_pay_api.rb +14 -30
  4. data/lib/square/api/bank_accounts_api.rb +40 -90
  5. data/lib/square/api/base_api.rb +42 -42
  6. data/lib/square/api/booking_custom_attributes_api.rb +164 -329
  7. data/lib/square/api/bookings_api.rb +135 -260
  8. data/lib/square/api/cards_api.rb +56 -118
  9. data/lib/square/api/cash_drawers_api.rb +47 -103
  10. data/lib/square/api/catalog_api.rb +197 -423
  11. data/lib/square/api/checkout_api.rb +85 -175
  12. data/lib/square/api/customer_custom_attributes_api.rb +150 -303
  13. data/lib/square/api/customer_groups_api.rb +69 -145
  14. data/lib/square/api/customer_segments_api.rb +26 -61
  15. data/lib/square/api/customers_api.rb +147 -294
  16. data/lib/square/api/devices_api.rb +42 -89
  17. data/lib/square/api/disputes_api.rb +130 -288
  18. data/lib/square/api/employees_api.rb +28 -63
  19. data/lib/square/api/gift_card_activities_api.rb +33 -65
  20. data/lib/square/api/gift_cards_api.rb +103 -202
  21. data/lib/square/api/inventory_api.rb +179 -366
  22. data/lib/square/api/invoices_api.rb +118 -237
  23. data/lib/square/api/labor_api.rb +223 -459
  24. data/lib/square/api/location_custom_attributes_api.rb +419 -0
  25. data/lib/square/api/locations_api.rb +54 -112
  26. data/lib/square/api/loyalty_api.rb +259 -512
  27. data/lib/square/api/merchants_api.rb +25 -60
  28. data/lib/square/api/mobile_authorization_api.rb +14 -30
  29. data/lib/square/api/o_auth_api.rb +54 -109
  30. data/lib/square/api/order_custom_attributes_api.rb +168 -333
  31. data/lib/square/api/orders_api.rb +115 -222
  32. data/lib/square/api/payments_api.rb +106 -208
  33. data/lib/square/api/payouts_api.rb +47 -100
  34. data/lib/square/api/refunds_api.rb +46 -93
  35. data/lib/square/api/sites_api.rb +11 -28
  36. data/lib/square/api/snippets_api.rb +42 -90
  37. data/lib/square/api/subscriptions_api.rb +150 -299
  38. data/lib/square/api/team_api.rb +114 -224
  39. data/lib/square/api/terminal_api.rb +162 -328
  40. data/lib/square/api/transactions_api.rb +62 -126
  41. data/lib/square/api/v1_transactions_api.rb +155 -296
  42. data/lib/square/api/vendors_api.rb +99 -192
  43. data/lib/square/api/webhook_subscriptions_api.rb +115 -235
  44. data/lib/square/api_helper.rb +1 -437
  45. data/lib/square/client.rb +82 -46
  46. data/lib/square/configuration.rb +28 -53
  47. data/lib/square/exceptions/api_exception.rb +1 -11
  48. data/lib/square/http/api_response.rb +13 -19
  49. data/lib/square/http/auth/o_auth2.rb +14 -7
  50. data/lib/square/http/http_call_back.rb +1 -15
  51. data/lib/square/http/http_method_enum.rb +1 -4
  52. data/lib/square/http/http_request.rb +1 -45
  53. data/lib/square/http/http_response.rb +1 -20
  54. data/lib/square/utilities/date_time_helper.rb +1 -146
  55. data/lib/square/utilities/file_wrapper.rb +5 -5
  56. data/lib/square.rb +7 -6
  57. data/spec/user_journey_spec.rb +2 -2
  58. data/test/api/api_test_base.rb +13 -5
  59. data/test/api/test_catalog_api.rb +5 -4
  60. data/test/api/test_customers_api.rb +3 -2
  61. data/test/api/test_employees_api.rb +4 -3
  62. data/test/api/test_labor_api.rb +6 -5
  63. data/test/api/test_locations_api.rb +3 -2
  64. data/test/api/test_merchants_api.rb +4 -3
  65. data/test/api/test_payments_api.rb +4 -3
  66. data/test/api/test_refunds_api.rb +4 -3
  67. metadata +12 -111
  68. data/lib/square/exceptions/validation_exception.rb +0 -13
  69. data/lib/square/http/faraday_client.rb +0 -93
  70. data/lib/square/http/http_client.rb +0 -118
  71. data/test/test_helper.rb +0 -89
@@ -1,10 +1,6 @@
1
1
  module Square
2
2
  # CustomerGroupsApi
3
3
  class CustomerGroupsApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Retrieves the list of customer groups of a business.
9
5
  # @param [String] cursor Optional parameter: A pagination cursor returned by
10
6
  # a previous call to this endpoint. Provide this cursor to retrieve the next
@@ -21,35 +17,19 @@ module Square
21
17
  # @return [ListCustomerGroupsResponse Hash] response from the API call
22
18
  def list_customer_groups(cursor: nil,
23
19
  limit: nil)
24
- # Prepare query url.
25
- _query_builder = config.get_base_uri
26
- _query_builder << '/v2/customers/groups'
27
- _query_builder = APIHelper.append_url_with_query_parameters(
28
- _query_builder,
29
- 'cursor' => cursor,
30
- 'limit' => limit
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(
51
- _response, data: decoded, errors: _errors
52
- )
20
+ new_api_call_builder
21
+ .request(new_request_builder(HttpMethodEnum::GET,
22
+ '/v2/customers/groups',
23
+ 'default')
24
+ .query_param(new_parameter(cursor, key: 'cursor'))
25
+ .query_param(new_parameter(limit, key: 'limit'))
26
+ .header_param(new_parameter('application/json', key: 'accept'))
27
+ .auth(Single.new('global')))
28
+ .response(new_response_handler
29
+ .deserializer(APIHelper.method(:json_deserialize))
30
+ .is_api_response(true)
31
+ .convertor(ApiResponse.method(:create)))
32
+ .execute
53
33
  end
54
34
 
55
35
  # Creates a new customer group for a business.
@@ -59,32 +39,20 @@ module Square
59
39
  # object definition for field details.
60
40
  # @return [CreateCustomerGroupResponse Hash] response from the API call
61
41
  def create_customer_group(body:)
62
- # Prepare query url.
63
- _query_builder = config.get_base_uri
64
- _query_builder << '/v2/customers/groups'
65
- _query_url = APIHelper.clean_url _query_builder
66
-
67
- # Prepare headers.
68
- _headers = {
69
- 'accept' => 'application/json',
70
- 'Content-Type' => 'application/json'
71
- }
72
-
73
- # Prepare and execute HttpRequest.
74
- _request = config.http_client.post(
75
- _query_url,
76
- headers: _headers,
77
- parameters: body.to_json
78
- )
79
- OAuth2.apply(config, _request)
80
- _response = execute_request(_request)
81
-
82
- # Return appropriate response type.
83
- decoded = APIHelper.json_deserialize(_response.raw_body)
84
- _errors = APIHelper.map_response(decoded, ['errors'])
85
- ApiResponse.new(
86
- _response, data: decoded, errors: _errors
87
- )
42
+ new_api_call_builder
43
+ .request(new_request_builder(HttpMethodEnum::POST,
44
+ '/v2/customers/groups',
45
+ 'default')
46
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
47
+ .body_param(new_parameter(body))
48
+ .header_param(new_parameter('application/json', key: 'accept'))
49
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
50
+ .auth(Single.new('global')))
51
+ .response(new_response_handler
52
+ .deserializer(APIHelper.method(:json_deserialize))
53
+ .is_api_response(true)
54
+ .convertor(ApiResponse.method(:create)))
55
+ .execute
88
56
  end
89
57
 
90
58
  # Deletes a customer group as identified by the `group_id` value.
@@ -92,34 +60,19 @@ module Square
92
60
  # to delete.
93
61
  # @return [DeleteCustomerGroupResponse Hash] response from the API call
94
62
  def delete_customer_group(group_id:)
95
- # Prepare query url.
96
- _query_builder = config.get_base_uri
97
- _query_builder << '/v2/customers/groups/{group_id}'
98
- _query_builder = APIHelper.append_url_with_template_parameters(
99
- _query_builder,
100
- 'group_id' => { 'value' => group_id, 'encode' => true }
101
- )
102
- _query_url = APIHelper.clean_url _query_builder
103
-
104
- # Prepare headers.
105
- _headers = {
106
- 'accept' => 'application/json'
107
- }
108
-
109
- # Prepare and execute HttpRequest.
110
- _request = config.http_client.delete(
111
- _query_url,
112
- headers: _headers
113
- )
114
- OAuth2.apply(config, _request)
115
- _response = execute_request(_request)
116
-
117
- # Return appropriate response type.
118
- decoded = APIHelper.json_deserialize(_response.raw_body)
119
- _errors = APIHelper.map_response(decoded, ['errors'])
120
- ApiResponse.new(
121
- _response, data: decoded, errors: _errors
122
- )
63
+ new_api_call_builder
64
+ .request(new_request_builder(HttpMethodEnum::DELETE,
65
+ '/v2/customers/groups/{group_id}',
66
+ 'default')
67
+ .template_param(new_parameter(group_id, key: 'group_id')
68
+ .should_encode(true))
69
+ .header_param(new_parameter('application/json', key: 'accept'))
70
+ .auth(Single.new('global')))
71
+ .response(new_response_handler
72
+ .deserializer(APIHelper.method(:json_deserialize))
73
+ .is_api_response(true)
74
+ .convertor(ApiResponse.method(:create)))
75
+ .execute
123
76
  end
124
77
 
125
78
  # Retrieves a specific customer group as identified by the `group_id` value.
@@ -127,34 +80,19 @@ module Square
127
80
  # to retrieve.
128
81
  # @return [RetrieveCustomerGroupResponse Hash] response from the API call
129
82
  def retrieve_customer_group(group_id:)
130
- # Prepare query url.
131
- _query_builder = config.get_base_uri
132
- _query_builder << '/v2/customers/groups/{group_id}'
133
- _query_builder = APIHelper.append_url_with_template_parameters(
134
- _query_builder,
135
- 'group_id' => { 'value' => group_id, 'encode' => true }
136
- )
137
- _query_url = APIHelper.clean_url _query_builder
138
-
139
- # Prepare headers.
140
- _headers = {
141
- 'accept' => 'application/json'
142
- }
143
-
144
- # Prepare and execute HttpRequest.
145
- _request = config.http_client.get(
146
- _query_url,
147
- headers: _headers
148
- )
149
- OAuth2.apply(config, _request)
150
- _response = execute_request(_request)
151
-
152
- # Return appropriate response type.
153
- decoded = APIHelper.json_deserialize(_response.raw_body)
154
- _errors = APIHelper.map_response(decoded, ['errors'])
155
- ApiResponse.new(
156
- _response, data: decoded, errors: _errors
157
- )
83
+ new_api_call_builder
84
+ .request(new_request_builder(HttpMethodEnum::GET,
85
+ '/v2/customers/groups/{group_id}',
86
+ 'default')
87
+ .template_param(new_parameter(group_id, key: 'group_id')
88
+ .should_encode(true))
89
+ .header_param(new_parameter('application/json', key: 'accept'))
90
+ .auth(Single.new('global')))
91
+ .response(new_response_handler
92
+ .deserializer(APIHelper.method(:json_deserialize))
93
+ .is_api_response(true)
94
+ .convertor(ApiResponse.method(:create)))
95
+ .execute
158
96
  end
159
97
 
160
98
  # Updates a customer group as identified by the `group_id` value.
@@ -166,36 +104,22 @@ module Square
166
104
  # @return [UpdateCustomerGroupResponse Hash] response from the API call
167
105
  def update_customer_group(group_id:,
168
106
  body:)
169
- # Prepare query url.
170
- _query_builder = config.get_base_uri
171
- _query_builder << '/v2/customers/groups/{group_id}'
172
- _query_builder = APIHelper.append_url_with_template_parameters(
173
- _query_builder,
174
- 'group_id' => { 'value' => group_id, 'encode' => true }
175
- )
176
- _query_url = APIHelper.clean_url _query_builder
177
-
178
- # Prepare headers.
179
- _headers = {
180
- 'accept' => 'application/json',
181
- 'Content-Type' => 'application/json'
182
- }
183
-
184
- # Prepare and execute HttpRequest.
185
- _request = config.http_client.put(
186
- _query_url,
187
- headers: _headers,
188
- parameters: body.to_json
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(
197
- _response, data: decoded, errors: _errors
198
- )
107
+ new_api_call_builder
108
+ .request(new_request_builder(HttpMethodEnum::PUT,
109
+ '/v2/customers/groups/{group_id}',
110
+ 'default')
111
+ .template_param(new_parameter(group_id, key: 'group_id')
112
+ .should_encode(true))
113
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
114
+ .body_param(new_parameter(body))
115
+ .header_param(new_parameter('application/json', key: 'accept'))
116
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
117
+ .auth(Single.new('global')))
118
+ .response(new_response_handler
119
+ .deserializer(APIHelper.method(:json_deserialize))
120
+ .is_api_response(true)
121
+ .convertor(ApiResponse.method(:create)))
122
+ .execute
199
123
  end
200
124
  end
201
125
  end
@@ -1,10 +1,6 @@
1
1
  module Square
2
2
  # CustomerSegmentsApi
3
3
  class CustomerSegmentsApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Retrieves the list of customer segments of a business.
9
5
  # @param [String] cursor Optional parameter: A pagination cursor returned by
10
6
  # previous calls to `ListCustomerSegments`. This cursor is used to retrieve
@@ -21,35 +17,19 @@ module Square
21
17
  # @return [ListCustomerSegmentsResponse Hash] response from the API call
22
18
  def list_customer_segments(cursor: nil,
23
19
  limit: nil)
24
- # Prepare query url.
25
- _query_builder = config.get_base_uri
26
- _query_builder << '/v2/customers/segments'
27
- _query_builder = APIHelper.append_url_with_query_parameters(
28
- _query_builder,
29
- 'cursor' => cursor,
30
- 'limit' => limit
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(
51
- _response, data: decoded, errors: _errors
52
- )
20
+ new_api_call_builder
21
+ .request(new_request_builder(HttpMethodEnum::GET,
22
+ '/v2/customers/segments',
23
+ 'default')
24
+ .query_param(new_parameter(cursor, key: 'cursor'))
25
+ .query_param(new_parameter(limit, key: 'limit'))
26
+ .header_param(new_parameter('application/json', key: 'accept'))
27
+ .auth(Single.new('global')))
28
+ .response(new_response_handler
29
+ .deserializer(APIHelper.method(:json_deserialize))
30
+ .is_api_response(true)
31
+ .convertor(ApiResponse.method(:create)))
32
+ .execute
53
33
  end
54
34
 
55
35
  # Retrieves a specific customer segment as identified by the `segment_id`
@@ -58,34 +38,19 @@ module Square
58
38
  # customer segment.
59
39
  # @return [RetrieveCustomerSegmentResponse Hash] response from the API call
60
40
  def retrieve_customer_segment(segment_id:)
61
- # Prepare query url.
62
- _query_builder = config.get_base_uri
63
- _query_builder << '/v2/customers/segments/{segment_id}'
64
- _query_builder = APIHelper.append_url_with_template_parameters(
65
- _query_builder,
66
- 'segment_id' => { 'value' => segment_id, 'encode' => true }
67
- )
68
- _query_url = APIHelper.clean_url _query_builder
69
-
70
- # Prepare headers.
71
- _headers = {
72
- 'accept' => 'application/json'
73
- }
74
-
75
- # Prepare and execute HttpRequest.
76
- _request = config.http_client.get(
77
- _query_url,
78
- headers: _headers
79
- )
80
- OAuth2.apply(config, _request)
81
- _response = execute_request(_request)
82
-
83
- # Return appropriate response type.
84
- decoded = APIHelper.json_deserialize(_response.raw_body)
85
- _errors = APIHelper.map_response(decoded, ['errors'])
86
- ApiResponse.new(
87
- _response, data: decoded, errors: _errors
88
- )
41
+ new_api_call_builder
42
+ .request(new_request_builder(HttpMethodEnum::GET,
43
+ '/v2/customers/segments/{segment_id}',
44
+ 'default')
45
+ .template_param(new_parameter(segment_id, key: 'segment_id')
46
+ .should_encode(true))
47
+ .header_param(new_parameter('application/json', key: 'accept'))
48
+ .auth(Single.new('global')))
49
+ .response(new_response_handler
50
+ .deserializer(APIHelper.method(:json_deserialize))
51
+ .is_api_response(true)
52
+ .convertor(ApiResponse.method(:create)))
53
+ .execute
89
54
  end
90
55
  end
91
56
  end