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
  # CardsApi
3
3
  class CardsApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Retrieves a list of cards owned by the account making the request.
9
5
  # A max of 25 cards will be returned.
10
6
  # @param [String] cursor Optional parameter: A pagination cursor returned by
@@ -29,38 +25,22 @@ module Square
29
25
  include_disabled: false,
30
26
  reference_id: nil,
31
27
  sort_order: nil)
32
- # Prepare query url.
33
- _query_builder = config.get_base_uri
34
- _query_builder << '/v2/cards'
35
- _query_builder = APIHelper.append_url_with_query_parameters(
36
- _query_builder,
37
- 'cursor' => cursor,
38
- 'customer_id' => customer_id,
39
- 'include_disabled' => include_disabled,
40
- 'reference_id' => reference_id,
41
- 'sort_order' => sort_order
42
- )
43
- _query_url = APIHelper.clean_url _query_builder
44
-
45
- # Prepare headers.
46
- _headers = {
47
- 'accept' => 'application/json'
48
- }
49
-
50
- # Prepare and execute HttpRequest.
51
- _request = config.http_client.get(
52
- _query_url,
53
- headers: _headers
54
- )
55
- OAuth2.apply(config, _request)
56
- _response = execute_request(_request)
57
-
58
- # Return appropriate response type.
59
- decoded = APIHelper.json_deserialize(_response.raw_body)
60
- _errors = APIHelper.map_response(decoded, ['errors'])
61
- ApiResponse.new(
62
- _response, data: decoded, errors: _errors
63
- )
28
+ new_api_call_builder
29
+ .request(new_request_builder(HttpMethodEnum::GET,
30
+ '/v2/cards',
31
+ 'default')
32
+ .query_param(new_parameter(cursor, key: 'cursor'))
33
+ .query_param(new_parameter(customer_id, key: 'customer_id'))
34
+ .query_param(new_parameter(include_disabled, key: 'include_disabled'))
35
+ .query_param(new_parameter(reference_id, key: 'reference_id'))
36
+ .query_param(new_parameter(sort_order, key: 'sort_order'))
37
+ .header_param(new_parameter('application/json', key: 'accept'))
38
+ .auth(Single.new('global')))
39
+ .response(new_response_handler
40
+ .deserializer(APIHelper.method(:json_deserialize))
41
+ .is_api_response(true)
42
+ .convertor(ApiResponse.method(:create)))
43
+ .execute
64
44
  end
65
45
 
66
46
  # Adds a card on file to an existing merchant.
@@ -69,32 +49,20 @@ module Square
69
49
  # definition for field details.
70
50
  # @return [CreateCardResponse Hash] response from the API call
71
51
  def create_card(body:)
72
- # Prepare query url.
73
- _query_builder = config.get_base_uri
74
- _query_builder << '/v2/cards'
75
- _query_url = APIHelper.clean_url _query_builder
76
-
77
- # Prepare headers.
78
- _headers = {
79
- 'accept' => 'application/json',
80
- 'Content-Type' => 'application/json'
81
- }
82
-
83
- # Prepare and execute HttpRequest.
84
- _request = config.http_client.post(
85
- _query_url,
86
- headers: _headers,
87
- parameters: body.to_json
88
- )
89
- OAuth2.apply(config, _request)
90
- _response = execute_request(_request)
91
-
92
- # Return appropriate response type.
93
- decoded = APIHelper.json_deserialize(_response.raw_body)
94
- _errors = APIHelper.map_response(decoded, ['errors'])
95
- ApiResponse.new(
96
- _response, data: decoded, errors: _errors
97
- )
52
+ new_api_call_builder
53
+ .request(new_request_builder(HttpMethodEnum::POST,
54
+ '/v2/cards',
55
+ 'default')
56
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
57
+ .body_param(new_parameter(body))
58
+ .header_param(new_parameter('application/json', key: 'accept'))
59
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
60
+ .auth(Single.new('global')))
61
+ .response(new_response_handler
62
+ .deserializer(APIHelper.method(:json_deserialize))
63
+ .is_api_response(true)
64
+ .convertor(ApiResponse.method(:create)))
65
+ .execute
98
66
  end
99
67
 
100
68
  # Retrieves details for a specific Card.
@@ -102,34 +70,19 @@ module Square
102
70
  # Card.
103
71
  # @return [RetrieveCardResponse Hash] response from the API call
104
72
  def retrieve_card(card_id:)
105
- # Prepare query url.
106
- _query_builder = config.get_base_uri
107
- _query_builder << '/v2/cards/{card_id}'
108
- _query_builder = APIHelper.append_url_with_template_parameters(
109
- _query_builder,
110
- 'card_id' => { 'value' => card_id, 'encode' => true }
111
- )
112
- _query_url = APIHelper.clean_url _query_builder
113
-
114
- # Prepare headers.
115
- _headers = {
116
- 'accept' => 'application/json'
117
- }
118
-
119
- # Prepare and execute HttpRequest.
120
- _request = config.http_client.get(
121
- _query_url,
122
- headers: _headers
123
- )
124
- OAuth2.apply(config, _request)
125
- _response = execute_request(_request)
126
-
127
- # Return appropriate response type.
128
- decoded = APIHelper.json_deserialize(_response.raw_body)
129
- _errors = APIHelper.map_response(decoded, ['errors'])
130
- ApiResponse.new(
131
- _response, data: decoded, errors: _errors
132
- )
73
+ new_api_call_builder
74
+ .request(new_request_builder(HttpMethodEnum::GET,
75
+ '/v2/cards/{card_id}',
76
+ 'default')
77
+ .template_param(new_parameter(card_id, key: 'card_id')
78
+ .should_encode(true))
79
+ .header_param(new_parameter('application/json', key: 'accept'))
80
+ .auth(Single.new('global')))
81
+ .response(new_response_handler
82
+ .deserializer(APIHelper.method(:json_deserialize))
83
+ .is_api_response(true)
84
+ .convertor(ApiResponse.method(:create)))
85
+ .execute
133
86
  end
134
87
 
135
88
  # Disables the card, preventing any further updates or charges.
@@ -138,34 +91,19 @@ module Square
138
91
  # Card.
139
92
  # @return [DisableCardResponse Hash] response from the API call
140
93
  def disable_card(card_id:)
141
- # Prepare query url.
142
- _query_builder = config.get_base_uri
143
- _query_builder << '/v2/cards/{card_id}/disable'
144
- _query_builder = APIHelper.append_url_with_template_parameters(
145
- _query_builder,
146
- 'card_id' => { 'value' => card_id, 'encode' => true }
147
- )
148
- _query_url = APIHelper.clean_url _query_builder
149
-
150
- # Prepare headers.
151
- _headers = {
152
- 'accept' => 'application/json'
153
- }
154
-
155
- # Prepare and execute HttpRequest.
156
- _request = config.http_client.post(
157
- _query_url,
158
- headers: _headers
159
- )
160
- OAuth2.apply(config, _request)
161
- _response = execute_request(_request)
162
-
163
- # Return appropriate response type.
164
- decoded = APIHelper.json_deserialize(_response.raw_body)
165
- _errors = APIHelper.map_response(decoded, ['errors'])
166
- ApiResponse.new(
167
- _response, data: decoded, errors: _errors
168
- )
94
+ new_api_call_builder
95
+ .request(new_request_builder(HttpMethodEnum::POST,
96
+ '/v2/cards/{card_id}/disable',
97
+ 'default')
98
+ .template_param(new_parameter(card_id, key: 'card_id')
99
+ .should_encode(true))
100
+ .header_param(new_parameter('application/json', key: 'accept'))
101
+ .auth(Single.new('global')))
102
+ .response(new_response_handler
103
+ .deserializer(APIHelper.method(:json_deserialize))
104
+ .is_api_response(true)
105
+ .convertor(ApiResponse.method(:create)))
106
+ .execute
169
107
  end
170
108
  end
171
109
  end
@@ -1,10 +1,6 @@
1
1
  module Square
2
2
  # CashDrawersApi
3
3
  class CashDrawersApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Provides the details for all of the cash drawer shifts for a location
9
5
  # in a date range.
10
6
  # @param [String] location_id Required parameter: The ID of the location to
@@ -27,39 +23,23 @@ module Square
27
23
  end_time: nil,
28
24
  limit: nil,
29
25
  cursor: nil)
30
- # Prepare query url.
31
- _query_builder = config.get_base_uri
32
- _query_builder << '/v2/cash-drawers/shifts'
33
- _query_builder = APIHelper.append_url_with_query_parameters(
34
- _query_builder,
35
- 'location_id' => location_id,
36
- 'sort_order' => sort_order,
37
- 'begin_time' => begin_time,
38
- 'end_time' => end_time,
39
- 'limit' => limit,
40
- 'cursor' => cursor
41
- )
42
- _query_url = APIHelper.clean_url _query_builder
43
-
44
- # Prepare headers.
45
- _headers = {
46
- 'accept' => 'application/json'
47
- }
48
-
49
- # Prepare and execute HttpRequest.
50
- _request = config.http_client.get(
51
- _query_url,
52
- headers: _headers
53
- )
54
- OAuth2.apply(config, _request)
55
- _response = execute_request(_request)
56
-
57
- # Return appropriate response type.
58
- decoded = APIHelper.json_deserialize(_response.raw_body)
59
- _errors = APIHelper.map_response(decoded, ['errors'])
60
- ApiResponse.new(
61
- _response, data: decoded, errors: _errors
62
- )
26
+ new_api_call_builder
27
+ .request(new_request_builder(HttpMethodEnum::GET,
28
+ '/v2/cash-drawers/shifts',
29
+ 'default')
30
+ .query_param(new_parameter(location_id, key: 'location_id'))
31
+ .query_param(new_parameter(sort_order, key: 'sort_order'))
32
+ .query_param(new_parameter(begin_time, key: 'begin_time'))
33
+ .query_param(new_parameter(end_time, key: 'end_time'))
34
+ .query_param(new_parameter(limit, key: 'limit'))
35
+ .query_param(new_parameter(cursor, key: 'cursor'))
36
+ .header_param(new_parameter('application/json', key: 'accept'))
37
+ .auth(Single.new('global')))
38
+ .response(new_response_handler
39
+ .deserializer(APIHelper.method(:json_deserialize))
40
+ .is_api_response(true)
41
+ .convertor(ApiResponse.method(:create)))
42
+ .execute
63
43
  end
64
44
 
65
45
  # Provides the summary details for a single cash drawer shift. See
@@ -71,38 +51,20 @@ module Square
71
51
  # @return [RetrieveCashDrawerShiftResponse Hash] response from the API call
72
52
  def retrieve_cash_drawer_shift(location_id:,
73
53
  shift_id:)
74
- # Prepare query url.
75
- _query_builder = config.get_base_uri
76
- _query_builder << '/v2/cash-drawers/shifts/{shift_id}'
77
- _query_builder = APIHelper.append_url_with_template_parameters(
78
- _query_builder,
79
- 'shift_id' => { 'value' => shift_id, 'encode' => true }
80
- )
81
- _query_builder = APIHelper.append_url_with_query_parameters(
82
- _query_builder,
83
- 'location_id' => location_id
84
- )
85
- _query_url = APIHelper.clean_url _query_builder
86
-
87
- # Prepare headers.
88
- _headers = {
89
- 'accept' => 'application/json'
90
- }
91
-
92
- # Prepare and execute HttpRequest.
93
- _request = config.http_client.get(
94
- _query_url,
95
- headers: _headers
96
- )
97
- OAuth2.apply(config, _request)
98
- _response = execute_request(_request)
99
-
100
- # Return appropriate response type.
101
- decoded = APIHelper.json_deserialize(_response.raw_body)
102
- _errors = APIHelper.map_response(decoded, ['errors'])
103
- ApiResponse.new(
104
- _response, data: decoded, errors: _errors
105
- )
54
+ new_api_call_builder
55
+ .request(new_request_builder(HttpMethodEnum::GET,
56
+ '/v2/cash-drawers/shifts/{shift_id}',
57
+ 'default')
58
+ .query_param(new_parameter(location_id, key: 'location_id'))
59
+ .template_param(new_parameter(shift_id, key: 'shift_id')
60
+ .should_encode(true))
61
+ .header_param(new_parameter('application/json', key: 'accept'))
62
+ .auth(Single.new('global')))
63
+ .response(new_response_handler
64
+ .deserializer(APIHelper.method(:json_deserialize))
65
+ .is_api_response(true)
66
+ .convertor(ApiResponse.method(:create)))
67
+ .execute
106
68
  end
107
69
 
108
70
  # Provides a paginated list of events for a single cash drawer shift.
@@ -118,40 +80,22 @@ module Square
118
80
  shift_id:,
119
81
  limit: nil,
120
82
  cursor: nil)
121
- # Prepare query url.
122
- _query_builder = config.get_base_uri
123
- _query_builder << '/v2/cash-drawers/shifts/{shift_id}/events'
124
- _query_builder = APIHelper.append_url_with_template_parameters(
125
- _query_builder,
126
- 'shift_id' => { 'value' => shift_id, 'encode' => true }
127
- )
128
- _query_builder = APIHelper.append_url_with_query_parameters(
129
- _query_builder,
130
- 'location_id' => location_id,
131
- 'limit' => limit,
132
- 'cursor' => cursor
133
- )
134
- _query_url = APIHelper.clean_url _query_builder
135
-
136
- # Prepare headers.
137
- _headers = {
138
- 'accept' => 'application/json'
139
- }
140
-
141
- # Prepare and execute HttpRequest.
142
- _request = config.http_client.get(
143
- _query_url,
144
- headers: _headers
145
- )
146
- OAuth2.apply(config, _request)
147
- _response = execute_request(_request)
148
-
149
- # Return appropriate response type.
150
- decoded = APIHelper.json_deserialize(_response.raw_body)
151
- _errors = APIHelper.map_response(decoded, ['errors'])
152
- ApiResponse.new(
153
- _response, data: decoded, errors: _errors
154
- )
83
+ new_api_call_builder
84
+ .request(new_request_builder(HttpMethodEnum::GET,
85
+ '/v2/cash-drawers/shifts/{shift_id}/events',
86
+ 'default')
87
+ .query_param(new_parameter(location_id, key: 'location_id'))
88
+ .template_param(new_parameter(shift_id, key: 'shift_id')
89
+ .should_encode(true))
90
+ .query_param(new_parameter(limit, key: 'limit'))
91
+ .query_param(new_parameter(cursor, key: 'cursor'))
92
+ .header_param(new_parameter('application/json', key: 'accept'))
93
+ .auth(Single.new('global')))
94
+ .response(new_response_handler
95
+ .deserializer(APIHelper.method(:json_deserialize))
96
+ .is_api_response(true)
97
+ .convertor(ApiResponse.method(:create)))
98
+ .execute
155
99
  end
156
100
  end
157
101
  end