fangkuai.rb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +10 -0
  3. data/README.md +1 -0
  4. data/lib/square.rb +61 -0
  5. data/lib/square/api/apple_pay_api.rb +50 -0
  6. data/lib/square/api/bank_accounts_api.rb +136 -0
  7. data/lib/square/api/base_api.rb +43 -0
  8. data/lib/square/api/cash_drawers_api.rb +150 -0
  9. data/lib/square/api/catalog_api.rb +572 -0
  10. data/lib/square/api/checkout_api.rb +49 -0
  11. data/lib/square/api/customer_groups_api.rb +182 -0
  12. data/lib/square/api/customer_segments_api.rb +78 -0
  13. data/lib/square/api/customers_api.rb +418 -0
  14. data/lib/square/api/devices_api.rb +120 -0
  15. data/lib/square/api/disputes_api.rb +398 -0
  16. data/lib/square/api/employees_api.rb +87 -0
  17. data/lib/square/api/inventory_api.rb +296 -0
  18. data/lib/square/api/invoices_api.rb +358 -0
  19. data/lib/square/api/labor_api.rb +630 -0
  20. data/lib/square/api/locations_api.rb +151 -0
  21. data/lib/square/api/loyalty_api.rb +543 -0
  22. data/lib/square/api/merchants_api.rb +83 -0
  23. data/lib/square/api/mobile_authorization_api.rb +52 -0
  24. data/lib/square/api/o_auth_api.rb +163 -0
  25. data/lib/square/api/orders_api.rb +280 -0
  26. data/lib/square/api/payments_api.rb +279 -0
  27. data/lib/square/api/refunds_api.rb +145 -0
  28. data/lib/square/api/subscriptions_api.rb +251 -0
  29. data/lib/square/api/team_api.rb +326 -0
  30. data/lib/square/api/terminal_api.rb +141 -0
  31. data/lib/square/api/transactions_api.rb +369 -0
  32. data/lib/square/api/v1_employees_api.rb +723 -0
  33. data/lib/square/api/v1_items_api.rb +1686 -0
  34. data/lib/square/api/v1_locations_api.rb +65 -0
  35. data/lib/square/api/v1_transactions_api.rb +572 -0
  36. data/lib/square/api_helper.rb +276 -0
  37. data/lib/square/client.rb +211 -0
  38. data/lib/square/configuration.rb +101 -0
  39. data/lib/square/exceptions/api_exception.rb +15 -0
  40. data/lib/square/http/api_response.rb +45 -0
  41. data/lib/square/http/auth/o_auth2.rb +12 -0
  42. data/lib/square/http/faraday_client.rb +55 -0
  43. data/lib/square/http/http_call_back.rb +19 -0
  44. data/lib/square/http/http_client.rb +99 -0
  45. data/lib/square/http/http_method_enum.rb +8 -0
  46. data/lib/square/http/http_request.rb +45 -0
  47. data/lib/square/http/http_response.rb +24 -0
  48. data/lib/square/utilities/file_wrapper.rb +12 -0
  49. data/spec/user_journey_spec.rb +148 -0
  50. data/test/api/api_test_base.rb +24 -0
  51. data/test/api/test_catalog_api.rb +59 -0
  52. data/test/api/test_customers_api.rb +45 -0
  53. data/test/api/test_employees_api.rb +36 -0
  54. data/test/api/test_labor_api.rb +74 -0
  55. data/test/api/test_locations_api.rb +35 -0
  56. data/test/api/test_merchants_api.rb +40 -0
  57. data/test/api/test_payments_api.rb +42 -0
  58. data/test/api/test_refunds_api.rb +41 -0
  59. data/test/http_response_catcher.rb +19 -0
  60. data/test/test_helper.rb +94 -0
  61. metadata +199 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 56c9c3f195a152d6a31bb63f9cb26ec4dcab92ccee6d1778db4466285e2d2bd2
4
+ data.tar.gz: 0ead846acab56019bf56f6ee729f3b80c86e52c24f19e8fc60bbc0a2250f2821
5
+ SHA512:
6
+ metadata.gz: c6b7526615b4bdb7ef94f1701a41668316b6cda8aa81da559bc32caa750e12e5722a7c44684648364aee580d54f1841483d698c91384d65f74f8d8f97887960d
7
+ data.tar.gz: 9c7240d6f939f422a0789339518aaf48de06fc00e6087313aaee7becc7bb29bd1a86ee7a10ec28179b75b9851c28361a6416659722461f1afbc8c1c6689a7d8a
data/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ Copyright 2020 Square, Inc.
2
+ Licensed under the Apache License, Version 2.0 (the "License");
3
+ you may not use this file except in compliance with the License.
4
+ You may obtain a copy of the License at
5
+ https://www.apache.org/licenses/LICENSE-2.0
6
+ Unless required by applicable law or agreed to in writing, software
7
+ distributed under the License is distributed on an "AS IS" BASIS,
8
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
+ See the License for the specific language governing permissions and
10
+ limitations under the License.
@@ -0,0 +1 @@
1
+ # test-ruby
@@ -0,0 +1,61 @@
1
+ require 'date'
2
+ require 'json'
3
+ require 'faraday'
4
+ require 'certifi'
5
+ require 'logging'
6
+
7
+ require_relative 'square/api_helper.rb'
8
+ require_relative 'square/client.rb'
9
+
10
+ # Utilities
11
+ require_relative 'square/utilities/file_wrapper.rb'
12
+
13
+ # Http
14
+ require_relative 'square/http/api_response.rb'
15
+ require_relative 'square/http/http_call_back.rb'
16
+ require_relative 'square/http/http_client.rb'
17
+ require_relative 'square/http/faraday_client.rb'
18
+ require_relative 'square/http/http_method_enum.rb'
19
+ require_relative 'square/http/http_request.rb'
20
+ require_relative 'square/http/http_response.rb'
21
+ require_relative 'square/http/auth/o_auth2.rb'
22
+
23
+ # Models
24
+
25
+ # Exceptions
26
+ require_relative 'square/exceptions/api_exception.rb'
27
+
28
+ require_relative 'square/configuration.rb'
29
+
30
+ # Controllers
31
+ require_relative 'square/api/base_api.rb'
32
+ require_relative 'square/api/mobile_authorization_api.rb'
33
+ require_relative 'square/api/o_auth_api.rb'
34
+ require_relative 'square/api/v1_locations_api.rb'
35
+ require_relative 'square/api/v1_employees_api.rb'
36
+ require_relative 'square/api/v1_transactions_api.rb'
37
+ require_relative 'square/api/v1_items_api.rb'
38
+ require_relative 'square/api/apple_pay_api.rb'
39
+ require_relative 'square/api/bank_accounts_api.rb'
40
+ require_relative 'square/api/cash_drawers_api.rb'
41
+ require_relative 'square/api/catalog_api.rb'
42
+ require_relative 'square/api/customers_api.rb'
43
+ require_relative 'square/api/customer_groups_api.rb'
44
+ require_relative 'square/api/customer_segments_api.rb'
45
+ require_relative 'square/api/devices_api.rb'
46
+ require_relative 'square/api/disputes_api.rb'
47
+ require_relative 'square/api/employees_api.rb'
48
+ require_relative 'square/api/inventory_api.rb'
49
+ require_relative 'square/api/invoices_api.rb'
50
+ require_relative 'square/api/labor_api.rb'
51
+ require_relative 'square/api/locations_api.rb'
52
+ require_relative 'square/api/checkout_api.rb'
53
+ require_relative 'square/api/transactions_api.rb'
54
+ require_relative 'square/api/loyalty_api.rb'
55
+ require_relative 'square/api/merchants_api.rb'
56
+ require_relative 'square/api/orders_api.rb'
57
+ require_relative 'square/api/payments_api.rb'
58
+ require_relative 'square/api/refunds_api.rb'
59
+ require_relative 'square/api/subscriptions_api.rb'
60
+ require_relative 'square/api/team_api.rb'
61
+ require_relative 'square/api/terminal_api.rb'
@@ -0,0 +1,50 @@
1
+ module Square
2
+ # ApplePayApi
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
+ # Activates a domain for use with Web Apple Pay and Square. A validation
9
+ # will be performed on this domain by Apple to ensure is it properly set up
10
+ # as
11
+ # an Apple Pay enabled domain.
12
+ # This endpoint provides an easy way for platform developers to bulk
13
+ # activate
14
+ # Web Apple Pay with Square for merchants using their platform.
15
+ # To learn more about Apple Pay on Web see the Apple Pay section in the
16
+ # [Square Payment Form
17
+ # Walkthrough](https://developer.squareup.com/docs/docs/payment-form/payment
18
+ # -form-walkthrough).
19
+ # @param [RegisterDomainRequest] body Required parameter: An object
20
+ # containing the fields to POST for the request. See the corresponding
21
+ # object definition for field details.
22
+ # @return [RegisterDomainResponse Hash] response from the API call
23
+ def register_domain(body:)
24
+ # Prepare query url.
25
+ _query_builder = config.get_base_uri
26
+ _query_builder << '/v2/apple-pay/domains'
27
+ _query_url = APIHelper.clean_url _query_builder
28
+
29
+ # Prepare headers.
30
+ _headers = {
31
+ 'accept' => 'application/json',
32
+ 'content-type' => 'application/json; charset=utf-8'
33
+ }
34
+
35
+ # Prepare and execute HttpRequest.
36
+ _request = config.http_client.post(
37
+ _query_url,
38
+ headers: _headers,
39
+ parameters: body.to_json
40
+ )
41
+ OAuth2.apply(config, _request)
42
+ _response = execute_request(_request)
43
+
44
+ # Return appropriate response type.
45
+ decoded = APIHelper.json_deserialize(_response.raw_body)
46
+ _errors = APIHelper.map_response(decoded, ['errors'])
47
+ ApiResponse.new(_response, data: decoded, errors: _errors)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,136 @@
1
+ module Square
2
+ # BankAccountsApi
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
+ # Returns a list of [BankAccount](#type-bankaccount) objects linked to a
9
+ # Square account.
10
+ # For more information, see
11
+ # [Bank Accounts
12
+ # API](https://developer.squareup.com/docs/docs/bank-accounts-api).
13
+ # @param [String] cursor Optional parameter: The pagination cursor returned
14
+ # by a previous call to this endpoint. Use it in the next `ListBankAccounts`
15
+ # request to retrieve the next set of results. See the
16
+ # [Pagination](https://developer.squareup.com/docs/docs/working-with-apis/pa
17
+ # gination) guide for more information.
18
+ # @param [Integer] limit Optional parameter: Upper limit on the number of
19
+ # bank accounts to return in the response. Currently, 1000 is the largest
20
+ # supported limit. You can specify a limit of up to 1000 bank accounts.
21
+ # This is also the default limit.
22
+ # @param [String] location_id Optional parameter: Location ID. You can
23
+ # specify this optional filter to retrieve only the linked bank accounts
24
+ # belonging to a specific location.
25
+ # @return [ListBankAccountsResponse Hash] response from the API call
26
+ def list_bank_accounts(cursor: nil,
27
+ limit: nil,
28
+ location_id: nil)
29
+ # Prepare query url.
30
+ _query_builder = config.get_base_uri
31
+ _query_builder << '/v2/bank-accounts'
32
+ _query_builder = APIHelper.append_url_with_query_parameters(
33
+ _query_builder,
34
+ 'cursor' => cursor,
35
+ 'limit' => limit,
36
+ 'location_id' => location_id
37
+ )
38
+ _query_url = APIHelper.clean_url _query_builder
39
+
40
+ # Prepare headers.
41
+ _headers = {
42
+ 'accept' => 'application/json'
43
+ }
44
+
45
+ # Prepare and execute HttpRequest.
46
+ _request = config.http_client.get(
47
+ _query_url,
48
+ headers: _headers
49
+ )
50
+ OAuth2.apply(config, _request)
51
+ _response = execute_request(_request)
52
+
53
+ # Return appropriate response type.
54
+ decoded = APIHelper.json_deserialize(_response.raw_body)
55
+ _errors = APIHelper.map_response(decoded, ['errors'])
56
+ ApiResponse.new(_response, data: decoded, errors: _errors)
57
+ end
58
+
59
+ # Returns details of a [BankAccount](#type-bankaccount) identified by V1
60
+ # bank account ID.
61
+ # For more information, see
62
+ # [Retrieve a bank account by using an ID issued by V1 Bank Accounts
63
+ # API](https://developer.squareup.com/docs/docs/bank-accounts-api#retrieve-a
64
+ # -bank-account-by-using-an-id-issued-by-the-v1-bank-accounts-api).
65
+ # @param [String] v1_bank_account_id Required parameter: Connect V1 ID of
66
+ # the desired `BankAccount`. For more information, see [Retrieve a bank
67
+ # account by using an ID issued by V1 Bank Accounts
68
+ # API](https://developer.squareup.com/docs/docs/bank-accounts-api#retrieve-a
69
+ # -bank-account-by-using-an-id-issued-by-v1-bank-accounts-api).
70
+ # @return [GetBankAccountByV1IdResponse Hash] response from the API call
71
+ def get_bank_account_by_v1_id(v1_bank_account_id:)
72
+ # Prepare query url.
73
+ _query_builder = config.get_base_uri
74
+ _query_builder << '/v2/bank-accounts/by-v1-id/{v1_bank_account_id}'
75
+ _query_builder = APIHelper.append_url_with_template_parameters(
76
+ _query_builder,
77
+ 'v1_bank_account_id' => v1_bank_account_id
78
+ )
79
+ _query_url = APIHelper.clean_url _query_builder
80
+
81
+ # Prepare headers.
82
+ _headers = {
83
+ 'accept' => 'application/json'
84
+ }
85
+
86
+ # Prepare and execute HttpRequest.
87
+ _request = config.http_client.get(
88
+ _query_url,
89
+ headers: _headers
90
+ )
91
+ OAuth2.apply(config, _request)
92
+ _response = execute_request(_request)
93
+
94
+ # Return appropriate response type.
95
+ decoded = APIHelper.json_deserialize(_response.raw_body)
96
+ _errors = APIHelper.map_response(decoded, ['errors'])
97
+ ApiResponse.new(_response, data: decoded, errors: _errors)
98
+ end
99
+
100
+ # Returns details of a [BankAccount](#type-bankaccount)
101
+ # linked to a Square account. For more information, see
102
+ # [Bank Accounts
103
+ # API](https://developer.squareup.com/docs/docs/bank-accounts-api).
104
+ # @param [String] bank_account_id Required parameter: Square-issued ID of
105
+ # the desired `BankAccount`.
106
+ # @return [GetBankAccountResponse Hash] response from the API call
107
+ def get_bank_account(bank_account_id:)
108
+ # Prepare query url.
109
+ _query_builder = config.get_base_uri
110
+ _query_builder << '/v2/bank-accounts/{bank_account_id}'
111
+ _query_builder = APIHelper.append_url_with_template_parameters(
112
+ _query_builder,
113
+ 'bank_account_id' => bank_account_id
114
+ )
115
+ _query_url = APIHelper.clean_url _query_builder
116
+
117
+ # Prepare headers.
118
+ _headers = {
119
+ 'accept' => 'application/json'
120
+ }
121
+
122
+ # Prepare and execute HttpRequest.
123
+ _request = config.http_client.get(
124
+ _query_url,
125
+ headers: _headers
126
+ )
127
+ OAuth2.apply(config, _request)
128
+ _response = execute_request(_request)
129
+
130
+ # Return appropriate response type.
131
+ decoded = APIHelper.json_deserialize(_response.raw_body)
132
+ _errors = APIHelper.map_response(decoded, ['errors'])
133
+ ApiResponse.new(_response, data: decoded, errors: _errors)
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,43 @@
1
+ module Square
2
+ # BaseApi.
3
+ class BaseApi
4
+ attr_accessor :config, :http_call_back
5
+
6
+ def initialize(config, http_call_back: nil)
7
+ @config = config
8
+ @http_call_back = http_call_back
9
+
10
+ @global_headers = {
11
+ 'user-agent' => 'Square-Ruby-SDK/6.3.0.20200826',
12
+ 'Square-Version' => config.square_version
13
+ }
14
+ end
15
+
16
+ def validate_parameters(args)
17
+ args.each do |_name, value|
18
+ if value.nil?
19
+ raise ArgumentError, "Required parameter #{_name} cannot be nil."
20
+ end
21
+ end
22
+ end
23
+
24
+ def execute_request(request, binary: false)
25
+ @http_call_back.on_before_request(request) if @http_call_back
26
+
27
+ APIHelper.clean_hash(request.headers)
28
+ request.headers.merge!(@global_headers)
29
+ unless config.additional_headers.nil?
30
+ request.headers.merge!(config.additional_headers)
31
+ end
32
+
33
+ response = if binary
34
+ config.http_client.execute_as_binary(request)
35
+ else
36
+ config.http_client.execute_as_string(request)
37
+ end
38
+ @http_call_back.on_after_response(response) if @http_call_back
39
+
40
+ response
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,150 @@
1
+ module Square
2
+ # CashDrawersApi
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
+ # Provides the details for all of the cash drawer shifts for a location
9
+ # in a date range.
10
+ # @param [String] location_id Required parameter: The ID of the location to
11
+ # query for a list of cash drawer shifts.
12
+ # @param [SortOrder] sort_order Optional parameter: The order in which cash
13
+ # drawer shifts are listed in the response, based on their opened_at field.
14
+ # Default value: ASC
15
+ # @param [String] begin_time Optional parameter: The inclusive start time of
16
+ # the query on opened_at, in ISO 8601 format.
17
+ # @param [String] end_time Optional parameter: The exclusive end date of the
18
+ # query on opened_at, in ISO 8601 format.
19
+ # @param [Integer] limit Optional parameter: Number of cash drawer shift
20
+ # events in a page of results (200 by default, 1000 max).
21
+ # @param [String] cursor Optional parameter: Opaque cursor for fetching the
22
+ # next page of results.
23
+ # @return [ListCashDrawerShiftsResponse Hash] response from the API call
24
+ def list_cash_drawer_shifts(location_id:,
25
+ sort_order: nil,
26
+ begin_time: nil,
27
+ end_time: nil,
28
+ limit: nil,
29
+ 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(_response, data: decoded, errors: _errors)
61
+ end
62
+
63
+ # Provides the summary details for a single cash drawer shift. See
64
+ # RetrieveCashDrawerShiftEvents for a list of cash drawer shift events.
65
+ # @param [String] location_id Required parameter: The ID of the location to
66
+ # retrieve cash drawer shifts from.
67
+ # @param [String] shift_id Required parameter: The shift ID.
68
+ # @return [RetrieveCashDrawerShiftResponse Hash] response from the API call
69
+ def retrieve_cash_drawer_shift(location_id:,
70
+ shift_id:)
71
+ # Prepare query url.
72
+ _query_builder = config.get_base_uri
73
+ _query_builder << '/v2/cash-drawers/shifts/{shift_id}'
74
+ _query_builder = APIHelper.append_url_with_template_parameters(
75
+ _query_builder,
76
+ 'shift_id' => shift_id
77
+ )
78
+ _query_builder = APIHelper.append_url_with_query_parameters(
79
+ _query_builder,
80
+ 'location_id' => location_id
81
+ )
82
+ _query_url = APIHelper.clean_url _query_builder
83
+
84
+ # Prepare headers.
85
+ _headers = {
86
+ 'accept' => 'application/json'
87
+ }
88
+
89
+ # Prepare and execute HttpRequest.
90
+ _request = config.http_client.get(
91
+ _query_url,
92
+ headers: _headers
93
+ )
94
+ OAuth2.apply(config, _request)
95
+ _response = execute_request(_request)
96
+
97
+ # Return appropriate response type.
98
+ decoded = APIHelper.json_deserialize(_response.raw_body)
99
+ _errors = APIHelper.map_response(decoded, ['errors'])
100
+ ApiResponse.new(_response, data: decoded, errors: _errors)
101
+ end
102
+
103
+ # Provides a paginated list of events for a single cash drawer shift.
104
+ # @param [String] location_id Required parameter: The ID of the location to
105
+ # list cash drawer shifts for.
106
+ # @param [String] shift_id Required parameter: The shift ID.
107
+ # @param [Integer] limit Optional parameter: Number of resources to be
108
+ # returned in a page of results (200 by default, 1000 max).
109
+ # @param [String] cursor Optional parameter: Opaque cursor for fetching the
110
+ # next page of results.
111
+ # @return [ListCashDrawerShiftEventsResponse Hash] response from the API call
112
+ def list_cash_drawer_shift_events(location_id:,
113
+ shift_id:,
114
+ limit: nil,
115
+ cursor: nil)
116
+ # Prepare query url.
117
+ _query_builder = config.get_base_uri
118
+ _query_builder << '/v2/cash-drawers/shifts/{shift_id}/events'
119
+ _query_builder = APIHelper.append_url_with_template_parameters(
120
+ _query_builder,
121
+ 'shift_id' => shift_id
122
+ )
123
+ _query_builder = APIHelper.append_url_with_query_parameters(
124
+ _query_builder,
125
+ 'location_id' => location_id,
126
+ 'limit' => limit,
127
+ 'cursor' => cursor
128
+ )
129
+ _query_url = APIHelper.clean_url _query_builder
130
+
131
+ # Prepare headers.
132
+ _headers = {
133
+ 'accept' => 'application/json'
134
+ }
135
+
136
+ # Prepare and execute HttpRequest.
137
+ _request = config.http_client.get(
138
+ _query_url,
139
+ headers: _headers
140
+ )
141
+ OAuth2.apply(config, _request)
142
+ _response = execute_request(_request)
143
+
144
+ # Return appropriate response type.
145
+ decoded = APIHelper.json_deserialize(_response.raw_body)
146
+ _errors = APIHelper.map_response(decoded, ['errors'])
147
+ ApiResponse.new(_response, data: decoded, errors: _errors)
148
+ end
149
+ end
150
+ end