square.rb 26.1.0.20230119 → 26.2.0.20230315

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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/square/api/apple_pay_api.rb +14 -30
  3. data/lib/square/api/bank_accounts_api.rb +40 -90
  4. data/lib/square/api/base_api.rb +42 -42
  5. data/lib/square/api/booking_custom_attributes_api.rb +164 -329
  6. data/lib/square/api/bookings_api.rb +135 -260
  7. data/lib/square/api/cards_api.rb +56 -118
  8. data/lib/square/api/cash_drawers_api.rb +47 -103
  9. data/lib/square/api/catalog_api.rb +197 -423
  10. data/lib/square/api/checkout_api.rb +85 -175
  11. data/lib/square/api/customer_custom_attributes_api.rb +150 -303
  12. data/lib/square/api/customer_groups_api.rb +69 -145
  13. data/lib/square/api/customer_segments_api.rb +26 -61
  14. data/lib/square/api/customers_api.rb +147 -294
  15. data/lib/square/api/devices_api.rb +42 -89
  16. data/lib/square/api/disputes_api.rb +130 -288
  17. data/lib/square/api/employees_api.rb +28 -63
  18. data/lib/square/api/gift_card_activities_api.rb +33 -65
  19. data/lib/square/api/gift_cards_api.rb +103 -202
  20. data/lib/square/api/inventory_api.rb +179 -366
  21. data/lib/square/api/invoices_api.rb +118 -237
  22. data/lib/square/api/labor_api.rb +223 -459
  23. data/lib/square/api/location_custom_attributes_api.rb +166 -331
  24. data/lib/square/api/locations_api.rb +54 -112
  25. data/lib/square/api/loyalty_api.rb +259 -512
  26. data/lib/square/api/merchants_api.rb +25 -60
  27. data/lib/square/api/mobile_authorization_api.rb +14 -30
  28. data/lib/square/api/o_auth_api.rb +54 -109
  29. data/lib/square/api/order_custom_attributes_api.rb +168 -333
  30. data/lib/square/api/orders_api.rb +115 -222
  31. data/lib/square/api/payments_api.rb +106 -208
  32. data/lib/square/api/payouts_api.rb +47 -100
  33. data/lib/square/api/refunds_api.rb +46 -93
  34. data/lib/square/api/sites_api.rb +11 -28
  35. data/lib/square/api/snippets_api.rb +42 -90
  36. data/lib/square/api/subscriptions_api.rb +150 -299
  37. data/lib/square/api/team_api.rb +114 -224
  38. data/lib/square/api/terminal_api.rb +162 -328
  39. data/lib/square/api/transactions_api.rb +62 -126
  40. data/lib/square/api/v1_transactions_api.rb +155 -296
  41. data/lib/square/api/vendors_api.rb +99 -192
  42. data/lib/square/api/webhook_subscriptions_api.rb +115 -235
  43. data/lib/square/api_helper.rb +1 -437
  44. data/lib/square/client.rb +77 -47
  45. data/lib/square/configuration.rb +28 -53
  46. data/lib/square/exceptions/api_exception.rb +1 -11
  47. data/lib/square/http/api_response.rb +13 -19
  48. data/lib/square/http/auth/o_auth2.rb +14 -7
  49. data/lib/square/http/http_call_back.rb +1 -15
  50. data/lib/square/http/http_method_enum.rb +1 -4
  51. data/lib/square/http/http_request.rb +1 -45
  52. data/lib/square/http/http_response.rb +1 -20
  53. data/lib/square/utilities/date_time_helper.rb +1 -146
  54. data/lib/square/utilities/file_wrapper.rb +5 -5
  55. data/lib/square.rb +6 -6
  56. data/spec/user_journey_spec.rb +2 -2
  57. data/test/api/api_test_base.rb +13 -5
  58. data/test/api/test_catalog_api.rb +5 -4
  59. data/test/api/test_customers_api.rb +3 -2
  60. data/test/api/test_employees_api.rb +4 -3
  61. data/test/api/test_labor_api.rb +6 -5
  62. data/test/api/test_locations_api.rb +3 -2
  63. data/test/api/test_merchants_api.rb +4 -3
  64. data/test/api/test_payments_api.rb +4 -3
  65. data/test/api/test_refunds_api.rb +4 -3
  66. metadata +11 -111
  67. data/lib/square/exceptions/validation_exception.rb +0 -13
  68. data/lib/square/http/faraday_client.rb +0 -93
  69. data/lib/square/http/http_client.rb +0 -118
  70. data/test/test_helper.rb +0 -89
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac8d00e1d947c816019d207e36e19a85ef2f8d66e3b5c4295e3e19f6cfcd5af6
4
- data.tar.gz: ba91ef39e6e11e16af9a859abe126cd8f25e0d0751a65a101e63dfb0bbbf4718
3
+ metadata.gz: 9fe50fe3512834461866b9d1ebbd83bee0ca14f16313e4928f7ae114105ffc22
4
+ data.tar.gz: e168aac2b86e67820df82977d1cd628f83566abbc77e821f029f509fadb19b5d
5
5
  SHA512:
6
- metadata.gz: 23f2218d4d9757a648c69c5d6d21eb764f121695c6a11ac80607f24bb86301745f410b1103937ad49a157f150784ea1d396ea57393d0743c0742848b8beba0fa
7
- data.tar.gz: fc4af83a8b04a151839c45f6f0c632f2b6b5b65abfcde66027d89714ac8566770b5f70407d021337d7cae3daa67957b06ca373eaf4b3b6791aef13ae1029ca87
6
+ metadata.gz: 1f4960b642816caa0d3aa71aceed7b834ca127c188b4e91098e56beacabb501531e67cf2747bdd3045e3dceedc565d9db9ec99f2fdfd369bdbec2c2bb110ca4d
7
+ data.tar.gz: 745fb7ff183d3445c7edcbe352dbb701597acf2a551971d9cfdd0cfa57e3002a085c3497404b52b49a39d89b7221991f092c14b7fec09352d6fe2b203def7940
@@ -1,10 +1,6 @@
1
1
  module Square
2
2
  # ApplePayApi
3
3
  class ApplePayApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Activates a domain for use with Apple Pay on the Web and Square. A
9
5
  # validation
10
6
  # is performed on this domain by Apple to ensure that it is properly set up
@@ -28,32 +24,20 @@ module Square
28
24
  # object definition for field details.
29
25
  # @return [RegisterDomainResponse Hash] response from the API call
30
26
  def register_domain(body:)
31
- # Prepare query url.
32
- _query_builder = config.get_base_uri
33
- _query_builder << '/v2/apple-pay/domains'
34
- _query_url = APIHelper.clean_url _query_builder
35
-
36
- # Prepare headers.
37
- _headers = {
38
- 'accept' => 'application/json',
39
- 'Content-Type' => 'application/json'
40
- }
41
-
42
- # Prepare and execute HttpRequest.
43
- _request = config.http_client.post(
44
- _query_url,
45
- headers: _headers,
46
- parameters: body.to_json
47
- )
48
- OAuth2.apply(config, _request)
49
- _response = execute_request(_request)
50
-
51
- # Return appropriate response type.
52
- decoded = APIHelper.json_deserialize(_response.raw_body)
53
- _errors = APIHelper.map_response(decoded, ['errors'])
54
- ApiResponse.new(
55
- _response, data: decoded, errors: _errors
56
- )
27
+ new_api_call_builder
28
+ .request(new_request_builder(HttpMethodEnum::POST,
29
+ '/v2/apple-pay/domains',
30
+ 'default')
31
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
32
+ .body_param(new_parameter(body))
33
+ .header_param(new_parameter('application/json', key: 'accept'))
34
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
35
+ .auth(Single.new('global')))
36
+ .response(new_response_handler
37
+ .deserializer(APIHelper.method(:json_deserialize))
38
+ .is_api_response(true)
39
+ .convertor(ApiResponse.method(:create)))
40
+ .execute
57
41
  end
58
42
  end
59
43
  end
@@ -1,10 +1,6 @@
1
1
  module Square
2
2
  # BankAccountsApi
3
3
  class BankAccountsApi < BaseApi
4
- def initialize(config, http_call_back: nil)
5
- super(config, http_call_back: http_call_back)
6
- end
7
-
8
4
  # Returns a list of [BankAccount]($m/BankAccount) objects linked to a Square
9
5
  # account.
10
6
  # @param [String] cursor Optional parameter: The pagination cursor returned
@@ -23,36 +19,20 @@ module Square
23
19
  def list_bank_accounts(cursor: nil,
24
20
  limit: nil,
25
21
  location_id: nil)
26
- # Prepare query url.
27
- _query_builder = config.get_base_uri
28
- _query_builder << '/v2/bank-accounts'
29
- _query_builder = APIHelper.append_url_with_query_parameters(
30
- _query_builder,
31
- 'cursor' => cursor,
32
- 'limit' => limit,
33
- 'location_id' => location_id
34
- )
35
- _query_url = APIHelper.clean_url _query_builder
36
-
37
- # Prepare headers.
38
- _headers = {
39
- 'accept' => 'application/json'
40
- }
41
-
42
- # Prepare and execute HttpRequest.
43
- _request = config.http_client.get(
44
- _query_url,
45
- headers: _headers
46
- )
47
- OAuth2.apply(config, _request)
48
- _response = execute_request(_request)
49
-
50
- # Return appropriate response type.
51
- decoded = APIHelper.json_deserialize(_response.raw_body)
52
- _errors = APIHelper.map_response(decoded, ['errors'])
53
- ApiResponse.new(
54
- _response, data: decoded, errors: _errors
55
- )
22
+ new_api_call_builder
23
+ .request(new_request_builder(HttpMethodEnum::GET,
24
+ '/v2/bank-accounts',
25
+ 'default')
26
+ .query_param(new_parameter(cursor, key: 'cursor'))
27
+ .query_param(new_parameter(limit, key: 'limit'))
28
+ .query_param(new_parameter(location_id, key: 'location_id'))
29
+ .header_param(new_parameter('application/json', key: 'accept'))
30
+ .auth(Single.new('global')))
31
+ .response(new_response_handler
32
+ .deserializer(APIHelper.method(:json_deserialize))
33
+ .is_api_response(true)
34
+ .convertor(ApiResponse.method(:create)))
35
+ .execute
56
36
  end
57
37
 
58
38
  # Returns details of a [BankAccount]($m/BankAccount) identified by V1 bank
@@ -64,34 +44,19 @@ module Square
64
44
  # -account-by-using-an-id-issued-by-v1-bank-accounts-api).
65
45
  # @return [GetBankAccountByV1IdResponse Hash] response from the API call
66
46
  def get_bank_account_by_v1_id(v1_bank_account_id:)
67
- # Prepare query url.
68
- _query_builder = config.get_base_uri
69
- _query_builder << '/v2/bank-accounts/by-v1-id/{v1_bank_account_id}'
70
- _query_builder = APIHelper.append_url_with_template_parameters(
71
- _query_builder,
72
- 'v1_bank_account_id' => { 'value' => v1_bank_account_id, 'encode' => true }
73
- )
74
- _query_url = APIHelper.clean_url _query_builder
75
-
76
- # Prepare headers.
77
- _headers = {
78
- 'accept' => 'application/json'
79
- }
80
-
81
- # Prepare and execute HttpRequest.
82
- _request = config.http_client.get(
83
- _query_url,
84
- headers: _headers
85
- )
86
- OAuth2.apply(config, _request)
87
- _response = execute_request(_request)
88
-
89
- # Return appropriate response type.
90
- decoded = APIHelper.json_deserialize(_response.raw_body)
91
- _errors = APIHelper.map_response(decoded, ['errors'])
92
- ApiResponse.new(
93
- _response, data: decoded, errors: _errors
94
- )
47
+ new_api_call_builder
48
+ .request(new_request_builder(HttpMethodEnum::GET,
49
+ '/v2/bank-accounts/by-v1-id/{v1_bank_account_id}',
50
+ 'default')
51
+ .template_param(new_parameter(v1_bank_account_id, key: 'v1_bank_account_id')
52
+ .should_encode(true))
53
+ .header_param(new_parameter('application/json', key: 'accept'))
54
+ .auth(Single.new('global')))
55
+ .response(new_response_handler
56
+ .deserializer(APIHelper.method(:json_deserialize))
57
+ .is_api_response(true)
58
+ .convertor(ApiResponse.method(:create)))
59
+ .execute
95
60
  end
96
61
 
97
62
  # Returns details of a [BankAccount]($m/BankAccount)
@@ -100,34 +65,19 @@ module Square
100
65
  # the desired `BankAccount`.
101
66
  # @return [GetBankAccountResponse Hash] response from the API call
102
67
  def get_bank_account(bank_account_id:)
103
- # Prepare query url.
104
- _query_builder = config.get_base_uri
105
- _query_builder << '/v2/bank-accounts/{bank_account_id}'
106
- _query_builder = APIHelper.append_url_with_template_parameters(
107
- _query_builder,
108
- 'bank_account_id' => { 'value' => bank_account_id, 'encode' => true }
109
- )
110
- _query_url = APIHelper.clean_url _query_builder
111
-
112
- # Prepare headers.
113
- _headers = {
114
- 'accept' => 'application/json'
115
- }
116
-
117
- # Prepare and execute HttpRequest.
118
- _request = config.http_client.get(
119
- _query_url,
120
- headers: _headers
121
- )
122
- OAuth2.apply(config, _request)
123
- _response = execute_request(_request)
124
-
125
- # Return appropriate response type.
126
- decoded = APIHelper.json_deserialize(_response.raw_body)
127
- _errors = APIHelper.map_response(decoded, ['errors'])
128
- ApiResponse.new(
129
- _response, data: decoded, errors: _errors
130
- )
68
+ new_api_call_builder
69
+ .request(new_request_builder(HttpMethodEnum::GET,
70
+ '/v2/bank-accounts/{bank_account_id}',
71
+ 'default')
72
+ .template_param(new_parameter(bank_account_id, key: 'bank_account_id')
73
+ .should_encode(true))
74
+ .header_param(new_parameter('application/json', key: 'accept'))
75
+ .auth(Single.new('global')))
76
+ .response(new_response_handler
77
+ .deserializer(APIHelper.method(:json_deserialize))
78
+ .is_api_response(true)
79
+ .convertor(ApiResponse.method(:create)))
80
+ .execute
131
81
  end
132
82
  end
133
83
  end
@@ -1,61 +1,61 @@
1
- require 'erb'
2
1
  module Square
3
2
  # BaseApi.
4
3
  class BaseApi
5
4
  attr_accessor :config, :http_call_back
6
5
 
7
- def initialize(config, http_call_back: nil)
8
- @config = config
9
- @http_call_back = http_call_back
6
+ def self.user_agent
7
+ 'Square-Ruby-SDK/26.2.0.20230315 ({api-version}) {engine}/{engine-version} ({os-info}) {detail}'
8
+ end
10
9
 
11
- @global_headers = {
12
- 'user-agent' => get_user_agent,
13
- 'Square-Version' => config.square_version
10
+ def self.user_agent_parameters
11
+ {
12
+ '{engine}' => { 'value' => RUBY_ENGINE, 'encode' => false },
13
+ '{engine-version}' => { 'value' => RUBY_ENGINE_VERSION, 'encode' => false },
14
+ '{os-info}' => { 'value' => RUBY_PLATFORM, 'encode' => false }
14
15
  }
15
16
  end
16
17
 
17
- def validate_parameters(args)
18
- args.each do |_name, value|
19
- raise ArgumentError, "Required parameter #{_name} cannot be nil." if value.nil?
20
- end
18
+ # Initialization constructor.
19
+ # @param [GlobalConfiguration] global_configuration The instance of GlobalConfiguration.
20
+ def initialize(global_configuration)
21
+ @global_configuration = global_configuration
22
+ @config = @global_configuration.client_configuration
23
+ @http_call_back = @config.http_callback
24
+ @api_call = ApiCall.new(@global_configuration)
21
25
  end
22
26
 
23
- def validate_parameters_types(args)
24
- args.each do |_name, type|
25
- key, val = type.first
26
- APIHelper.validate_types(key, val) unless key.nil?
27
- end
27
+ # Creates a new builder for the Api Call instance.
28
+ # @return [ApiCall] The instance of ApiCall.
29
+ def new_api_call_builder
30
+ @api_call.new_builder
28
31
  end
29
32
 
30
- def execute_request(request, binary: false)
31
- @http_call_back&.on_before_request(request)
32
-
33
- APIHelper.clean_hash(request.headers)
34
- request.headers.merge!(@global_headers)
35
- request.headers.merge!(config.additional_headers) unless config.additional_headers.nil?
36
-
37
- response = if binary
38
- config.http_client.execute_as_binary(request)
39
- else
40
- config.http_client.execute_as_string(request)
41
- end
42
- @http_call_back&.on_after_response(response)
33
+ # Creates a new instance of the request builder.
34
+ # @param [HttpMethodEnum] http_method The HTTP method to use in the request.
35
+ # @param [String] path The endpoint path to use in the request.
36
+ # @param [String] server The server to extract the base uri for the request.
37
+ # @return [RequestBuilder] The instance of RequestBuilder.
38
+ def new_request_builder(http_method, path, server)
39
+ RequestBuilder.new
40
+ .http_method(http_method)
41
+ .path(path)
42
+ .server(server)
43
+ end
43
44
 
44
- response
45
+ # Creates a new instance of the response handler.
46
+ # @return [ResponseHandler] The instance of ResponseHandler.
47
+ def new_response_handler
48
+ ResponseHandler.new
45
49
  end
46
50
 
47
- def get_user_agent
48
- user_agent = 'Square-Ruby-SDK/26.1.0.20230119 ({api-version}) {engine}/{engine-version} ({os-info}) {detail}'
49
- user_agent['{engine}'] = RUBY_ENGINE
50
- user_agent['{engine-version}'] = RUBY_ENGINE_VERSION
51
- user_agent['{os-info}'] = RUBY_PLATFORM
52
- user_agent['{api-version}'] = config.square_version
53
- if config.user_agent_detail.nil? || config.user_agent_detail.empty?
54
- user_agent = user_agent.gsub('{detail}', '')
55
- else
56
- user_agent['{detail}'] = ERB::Util.url_encode(config.user_agent_detail.to_s)
57
- end
58
- user_agent
51
+ # Creates a new instance of the parameter.
52
+ # @param [String|optional] key The key of the parameter.
53
+ # @param [Object] value The value of the parameter.
54
+ # @return [Parameter] The instance of Parameter.
55
+ def new_parameter(value, key: nil)
56
+ Parameter.new
57
+ .key(key)
58
+ .value(value)
59
59
  end
60
60
  end
61
61
  end