square.rb 14.1.0.20210915 → 17.0.0.20211215

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +23 -20
  4. data/lib/square/api/apple_pay_api.rb +1 -1
  5. data/lib/square/api/base_api.rb +8 -4
  6. data/lib/square/api/bookings_api.rb +64 -4
  7. data/lib/square/api/cards_api.rb +1 -1
  8. data/lib/square/api/catalog_api.rb +109 -34
  9. data/lib/square/api/checkout_api.rb +1 -1
  10. data/lib/square/api/customer_groups_api.rb +3 -3
  11. data/lib/square/api/customer_segments_api.rb +1 -1
  12. data/lib/square/api/customers_api.rb +5 -5
  13. data/lib/square/api/devices_api.rb +1 -1
  14. data/lib/square/api/disputes_api.rb +1 -1
  15. data/lib/square/api/gift_card_activities_api.rb +26 -20
  16. data/lib/square/api/gift_cards_api.rb +29 -24
  17. data/lib/square/api/inventory_api.rb +6 -6
  18. data/lib/square/api/invoices_api.rb +5 -5
  19. data/lib/square/api/labor_api.rb +6 -6
  20. data/lib/square/api/locations_api.rb +20 -12
  21. data/lib/square/api/loyalty_api.rb +9 -9
  22. data/lib/square/api/mobile_authorization_api.rb +4 -4
  23. data/lib/square/api/o_auth_api.rb +10 -10
  24. data/lib/square/api/orders_api.rb +7 -7
  25. data/lib/square/api/payments_api.rb +12 -6
  26. data/lib/square/api/refunds_api.rb +1 -1
  27. data/lib/square/api/sites_api.rb +2 -1
  28. data/lib/square/api/snippets_api.rb +1 -1
  29. data/lib/square/api/subscriptions_api.rb +159 -16
  30. data/lib/square/api/team_api.rb +6 -6
  31. data/lib/square/api/terminal_api.rb +4 -4
  32. data/lib/square/api/transactions_api.rb +0 -188
  33. data/lib/square/api/v1_transactions_api.rb +2 -2
  34. data/lib/square/client.rb +12 -6
  35. data/lib/square/configuration.rb +23 -15
  36. data/lib/square/http/api_response.rb +1 -1
  37. data/lib/square/http/faraday_client.rb +20 -1
  38. data/test/api/test_locations_api.rb +2 -5
  39. data/test/test_helper.rb +1 -1
  40. metadata +2 -5
data/lib/square/client.rb CHANGED
@@ -4,13 +4,17 @@ module Square
4
4
  attr_reader :config
5
5
 
6
6
  def sdk_version
7
- '14.1.0.20210915'
7
+ '17.0.0.20211215'
8
8
  end
9
9
 
10
10
  def square_version
11
11
  config.square_version
12
12
  end
13
13
 
14
+ def user_agent_detail
15
+ config.user_agent_detail
16
+ end
17
+
14
18
  # Access to mobile_authorization controller.
15
19
  # @return [MobileAuthorizationApi] Returns the controller instance.
16
20
  def mobile_authorization
@@ -209,15 +213,16 @@ module Square
209
213
  @terminal ||= TerminalApi.new config
210
214
  end
211
215
 
212
- def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
213
- backoff_factor: 2,
216
+ def initialize(http_client_instance: nil, timeout: 60, max_retries: 0,
217
+ retry_interval: 1, backoff_factor: 2,
214
218
  retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
215
219
  retry_methods: %i[get put], environment: 'production',
216
220
  custom_url: 'https://connect.squareup.com',
217
- square_version: '2021-09-15', access_token: 'TODO: Replace',
218
- additional_headers: {}, config: nil)
221
+ square_version: '2021-12-15', access_token: '',
222
+ user_agent_detail: '', additional_headers: {}, config: nil)
219
223
  @config = if config.nil?
220
- Configuration.new(timeout: timeout, max_retries: max_retries,
224
+ Configuration.new(http_client_instance: http_client_instance,
225
+ timeout: timeout, max_retries: max_retries,
221
226
  retry_interval: retry_interval,
222
227
  backoff_factor: backoff_factor,
223
228
  retry_statuses: retry_statuses,
@@ -226,6 +231,7 @@ module Square
226
231
  custom_url: custom_url,
227
232
  square_version: square_version,
228
233
  access_token: access_token,
234
+ user_agent_detail: user_agent_detail,
229
235
  additional_headers: additional_headers)
230
236
  else
231
237
  config
@@ -3,26 +3,28 @@ module Square
3
3
  # are configured in this class.
4
4
  class Configuration
5
5
  # The attribute readers for properties.
6
- attr_reader :http_client, :timeout, :max_retries, :retry_interval, :backoff_factor,
7
- :retry_statuses, :retry_methods, :environment, :custom_url, :square_version,
8
- :access_token,
9
-
6
+ attr_reader :http_client, :http_client_instance, :timeout, :max_retries, :retry_interval,
7
+ :backoff_factor, :retry_statuses, :retry_methods, :environment, :custom_url,
8
+ :square_version, :access_token, :user_agent_detail
9
+
10
10
  def additional_headers
11
11
  @additional_headers.clone
12
12
  end
13
13
 
14
-
15
14
  class << self
16
15
  attr_reader :environments
17
16
  end
18
17
 
19
- def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
20
- backoff_factor: 2,
18
+ def initialize(http_client_instance: nil, timeout: 60, max_retries: 0,
19
+ retry_interval: 1, backoff_factor: 2,
21
20
  retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
22
21
  retry_methods: %i[get put], environment: 'production',
23
22
  custom_url: 'https://connect.squareup.com',
24
- square_version: '2021-09-15', access_token: 'TODO: Replace',
25
- additional_headers: {})
23
+ square_version: '2021-12-15', access_token: '',
24
+ user_agent_detail: '', additional_headers: {})
25
+ # The Http Client passed from the sdk user for making requests
26
+ @http_client_instance = http_client_instance
27
+
26
28
  # The value to use for connection timeout
27
29
  @timeout = timeout
28
30
 
@@ -61,10 +63,12 @@ module Square
61
63
  @http_client = create_http_client
62
64
  end
63
65
 
64
- def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
65
- backoff_factor: nil, retry_statuses: nil, retry_methods: nil,
66
- environment: nil, custom_url: nil, square_version: nil,
67
- access_token: nil, additional_headers: nil)
66
+ def clone_with(http_client_instance: nil, timeout: nil, max_retries: nil,
67
+ retry_interval: nil, backoff_factor: nil,
68
+ retry_statuses: nil, retry_methods: nil, environment: nil,
69
+ custom_url: nil, square_version: nil, access_token: nil,
70
+ user_agent_detail: nil, additional_headers: nil)
71
+ http_client_instance ||= self.http_client_instance
68
72
  timeout ||= self.timeout
69
73
  max_retries ||= self.max_retries
70
74
  retry_interval ||= self.retry_interval
@@ -75,15 +79,18 @@ module Square
75
79
  custom_url ||= self.custom_url
76
80
  square_version ||= self.square_version
77
81
  access_token ||= self.access_token
82
+ user_agent_detail ||= self.user_agent_detail
78
83
  additional_headers ||= self.additional_headers
79
84
 
80
- Configuration.new(timeout: timeout, max_retries: max_retries,
85
+ Configuration.new(http_client_instance: http_client_instance,
86
+ timeout: timeout, max_retries: max_retries,
81
87
  retry_interval: retry_interval,
82
88
  backoff_factor: backoff_factor,
83
89
  retry_statuses: retry_statuses,
84
90
  retry_methods: retry_methods, environment: environment,
85
91
  custom_url: custom_url, square_version: square_version,
86
92
  access_token: access_token,
93
+ user_agent_detail: user_agent_detail,
87
94
  additional_headers: additional_headers)
88
95
  end
89
96
 
@@ -92,7 +99,8 @@ module Square
92
99
  retry_interval: retry_interval,
93
100
  backoff_factor: backoff_factor,
94
101
  retry_statuses: retry_statuses,
95
- retry_methods: retry_methods)
102
+ retry_methods: retry_methods,
103
+ http_client_instance: http_client_instance)
96
104
  end
97
105
 
98
106
  # All the environments the SDK can run in.
@@ -25,7 +25,7 @@ module Square
25
25
  end.new(*data.values)
26
26
 
27
27
  @cursor = data.fetch(:cursor, nil)
28
- data.reject! { |k| k == :cursor || k == :errors }
28
+ data.reject! { |k| %i[cursor errors].include?(k) }
29
29
  @data = Struct.new(*data.keys).new(*data.values) if data.keys.any?
30
30
  end
31
31
  else
@@ -7,7 +7,25 @@ module Square
7
7
  # The constructor.
8
8
  def initialize(timeout:, max_retries:, retry_interval:,
9
9
  backoff_factor:, retry_statuses:, retry_methods:,
10
- cache: false, verify: true)
10
+ http_client_instance: nil, cache: false, verify: true)
11
+ if http_client_instance.nil?
12
+ create_connection(timeout: timeout, max_retries: max_retries,
13
+ retry_interval: retry_interval, backoff_factor: backoff_factor,
14
+ retry_statuses: retry_statuses, retry_methods: retry_methods,
15
+ cache: cache, verify: verify)
16
+ else
17
+ if http_client_instance.instance_variable_get('@connection').nil?
18
+ raise ArgumentError,
19
+ "`connection` cannot be nil in `#{self.class}`. Please specify a valid value."
20
+ end
21
+ @connection = http_client_instance.instance_variable_get('@connection')
22
+ end
23
+ end
24
+
25
+ # Method to initialize connection.
26
+ def create_connection(timeout:, max_retries:, retry_interval:,
27
+ backoff_factor:, retry_statuses:, retry_methods:,
28
+ cache: false, verify: true)
11
29
  @connection = Faraday.new do |faraday|
12
30
  faraday.use Faraday::HttpCache, serializer: Marshal if cache
13
31
  faraday.use FaradayMiddleware::FollowRedirects
@@ -24,6 +42,7 @@ module Square
24
42
  faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
25
43
  faraday.options[:timeout] = timeout if timeout.positive?
26
44
  end
45
+ @connection
27
46
  end
28
47
 
29
48
  # Method overridden from HttpClient.
@@ -7,11 +7,8 @@ class LocationsApiTests < ApiTestBase
7
7
  @controller = LocationsApi.new CONFIG, http_call_back: @response_catcher
8
8
  end
9
9
 
10
- # Provides information of all locations of a business.
11
- #
12
- #Many Square API endpoints require a `location_id` parameter.
13
- #The `id` field of the [`Location`]($m/Location) objects returned by this
14
- #endpoint correspond to that `location_id` parameter.
10
+ # Provides details about all of the seller's locations,
11
+ #including those with an inactive status.
15
12
  def test_list_locations()
16
13
 
17
14
  # Perform the API call through the SDK function
data/test/test_helper.rb CHANGED
@@ -82,7 +82,7 @@ class TestHelper
82
82
  unless @cache.keys.include? url
83
83
  @cache[url] = Tempfile.new('APIMatic')
84
84
  @cache[url].binmode
85
- @cache[url].write(open(url, {ssl_ca_cert: Certifi.where}).read)
85
+ @cache[url].write(URI.open(url, {ssl_ca_cert: Certifi.where}).read)
86
86
  end
87
87
  return @cache[url].path
88
88
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: square.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 14.1.0.20210915
4
+ version: 17.0.0.20211215
5
5
  platform: ruby
6
6
  authors:
7
7
  - Square Developer Platform
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-16 00:00:00.000000000 Z
11
+ date: 2021-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logging
@@ -209,9 +209,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
209
  - - ">="
210
210
  - !ruby/object:Gem::Version
211
211
  version: '2.5'
212
- - - "<"
213
- - !ruby/object:Gem::Version
214
- version: '3.0'
215
212
  required_rubygems_version: !ruby/object:Gem::Requirement
216
213
  requirements:
217
214
  - - ">="