square.rb 3.20190624.0 → 3.20190814.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +10 -28
- data/README.md +281 -17235
- data/lib/square/api/apple_pay_api.rb +55 -54
- data/lib/square/api/base_api.rb +45 -45
- data/lib/square/api/catalog_api.rb +461 -460
- data/lib/square/api/checkout_api.rb +54 -54
- data/lib/square/api/customers_api.rb +335 -334
- data/lib/square/api/employees_api.rb +91 -91
- data/lib/square/api/inventory_api.rb +300 -298
- data/lib/square/api/labor_api.rb +558 -558
- data/lib/square/api/locations_api.rb +45 -45
- data/lib/square/api/mobile_authorization_api.rb +56 -56
- data/lib/square/api/o_auth_api.rb +168 -164
- data/lib/square/api/orders_api.rb +269 -151
- data/lib/square/api/payments_api.rb +282 -0
- data/lib/square/api/refunds_api.rb +149 -0
- data/lib/square/api/reporting_api.rb +143 -139
- data/lib/square/api/transactions_api.rb +379 -360
- data/lib/square/api/v1_employees_api.rb +720 -720
- data/lib/square/api/v1_items_api.rb +1651 -1651
- data/lib/square/api/v1_locations_api.rb +67 -67
- data/lib/square/api/v1_locations_api.rbe +67 -0
- data/lib/square/api/v1_transactions_api.rb +574 -574
- data/lib/square/api_helper.rb +281 -277
- data/lib/square/client.rb +139 -127
- data/lib/square/configuration.rb +88 -85
- data/lib/square/exceptions/api_exception.rb +20 -20
- data/lib/square/http/api_response.rb +50 -50
- data/lib/square/http/auth/o_auth2.rb +17 -17
- data/lib/square/http/faraday_client.rb +64 -64
- data/lib/square/http/http_call_back.rb +24 -24
- data/lib/square/http/http_client.rb +104 -104
- data/lib/square/http/http_method_enum.rb +13 -13
- data/lib/square/http/http_request.rb +50 -50
- data/lib/square/http/http_response.rb +29 -29
- data/lib/square.rb +52 -50
- data/spec/user_journey_spec.rb +4 -1
- data/test/api/api_test_base.rb +2 -1
- data/test/api/test_catalog_api.rb +59 -0
- data/test/api/test_employees_api.rb +36 -0
- data/test/api/test_locations_api.rb +35 -0
- data/test/api/test_payments_api.rb +42 -0
- data/test/api/test_refunds_api.rb +41 -0
- metadata +19 -11
data/lib/square/client.rb
CHANGED
@@ -1,127 +1,139 @@
|
|
1
|
-
# square
|
2
|
-
#
|
3
|
-
# This file was automatically generated by APIMATIC v2.0
|
4
|
-
# ( https://apimatic.io ).
|
5
|
-
|
6
|
-
module Square
|
7
|
-
# square client class.
|
8
|
-
class Client
|
9
|
-
attr_reader :config
|
10
|
-
|
11
|
-
# Access to mobile_authorization controller.
|
12
|
-
# @return [MobileAuthorizationApi] Returns the controller instance.
|
13
|
-
def mobile_authorization
|
14
|
-
@mobile_authorization ||= MobileAuthorizationApi.new config
|
15
|
-
end
|
16
|
-
|
17
|
-
# Access to o_auth controller.
|
18
|
-
# @return [OAuthApi] Returns the controller instance.
|
19
|
-
def o_auth
|
20
|
-
@o_auth ||= OAuthApi.new config
|
21
|
-
end
|
22
|
-
|
23
|
-
# Access to v1_locations controller.
|
24
|
-
# @return [V1LocationsApi] Returns the controller instance.
|
25
|
-
def v1_locations
|
26
|
-
@v1_locations ||= V1LocationsApi.new config
|
27
|
-
end
|
28
|
-
|
29
|
-
# Access to v1_employees controller.
|
30
|
-
# @return [V1EmployeesApi] Returns the controller instance.
|
31
|
-
def v1_employees
|
32
|
-
@v1_employees ||= V1EmployeesApi.new config
|
33
|
-
end
|
34
|
-
|
35
|
-
# Access to v1_transactions controller.
|
36
|
-
# @return [V1TransactionsApi] Returns the controller instance.
|
37
|
-
def v1_transactions
|
38
|
-
@v1_transactions ||= V1TransactionsApi.new config
|
39
|
-
end
|
40
|
-
|
41
|
-
# Access to v1_items controller.
|
42
|
-
# @return [V1ItemsApi] Returns the controller instance.
|
43
|
-
def v1_items
|
44
|
-
@v1_items ||= V1ItemsApi.new config
|
45
|
-
end
|
46
|
-
|
47
|
-
# Access to apple_pay controller.
|
48
|
-
# @return [ApplePayApi] Returns the controller instance.
|
49
|
-
def apple_pay
|
50
|
-
@apple_pay ||= ApplePayApi.new config
|
51
|
-
end
|
52
|
-
|
53
|
-
# Access to catalog controller.
|
54
|
-
# @return [CatalogApi] Returns the controller instance.
|
55
|
-
def catalog
|
56
|
-
@catalog ||= CatalogApi.new config
|
57
|
-
end
|
58
|
-
|
59
|
-
# Access to customers controller.
|
60
|
-
# @return [CustomersApi] Returns the controller instance.
|
61
|
-
def customers
|
62
|
-
@customers ||= CustomersApi.new config
|
63
|
-
end
|
64
|
-
|
65
|
-
# Access to employees controller.
|
66
|
-
# @return [EmployeesApi] Returns the controller instance.
|
67
|
-
def employees
|
68
|
-
@employees ||= EmployeesApi.new config
|
69
|
-
end
|
70
|
-
|
71
|
-
# Access to inventory controller.
|
72
|
-
# @return [InventoryApi] Returns the controller instance.
|
73
|
-
def inventory
|
74
|
-
@inventory ||= InventoryApi.new config
|
75
|
-
end
|
76
|
-
|
77
|
-
# Access to labor controller.
|
78
|
-
# @return [LaborApi] Returns the controller instance.
|
79
|
-
def labor
|
80
|
-
@labor ||= LaborApi.new config
|
81
|
-
end
|
82
|
-
|
83
|
-
# Access to locations controller.
|
84
|
-
# @return [LocationsApi] Returns the controller instance.
|
85
|
-
def locations
|
86
|
-
@locations ||= LocationsApi.new config
|
87
|
-
end
|
88
|
-
|
89
|
-
# Access to reporting controller.
|
90
|
-
# @return [ReportingApi] Returns the controller instance.
|
91
|
-
def reporting
|
92
|
-
@reporting ||= ReportingApi.new config
|
93
|
-
end
|
94
|
-
|
95
|
-
# Access to checkout controller.
|
96
|
-
# @return [CheckoutApi] Returns the controller instance.
|
97
|
-
def checkout
|
98
|
-
@checkout ||= CheckoutApi.new config
|
99
|
-
end
|
100
|
-
|
101
|
-
# Access to orders controller.
|
102
|
-
# @return [OrdersApi] Returns the controller instance.
|
103
|
-
def orders
|
104
|
-
@orders ||= OrdersApi.new config
|
105
|
-
end
|
106
|
-
|
107
|
-
# Access to transactions controller.
|
108
|
-
# @return [TransactionsApi] Returns the controller instance.
|
109
|
-
def transactions
|
110
|
-
@transactions ||= TransactionsApi.new config
|
111
|
-
end
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
@
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
1
|
+
# square
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Square
|
7
|
+
# square client class.
|
8
|
+
class Client
|
9
|
+
attr_reader :config
|
10
|
+
|
11
|
+
# Access to mobile_authorization controller.
|
12
|
+
# @return [MobileAuthorizationApi] Returns the controller instance.
|
13
|
+
def mobile_authorization
|
14
|
+
@mobile_authorization ||= MobileAuthorizationApi.new config
|
15
|
+
end
|
16
|
+
|
17
|
+
# Access to o_auth controller.
|
18
|
+
# @return [OAuthApi] Returns the controller instance.
|
19
|
+
def o_auth
|
20
|
+
@o_auth ||= OAuthApi.new config
|
21
|
+
end
|
22
|
+
|
23
|
+
# Access to v1_locations controller.
|
24
|
+
# @return [V1LocationsApi] Returns the controller instance.
|
25
|
+
def v1_locations
|
26
|
+
@v1_locations ||= V1LocationsApi.new config
|
27
|
+
end
|
28
|
+
|
29
|
+
# Access to v1_employees controller.
|
30
|
+
# @return [V1EmployeesApi] Returns the controller instance.
|
31
|
+
def v1_employees
|
32
|
+
@v1_employees ||= V1EmployeesApi.new config
|
33
|
+
end
|
34
|
+
|
35
|
+
# Access to v1_transactions controller.
|
36
|
+
# @return [V1TransactionsApi] Returns the controller instance.
|
37
|
+
def v1_transactions
|
38
|
+
@v1_transactions ||= V1TransactionsApi.new config
|
39
|
+
end
|
40
|
+
|
41
|
+
# Access to v1_items controller.
|
42
|
+
# @return [V1ItemsApi] Returns the controller instance.
|
43
|
+
def v1_items
|
44
|
+
@v1_items ||= V1ItemsApi.new config
|
45
|
+
end
|
46
|
+
|
47
|
+
# Access to apple_pay controller.
|
48
|
+
# @return [ApplePayApi] Returns the controller instance.
|
49
|
+
def apple_pay
|
50
|
+
@apple_pay ||= ApplePayApi.new config
|
51
|
+
end
|
52
|
+
|
53
|
+
# Access to catalog controller.
|
54
|
+
# @return [CatalogApi] Returns the controller instance.
|
55
|
+
def catalog
|
56
|
+
@catalog ||= CatalogApi.new config
|
57
|
+
end
|
58
|
+
|
59
|
+
# Access to customers controller.
|
60
|
+
# @return [CustomersApi] Returns the controller instance.
|
61
|
+
def customers
|
62
|
+
@customers ||= CustomersApi.new config
|
63
|
+
end
|
64
|
+
|
65
|
+
# Access to employees controller.
|
66
|
+
# @return [EmployeesApi] Returns the controller instance.
|
67
|
+
def employees
|
68
|
+
@employees ||= EmployeesApi.new config
|
69
|
+
end
|
70
|
+
|
71
|
+
# Access to inventory controller.
|
72
|
+
# @return [InventoryApi] Returns the controller instance.
|
73
|
+
def inventory
|
74
|
+
@inventory ||= InventoryApi.new config
|
75
|
+
end
|
76
|
+
|
77
|
+
# Access to labor controller.
|
78
|
+
# @return [LaborApi] Returns the controller instance.
|
79
|
+
def labor
|
80
|
+
@labor ||= LaborApi.new config
|
81
|
+
end
|
82
|
+
|
83
|
+
# Access to locations controller.
|
84
|
+
# @return [LocationsApi] Returns the controller instance.
|
85
|
+
def locations
|
86
|
+
@locations ||= LocationsApi.new config
|
87
|
+
end
|
88
|
+
|
89
|
+
# Access to reporting controller.
|
90
|
+
# @return [ReportingApi] Returns the controller instance.
|
91
|
+
def reporting
|
92
|
+
@reporting ||= ReportingApi.new config
|
93
|
+
end
|
94
|
+
|
95
|
+
# Access to checkout controller.
|
96
|
+
# @return [CheckoutApi] Returns the controller instance.
|
97
|
+
def checkout
|
98
|
+
@checkout ||= CheckoutApi.new config
|
99
|
+
end
|
100
|
+
|
101
|
+
# Access to orders controller.
|
102
|
+
# @return [OrdersApi] Returns the controller instance.
|
103
|
+
def orders
|
104
|
+
@orders ||= OrdersApi.new config
|
105
|
+
end
|
106
|
+
|
107
|
+
# Access to transactions controller.
|
108
|
+
# @return [TransactionsApi] Returns the controller instance.
|
109
|
+
def transactions
|
110
|
+
@transactions ||= TransactionsApi.new config
|
111
|
+
end
|
112
|
+
|
113
|
+
# Access to payments controller.
|
114
|
+
# @return [PaymentsApi] Returns the controller instance.
|
115
|
+
def payments
|
116
|
+
@payments ||= PaymentsApi.new config
|
117
|
+
end
|
118
|
+
|
119
|
+
# Access to refunds controller.
|
120
|
+
# @return [RefundsApi] Returns the controller instance.
|
121
|
+
def refunds
|
122
|
+
@refunds ||= RefundsApi.new config
|
123
|
+
end
|
124
|
+
|
125
|
+
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
|
126
|
+
backoff_factor: 1, environment: 'production',
|
127
|
+
access_token: 'TODO: Replace', config: nil)
|
128
|
+
@config = if config.nil?
|
129
|
+
Configuration.new(timeout: timeout, max_retries: max_retries,
|
130
|
+
retry_interval: retry_interval,
|
131
|
+
backoff_factor: backoff_factor,
|
132
|
+
environment: environment,
|
133
|
+
access_token: access_token)
|
134
|
+
else
|
135
|
+
config
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/lib/square/configuration.rb
CHANGED
@@ -1,85 +1,88 @@
|
|
1
|
-
# square
|
2
|
-
#
|
3
|
-
# This file was automatically generated by APIMATIC v2.0
|
4
|
-
# ( https://apimatic.io ).
|
5
|
-
|
6
|
-
module Square
|
7
|
-
# All configuration including auth info and base URI for the API access
|
8
|
-
# are configured in this class.
|
9
|
-
class Configuration
|
10
|
-
# The attribute readers for properties.
|
11
|
-
attr_reader :http_client
|
12
|
-
attr_reader :timeout
|
13
|
-
attr_reader :max_retries
|
14
|
-
attr_reader :retry_interval
|
15
|
-
attr_reader :backoff_factor
|
16
|
-
attr_reader :environment
|
17
|
-
attr_reader :access_token
|
18
|
-
|
19
|
-
class << self
|
20
|
-
attr_reader :environments
|
21
|
-
end
|
22
|
-
|
23
|
-
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
|
24
|
-
backoff_factor: 1, environment: 'production',
|
25
|
-
access_token: 'TODO: Replace')
|
26
|
-
# The value to use for connection timeout
|
27
|
-
@timeout = timeout
|
28
|
-
|
29
|
-
# The number of times to retry an endpoint call if it fails
|
30
|
-
@max_retries = max_retries
|
31
|
-
|
32
|
-
# Pause in seconds between retries
|
33
|
-
@retry_interval = retry_interval
|
34
|
-
|
35
|
-
# The amount to multiply each successive retry's interval amount
|
36
|
-
# by in order to provide backoff
|
37
|
-
@backoff_factor = backoff_factor
|
38
|
-
|
39
|
-
# Current API environment
|
40
|
-
@environment = environment
|
41
|
-
|
42
|
-
# OAuth 2.0 Access Token
|
43
|
-
@access_token = access_token
|
44
|
-
|
45
|
-
# The Http Client to use for making requests.
|
46
|
-
@http_client = create_http_client
|
47
|
-
end
|
48
|
-
|
49
|
-
def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
|
50
|
-
backoff_factor: nil, environment: nil, access_token: nil)
|
51
|
-
timeout ||= self.timeout
|
52
|
-
max_retries ||= self.max_retries
|
53
|
-
retry_interval ||= self.retry_interval
|
54
|
-
backoff_factor ||= self.backoff_factor
|
55
|
-
environment ||= self.environment
|
56
|
-
access_token ||= self.access_token
|
57
|
-
|
58
|
-
Configuration.new(timeout: timeout, max_retries: max_retries,
|
59
|
-
retry_interval: retry_interval,
|
60
|
-
backoff_factor: backoff_factor,
|
61
|
-
environment: environment, access_token: access_token)
|
62
|
-
end
|
63
|
-
|
64
|
-
def create_http_client
|
65
|
-
FaradayClient.new(timeout: timeout, max_retries: max_retries,
|
66
|
-
retry_interval: retry_interval,
|
67
|
-
backoff_factor: backoff_factor)
|
68
|
-
end
|
69
|
-
|
70
|
-
# All the environments the SDK can run in.
|
71
|
-
@environments = {
|
72
|
-
'production' => {
|
73
|
-
'default' => 'https://connect.squareup.com'
|
74
|
-
}
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
#
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
1
|
+
# square
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Square
|
7
|
+
# All configuration including auth info and base URI for the API access
|
8
|
+
# are configured in this class.
|
9
|
+
class Configuration
|
10
|
+
# The attribute readers for properties.
|
11
|
+
attr_reader :http_client
|
12
|
+
attr_reader :timeout
|
13
|
+
attr_reader :max_retries
|
14
|
+
attr_reader :retry_interval
|
15
|
+
attr_reader :backoff_factor
|
16
|
+
attr_reader :environment
|
17
|
+
attr_reader :access_token
|
18
|
+
|
19
|
+
class << self
|
20
|
+
attr_reader :environments
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
|
24
|
+
backoff_factor: 1, environment: 'production',
|
25
|
+
access_token: 'TODO: Replace')
|
26
|
+
# The value to use for connection timeout
|
27
|
+
@timeout = timeout
|
28
|
+
|
29
|
+
# The number of times to retry an endpoint call if it fails
|
30
|
+
@max_retries = max_retries
|
31
|
+
|
32
|
+
# Pause in seconds between retries
|
33
|
+
@retry_interval = retry_interval
|
34
|
+
|
35
|
+
# The amount to multiply each successive retry's interval amount
|
36
|
+
# by in order to provide backoff
|
37
|
+
@backoff_factor = backoff_factor
|
38
|
+
|
39
|
+
# Current API environment
|
40
|
+
@environment = environment
|
41
|
+
|
42
|
+
# OAuth 2.0 Access Token
|
43
|
+
@access_token = access_token
|
44
|
+
|
45
|
+
# The Http Client to use for making requests.
|
46
|
+
@http_client = create_http_client
|
47
|
+
end
|
48
|
+
|
49
|
+
def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
|
50
|
+
backoff_factor: nil, environment: nil, access_token: nil)
|
51
|
+
timeout ||= self.timeout
|
52
|
+
max_retries ||= self.max_retries
|
53
|
+
retry_interval ||= self.retry_interval
|
54
|
+
backoff_factor ||= self.backoff_factor
|
55
|
+
environment ||= self.environment
|
56
|
+
access_token ||= self.access_token
|
57
|
+
|
58
|
+
Configuration.new(timeout: timeout, max_retries: max_retries,
|
59
|
+
retry_interval: retry_interval,
|
60
|
+
backoff_factor: backoff_factor,
|
61
|
+
environment: environment, access_token: access_token)
|
62
|
+
end
|
63
|
+
|
64
|
+
def create_http_client
|
65
|
+
FaradayClient.new(timeout: timeout, max_retries: max_retries,
|
66
|
+
retry_interval: retry_interval,
|
67
|
+
backoff_factor: backoff_factor)
|
68
|
+
end
|
69
|
+
|
70
|
+
# All the environments the SDK can run in.
|
71
|
+
@environments = {
|
72
|
+
'production' => {
|
73
|
+
'default' => 'https://connect.squareup.com'
|
74
|
+
},
|
75
|
+
'sandbox' => {
|
76
|
+
'default' => 'https://connect.squareupsandbox.com'
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
# Generates the appropriate base URI for the environment and the server.
|
81
|
+
# @param [Configuration::Server] The server enum for which the base URI is
|
82
|
+
# required.
|
83
|
+
# @return [String] The base URI.
|
84
|
+
def get_base_uri(server = 'default')
|
85
|
+
self.class.environments[environment][server].clone
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -1,20 +1,20 @@
|
|
1
|
-
# square
|
2
|
-
#
|
3
|
-
# This file was automatically generated by APIMATIC v2.0
|
4
|
-
# ( https://apimatic.io ).
|
5
|
-
|
6
|
-
module Square
|
7
|
-
# Class for exceptions when there is a network error, status code error, etc.
|
8
|
-
class APIException < StandardError
|
9
|
-
attr_reader :response, :response_code
|
10
|
-
|
11
|
-
# The constructor.
|
12
|
-
# @param [String] The reason for raising an exception.
|
13
|
-
# @param [HttpResponse] The HttpReponse of the API call.
|
14
|
-
def initialize(reason, response)
|
15
|
-
super(reason)
|
16
|
-
@response = response
|
17
|
-
@response_code = response.status_code
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
1
|
+
# square
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Square
|
7
|
+
# Class for exceptions when there is a network error, status code error, etc.
|
8
|
+
class APIException < StandardError
|
9
|
+
attr_reader :response, :response_code
|
10
|
+
|
11
|
+
# The constructor.
|
12
|
+
# @param [String] The reason for raising an exception.
|
13
|
+
# @param [HttpResponse] The HttpReponse of the API call.
|
14
|
+
def initialize(reason, response)
|
15
|
+
super(reason)
|
16
|
+
@response = response
|
17
|
+
@response_code = response.status_code
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,50 +1,50 @@
|
|
1
|
-
# square
|
2
|
-
#
|
3
|
-
# This file was automatically generated by APIMATIC v2.0
|
4
|
-
# ( https://apimatic.io ).
|
5
|
-
|
6
|
-
module Square
|
7
|
-
# Http response received.
|
8
|
-
class ApiResponse
|
9
|
-
attr_reader(:status_code, :reason_phrase, :headers, :raw_body, :request,
|
10
|
-
:data, :errors, :body, :cursor)
|
11
|
-
|
12
|
-
# The constructor
|
13
|
-
# @param [HttpResponse] The original, raw response from the api.
|
14
|
-
# @param [Object] The data field specified for the response.
|
15
|
-
# @param [Array<String>] Any errors returned by the server.
|
16
|
-
def initialize(http_response,
|
17
|
-
data: nil,
|
18
|
-
errors: nil)
|
19
|
-
@status_code = http_response.status_code
|
20
|
-
@reason_phrase = http_response.reason_phrase
|
21
|
-
@headers = http_response.headers
|
22
|
-
@raw_body = http_response.raw_body
|
23
|
-
@request = http_response.request
|
24
|
-
@errors = errors
|
25
|
-
|
26
|
-
if data.is_a? Hash
|
27
|
-
if data.keys.any?
|
28
|
-
@body = Struct.new(*data.keys) do
|
29
|
-
define_method(:to_s) { http_response.raw_body }
|
30
|
-
end.new(*data.values)
|
31
|
-
|
32
|
-
@cursor = data.fetch(:cursor, nil)
|
33
|
-
data.reject! { |k| k == :cursor || k == :errors }
|
34
|
-
@data = Struct.new(*data.keys).new(*data.values) if data.keys.any?
|
35
|
-
end
|
36
|
-
else
|
37
|
-
@data = data
|
38
|
-
@body = data
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def success?
|
43
|
-
status_code >= 200 && status_code < 300
|
44
|
-
end
|
45
|
-
|
46
|
-
def error?
|
47
|
-
status_code >= 400 && status_code < 600
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
1
|
+
# square
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Square
|
7
|
+
# Http response received.
|
8
|
+
class ApiResponse
|
9
|
+
attr_reader(:status_code, :reason_phrase, :headers, :raw_body, :request,
|
10
|
+
:data, :errors, :body, :cursor)
|
11
|
+
|
12
|
+
# The constructor
|
13
|
+
# @param [HttpResponse] The original, raw response from the api.
|
14
|
+
# @param [Object] The data field specified for the response.
|
15
|
+
# @param [Array<String>] Any errors returned by the server.
|
16
|
+
def initialize(http_response,
|
17
|
+
data: nil,
|
18
|
+
errors: nil)
|
19
|
+
@status_code = http_response.status_code
|
20
|
+
@reason_phrase = http_response.reason_phrase
|
21
|
+
@headers = http_response.headers
|
22
|
+
@raw_body = http_response.raw_body
|
23
|
+
@request = http_response.request
|
24
|
+
@errors = errors
|
25
|
+
|
26
|
+
if data.is_a? Hash
|
27
|
+
if data.keys.any?
|
28
|
+
@body = Struct.new(*data.keys) do
|
29
|
+
define_method(:to_s) { http_response.raw_body }
|
30
|
+
end.new(*data.values)
|
31
|
+
|
32
|
+
@cursor = data.fetch(:cursor, nil)
|
33
|
+
data.reject! { |k| k == :cursor || k == :errors }
|
34
|
+
@data = Struct.new(*data.keys).new(*data.values) if data.keys.any?
|
35
|
+
end
|
36
|
+
else
|
37
|
+
@data = data
|
38
|
+
@body = data
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def success?
|
43
|
+
status_code >= 200 && status_code < 300
|
44
|
+
end
|
45
|
+
|
46
|
+
def error?
|
47
|
+
status_code >= 400 && status_code < 600
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
# square
|
2
|
-
#
|
3
|
-
# This file was automatically generated by APIMATIC v2.0
|
4
|
-
# ( https://apimatic.io ).
|
5
|
-
|
6
|
-
module Square
|
7
|
-
# Utility class for OAuth 2 authorization and token management.
|
8
|
-
class OAuth2
|
9
|
-
# Add OAuth2 authentication to the http request.
|
10
|
-
# @param [HttpRequest] The HttpRequest object to which authentication will
|
11
|
-
# be added.
|
12
|
-
def self.apply(config, http_request)
|
13
|
-
token = config.access_token
|
14
|
-
http_request.headers['Authorization'] = "Bearer #{token}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
# square
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module Square
|
7
|
+
# Utility class for OAuth 2 authorization and token management.
|
8
|
+
class OAuth2
|
9
|
+
# Add OAuth2 authentication to the http request.
|
10
|
+
# @param [HttpRequest] The HttpRequest object to which authentication will
|
11
|
+
# be added.
|
12
|
+
def self.apply(config, http_request)
|
13
|
+
token = config.access_token
|
14
|
+
http_request.headers['Authorization'] = "Bearer #{token}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|