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,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../test/api/api_test_base'
4
+ require 'json'
5
+
6
+ describe "UserJourney" do
7
+ let(:access_token) { ApiTestBase::CONFIG.access_token }
8
+ let(:environment) { ApiTestBase::CONFIG.environment }
9
+
10
+ let(:phone_number) { "1-212-555-4240" }
11
+ let(:phone_number2) { "1-917-500-1000" }
12
+ let(:postal_code) { "10003" }
13
+ let(:postal_code2) { "98100" }
14
+
15
+ let :customer do
16
+ {
17
+ "given_name": "Amelia",
18
+ "family_name": "Earhart",
19
+ "phone_number": phone_number,
20
+ "note": "a customer",
21
+ "address": {
22
+ "address_line_1": "500 Electric Ave",
23
+ "address_line_2": "Suite 600",
24
+ "locality": "New York",
25
+ "administrative_district_level_1": "NY",
26
+ "postal_code": postal_code,
27
+ "country": "US"
28
+ }
29
+ }
30
+ end
31
+
32
+ let :sq do
33
+ Square::Client.new(access_token: access_token, environment: environment)
34
+ end
35
+
36
+ let :unauthoerized_sq do
37
+ Square::Client.new(access_token: "bad_token")
38
+ end
39
+
40
+ let :customer2 do
41
+ tmp_customer = customer.clone
42
+ tmp_customer[:phone_number] = phone_number2
43
+ tmp_customer[:address][:postal_code] = postal_code2
44
+ tmp_customer
45
+ end
46
+
47
+ describe 'Response Object Verification' do
48
+ it "should contain following fields" do
49
+ response = sq.locations.list_locations
50
+ assert_equal response.status_code, 200
51
+ assert_includes response.body.to_h.keys, :locations
52
+ assert_equal response.data.to_h.keys, %i[locations]
53
+ assert_nil response.errors
54
+ assert_nil response.cursor
55
+ end
56
+ end
57
+
58
+ describe 'ListLocations' do
59
+ it 'should return success 200' do
60
+ assert_equal sq.locations.list_locations.status_code, 200
61
+ end
62
+ end
63
+
64
+ describe 'API Call Error' do
65
+ it 'should return error' do
66
+ response = unauthoerized_sq.locations.list_locations
67
+ assert_equal response.status_code, 401
68
+ assert_instance_of Array, response.errors
69
+ refute_nil response.errors
70
+ end
71
+ end
72
+
73
+ # There is no sandbox support for V1 endpoints as production token is required for the following tests
74
+ # describe 'V1 Category' do
75
+ # it 'should succeed for each endpoint call' do
76
+ # location_id = "your_location_id"
77
+ # access_token = "your_production_access_token"
78
+ # name1 = "fruit"
79
+ # name2 = "drink"
80
+ # api = Square::Client.new(access_token: access_token).v1_items
81
+ #
82
+ # # create
83
+ # response = api.create_category(location_id: location_id, body: {name: name1})
84
+ # assert_equal response.data.name, name1
85
+ # assert_nil response.errors
86
+ # assert_equal response.status_code, 200
87
+ #
88
+ # created_id = response.data.id
89
+ #
90
+ # # list
91
+ # response = api.list_categories(location_id: location_id)
92
+ # assert_instance_of Array, response.data
93
+ # assert_equal response.status_code, 200
94
+ #
95
+ # # update
96
+ # response = api.update_category(location_id: location_id, category_id: created_id, body: {name: name2})
97
+ # assert_equal response.data.name, name2
98
+ # assert_equal response.status_code, 200
99
+ #
100
+ # # delete
101
+ # response = api.delete_category(location_id: location_id, category_id: created_id)
102
+ # assert_nil response.data
103
+ # assert_equal response.status_code, 200
104
+ # end
105
+ # end
106
+
107
+ describe 'V2 Customers' do
108
+ it 'should succeed for each endpoint call' do
109
+ # create
110
+ response = sq.customers.create_customer(body: customer)
111
+ assert_equal response.data.customer[:phone_number], phone_number
112
+
113
+ assert_equal response.status_code, 200
114
+ created_customer = response.data.customer
115
+
116
+ # retrieve
117
+ response = sq.customers.retrieve_customer(customer_id: created_customer[:id])
118
+ assert_equal response.data.customer[:phone_number], phone_number
119
+ assert_equal response.data.customer[:address][:postal_code], postal_code
120
+ assert_equal response.status_code, 200
121
+
122
+ # list
123
+ response = sq.customers.list_customers
124
+ if response.data != nil
125
+ assert_equal response.data.to_h.keys, %i[customers]
126
+ assert_equal response.status_code, 200
127
+ end
128
+
129
+
130
+ # update
131
+ response = sq.customers.update_customer(customer_id: created_customer[:id], body: customer2)
132
+ assert_equal response.data.customer[:phone_number], phone_number2
133
+ assert_equal response.data.customer[:address][:postal_code], postal_code2
134
+ assert_equal response.status_code, 200
135
+
136
+ # retrieve
137
+ response = sq.customers.retrieve_customer(customer_id: created_customer[:id])
138
+ assert_equal response.data.customer[:phone_number], phone_number2
139
+ assert_equal response.data.customer[:address][:postal_code], postal_code2
140
+ assert_equal response.status_code, 200
141
+
142
+ # delete
143
+ response = sq.customers.delete_customer(customer_id: created_customer[:id])
144
+ assert_equal response.data.to_h, {}
145
+ assert_equal response.status_code, 200
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,24 @@
1
+ # square
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ require 'json'
7
+ require 'minitest/autorun'
8
+ require 'minitest/hell'
9
+ require 'minitest/pride'
10
+ require 'minitest/proveit'
11
+ require 'square'
12
+ require_relative '../test_helper'
13
+ require_relative '../http_response_catcher'
14
+
15
+ class ApiTestBase < Minitest::Test
16
+ parallelize_me!
17
+ include Square
18
+
19
+ # Create configuration and set any test parameters
20
+ CONFIG = Configuration.new(
21
+ access_token: ENV.fetch('SQUARE_SANDBOX_TOKEN', 'AccessToken'),
22
+ environment: "sandbox"
23
+ )
24
+ end
@@ -0,0 +1,59 @@
1
+ # square
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ require_relative 'api_test_base'
7
+
8
+ class CatalogApiTests < ApiTestBase
9
+ # Called only once for the class before any test has executed
10
+ def setup
11
+ @response_catcher = HttpResponseCatcher.new
12
+ @controller = CatalogApi.new CONFIG, http_call_back: @response_catcher
13
+ end
14
+
15
+ # Returns information about the Square Catalog API, such as batch size
16
+ #limits for `BatchUpsertCatalogObjects`.
17
+ def test_test_catalog_info()
18
+
19
+ # Perform the API call through the SDK function
20
+ result = @controller.catalog_info()
21
+
22
+ # Test response code
23
+ assert_equal(200, @response_catcher.response.status_code)
24
+
25
+ # Test headers
26
+ expected_headers = {}
27
+ expected_headers['content-type'] = 'application/json'
28
+
29
+ assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
30
+ end
31
+
32
+ # Returns a list of [CatalogObject](#type-catalogobject)s that includes
33
+ #all objects of a set of desired types (for example, all [CatalogItem](#type-catalogitem)
34
+ #and [CatalogTax](#type-catalogtax) objects) in the catalog. The `types` parameter
35
+ #is specified as a comma-separated list of valid [CatalogObject](#type-catalogobject) types:
36
+ #`ITEM`, `ITEM_VARIATION`, `MODIFIER`, `MODIFIER_LIST`, `CATEGORY`, `DISCOUNT`, `TAX`.
37
+ #
38
+ #__Important:__ ListCatalog does not return deleted catalog items. To retrieve
39
+ #deleted catalog items, use SearchCatalogObjects and set `include_deleted_objects`
40
+ #to `true`.
41
+ def test_test_list_catalog()
42
+ # Parameters for the API call
43
+ cursor = nil
44
+ types = nil
45
+
46
+ # Perform the API call through the SDK function
47
+ result = @controller.list_catalog(cursor: cursor, types: types)
48
+
49
+ # Test response code
50
+ assert_equal(200, @response_catcher.response.status_code)
51
+
52
+ # Test headers
53
+ expected_headers = {}
54
+ expected_headers['content-type'] = 'application/json'
55
+
56
+ assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
57
+ end
58
+
59
+ end
@@ -0,0 +1,45 @@
1
+ # square
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ require_relative 'api_test_base'
7
+
8
+ class CustomersApiTests < ApiTestBase
9
+ # Called only once for the class before any test has executed
10
+ def setup
11
+ @response_catcher = HttpResponseCatcher.new
12
+ @controller = CustomersApi.new CONFIG, http_call_back: @response_catcher
13
+ end
14
+
15
+ # Creates a new customer for a business, which can have associated cards on file.
16
+ #
17
+ #You must provide __at least one__ of the following values in your request to this
18
+ #endpoint:
19
+ #
20
+ #- `given_name`
21
+ #- `family_name`
22
+ #- `company_name`
23
+ #- `email_address`
24
+ #- `phone_number`
25
+ #
26
+ #This endpoint does not accept an idempotency key. If you accidentally create
27
+ #a duplicate customer, you can delete it with the
28
+ #[DeleteCustomer](#endpoint-deletecustomer) endpoint.
29
+ def test_create_customer()
30
+ # Parameters for the API call
31
+ body = APIHelper.json_deserialize(
32
+ '{"given_name":"Amelia","family_name":"Earhart","email_address":"Amelia.Ear'\
33
+ 'hart@example.com","address":{"address_line_1":"500 Electric Ave","address_l'\
34
+ 'ine_2":"Suite 600","locality":"New York"},"phone_number":"1-212-555-4240","'\
35
+ 'reference_id":"YOUR_REFERENCE_ID","note":"a customer"}'
36
+ )
37
+
38
+ # Perform the API call through the SDK function
39
+ result = @controller.create_customer(body: body)
40
+
41
+ # Test response code
42
+ assert_equal(200, @response_catcher.response.status_code)
43
+ end
44
+
45
+ end
@@ -0,0 +1,36 @@
1
+ # square
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ require_relative 'api_test_base'
7
+
8
+ class EmployeesApiTests < ApiTestBase
9
+ # Called only once for the class before any test has executed
10
+ def setup
11
+ @response_catcher = HttpResponseCatcher.new
12
+ @controller = EmployeesApi.new CONFIG, http_call_back: @response_catcher
13
+ end
14
+
15
+ # Gets a list of `Employee` objects for a business.
16
+ def test_test_list_employees()
17
+ # Parameters for the API call
18
+ location_id = nil
19
+ status = nil
20
+ limit = nil
21
+ cursor = nil
22
+
23
+ # Perform the API call through the SDK function
24
+ result = @controller.list_employees(location_id: location_id, status: status, limit: limit, cursor: cursor)
25
+
26
+ # Test response code
27
+ assert_equal(200, @response_catcher.response.status_code)
28
+
29
+ # Test headers
30
+ expected_headers = {}
31
+ expected_headers['content-type'] = 'application/json'
32
+
33
+ assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
34
+ end
35
+
36
+ end
@@ -0,0 +1,74 @@
1
+ # square
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ require_relative 'api_test_base'
7
+
8
+ class LaborApiTests < ApiTestBase
9
+ # Called only once for the class before any test has executed
10
+ def setup
11
+ @response_catcher = HttpResponseCatcher.new
12
+ @controller = LaborApi.new CONFIG, http_call_back: @response_catcher
13
+ end
14
+
15
+ # Returns a paginated list of `BreakType` instances for a business.
16
+ def test_list_break_types()
17
+ # Parameters for the API call
18
+ location_id = nil
19
+ limit = nil
20
+ cursor = nil
21
+
22
+ # Perform the API call through the SDK function
23
+ result = @controller.list_break_types(location_id: location_id, limit: limit, cursor: cursor)
24
+
25
+ # Test response code
26
+ assert_equal(200, @response_catcher.response.status_code)
27
+
28
+ # Test headers
29
+ expected_headers = {}
30
+ expected_headers['content-type'] = 'application/json'
31
+
32
+ assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
33
+ end
34
+
35
+ # Returns a paginated list of `EmployeeWage` instances for a business.
36
+ def test_list_employee_wages()
37
+ # Parameters for the API call
38
+ employee_id = nil
39
+ limit = nil
40
+ cursor = nil
41
+
42
+ # Perform the API call through the SDK function
43
+ result = @controller.list_employee_wages(employee_id: employee_id, limit: limit, cursor: cursor)
44
+
45
+ # Test response code
46
+ assert_equal(200, @response_catcher.response.status_code)
47
+
48
+ # Test headers
49
+ expected_headers = {}
50
+ expected_headers['content-type'] = 'application/json'
51
+
52
+ assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
53
+ end
54
+
55
+ # Returns a list of `WorkweekConfig` instances for a business.
56
+ def test_list_workweek_configs()
57
+ # Parameters for the API call
58
+ limit = nil
59
+ cursor = nil
60
+
61
+ # Perform the API call through the SDK function
62
+ result = @controller.list_workweek_configs(limit: limit, cursor: cursor)
63
+
64
+ # Test response code
65
+ assert_equal(200, @response_catcher.response.status_code)
66
+
67
+ # Test headers
68
+ expected_headers = {}
69
+ expected_headers['content-type'] = 'application/json'
70
+
71
+ assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
72
+ end
73
+
74
+ end
@@ -0,0 +1,35 @@
1
+ # square
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ require_relative 'api_test_base'
7
+
8
+ class LocationsApiTests < ApiTestBase
9
+ # Called only once for the class before any test has executed
10
+ def setup
11
+ @response_catcher = HttpResponseCatcher.new
12
+ @controller = LocationsApi.new CONFIG, http_call_back: @response_catcher
13
+ end
14
+
15
+ # Provides the details for all of a business's locations.
16
+ #
17
+ #Most other Connect API endpoints have a required `location_id` path parameter.
18
+ #The `id` field of the [`Location`](#type-location) objects returned by this
19
+ #endpoint correspond to that `location_id` parameter.
20
+ def test_test_list_locations()
21
+
22
+ # Perform the API call through the SDK function
23
+ result = @controller.list_locations()
24
+
25
+ # Test response code
26
+ assert_equal(200, @response_catcher.response.status_code)
27
+
28
+ # Test headers
29
+ expected_headers = {}
30
+ expected_headers['content-type'] = 'application/json'
31
+
32
+ assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
33
+ end
34
+
35
+ end
@@ -0,0 +1,40 @@
1
+ # square
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ require_relative 'api_test_base'
7
+
8
+ class MerchantsApiTests < ApiTestBase
9
+ # Called only once for the class before any test has executed
10
+ def setup
11
+ @response_catcher = HttpResponseCatcher.new
12
+ @controller = MerchantsApi.new CONFIG, http_call_back: @response_catcher
13
+ end
14
+
15
+ # Returns `Merchant` information for a given access token.
16
+ #
17
+ #If you don't know a `Merchant` ID, you can use this endpoint to retrieve the merchant ID for an access token.
18
+ #You can specify your personal access token to get your own merchant information or specify an OAuth token
19
+ #to get the information for the merchant that granted you access.
20
+ #
21
+ #If you know the merchant ID, you can also use the [RetrieveMerchant](#endpoint-merchants-retrievemerchant)
22
+ #endpoint to get the merchant information.
23
+ def test_list_merchants()
24
+ # Parameters for the API call
25
+ cursor = nil
26
+
27
+ # Perform the API call through the SDK function
28
+ result = @controller.list_merchants(cursor: cursor)
29
+
30
+ # Test response code
31
+ assert_equal(200, @response_catcher.response.status_code)
32
+
33
+ # Test headers
34
+ expected_headers = {}
35
+ expected_headers['content-type'] = 'application/json'
36
+
37
+ assert(TestHelper.match_headers(expected_headers, @response_catcher.response.headers))
38
+ end
39
+
40
+ end