patch_ruby 1.0.0.pre
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.
- checksums.yaml +7 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +72 -0
- data/README.md +54 -0
- data/Rakefile +10 -0
- data/lib/patch_ruby.rb +61 -0
- data/lib/patch_ruby/api/estimates_api.rb +213 -0
- data/lib/patch_ruby/api/orders_api.rb +339 -0
- data/lib/patch_ruby/api/preferences_api.rb +276 -0
- data/lib/patch_ruby/api/projects_api.rb +148 -0
- data/lib/patch_ruby/api_client.rb +388 -0
- data/lib/patch_ruby/api_error.rb +57 -0
- data/lib/patch_ruby/configuration.rb +254 -0
- data/lib/patch_ruby/models/allocation.rb +229 -0
- data/lib/patch_ruby/models/create_mass_estimate_request.rb +216 -0
- data/lib/patch_ruby/models/create_order_request.rb +216 -0
- data/lib/patch_ruby/models/create_preference_request.rb +216 -0
- data/lib/patch_ruby/models/error_response.rb +239 -0
- data/lib/patch_ruby/models/estimate.rb +238 -0
- data/lib/patch_ruby/models/estimate_list_response.rb +255 -0
- data/lib/patch_ruby/models/estimate_response.rb +239 -0
- data/lib/patch_ruby/models/meta_index_object.rb +220 -0
- data/lib/patch_ruby/models/order.rb +313 -0
- data/lib/patch_ruby/models/order_list_response.rb +255 -0
- data/lib/patch_ruby/models/order_response.rb +239 -0
- data/lib/patch_ruby/models/preference.rb +229 -0
- data/lib/patch_ruby/models/preference_list_response.rb +255 -0
- data/lib/patch_ruby/models/preference_response.rb +239 -0
- data/lib/patch_ruby/models/project.rb +283 -0
- data/lib/patch_ruby/models/project_list_response.rb +255 -0
- data/lib/patch_ruby/models/project_response.rb +239 -0
- data/lib/patch_ruby/version.rb +15 -0
- data/patch_ruby.gemspec +39 -0
- data/spec/api/estimates_api_spec.rb +71 -0
- data/spec/api/orders_api_spec.rb +95 -0
- data/spec/api/preferences_api_spec.rb +83 -0
- data/spec/api/projects_api_spec.rb +59 -0
- data/spec/api_client_spec.rb +226 -0
- data/spec/configuration_spec.rb +42 -0
- data/spec/fixtures/vcr_cassettes/estimate_orders.yml +276 -0
- data/spec/fixtures/vcr_cassettes/estimates.yml +211 -0
- data/spec/fixtures/vcr_cassettes/orders.yml +229 -0
- data/spec/fixtures/vcr_cassettes/preferences.yml +352 -0
- data/spec/fixtures/vcr_cassettes/projects.yml +143 -0
- data/spec/integration/estimates_spec.rb +31 -0
- data/spec/integration/orders_spec.rb +53 -0
- data/spec/integration/preferences_spec.rb +40 -0
- data/spec/integration/projects_spec.rb +31 -0
- data/spec/models/allocation_spec.rb +53 -0
- data/spec/models/create_mass_estimate_request_spec.rb +41 -0
- data/spec/models/create_order_request_spec.rb +41 -0
- data/spec/models/create_preference_request_spec.rb +41 -0
- data/spec/models/error_response_spec.rb +53 -0
- data/spec/models/estimate_list_response_spec.rb +59 -0
- data/spec/models/estimate_response_spec.rb +53 -0
- data/spec/models/estimate_spec.rb +59 -0
- data/spec/models/meta_index_object_spec.rb +47 -0
- data/spec/models/order_list_response_spec.rb +59 -0
- data/spec/models/order_response_spec.rb +53 -0
- data/spec/models/order_spec.rb +85 -0
- data/spec/models/preference_list_response_spec.rb +59 -0
- data/spec/models/preference_response_spec.rb +53 -0
- data/spec/models/preference_spec.rb +53 -0
- data/spec/models/project_list_response_spec.rb +59 -0
- data/spec/models/project_response_spec.rb +53 -0
- data/spec/models/project_spec.rb +89 -0
- data/spec/spec_helper.rb +122 -0
- metadata +203 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
=begin
|
2
|
+
#Patch API V1
|
3
|
+
|
4
|
+
#The core API used to integrate with Patch's service
|
5
|
+
|
6
|
+
The version of the OpenAPI document: v1
|
7
|
+
Contact: developers@usepatch.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 4.3.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
module Patch
|
14
|
+
VERSION = '1.0.0.pre'
|
15
|
+
end
|
data/patch_ruby.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
=begin
|
4
|
+
#Patch API V1
|
5
|
+
|
6
|
+
#The core API used to integrate with Patch's service
|
7
|
+
|
8
|
+
The version of the OpenAPI document: v1
|
9
|
+
Contact: developers@usepatch.com
|
10
|
+
Generated by: https://openapi-generator.tech
|
11
|
+
OpenAPI Generator version: 4.3.1
|
12
|
+
|
13
|
+
=end
|
14
|
+
|
15
|
+
$:.push File.expand_path("../lib", __FILE__)
|
16
|
+
require "patch_ruby/version"
|
17
|
+
|
18
|
+
Gem::Specification.new do |s|
|
19
|
+
s.name = "patch_ruby"
|
20
|
+
s.version = Patch::VERSION
|
21
|
+
s.platform = Gem::Platform::RUBY
|
22
|
+
s.authors = ["Patch Technology"]
|
23
|
+
s.email = ["developers@usepatch.com"]
|
24
|
+
s.homepage = "https://www.usepatch.com"
|
25
|
+
s.summary = "Ruby wrapper for the Patch API"
|
26
|
+
s.description = "Ruby wrapper for the Patch API"
|
27
|
+
s.license = 'MIT'
|
28
|
+
s.required_ruby_version = ">= 1.9"
|
29
|
+
|
30
|
+
s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'
|
31
|
+
s.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0'
|
32
|
+
|
33
|
+
s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
|
34
|
+
|
35
|
+
s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? }
|
36
|
+
s.test_files = `find spec/*`.split("\n")
|
37
|
+
s.executables = []
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
=begin
|
2
|
+
#Patch API V1
|
3
|
+
|
4
|
+
#The core API used to integrate with Patch's service
|
5
|
+
|
6
|
+
The version of the OpenAPI document: v1
|
7
|
+
Contact: developers@usepatch.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 4.3.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
# Unit tests for Patch::EstimatesApi
|
17
|
+
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
18
|
+
# Please update as you see appropriate
|
19
|
+
describe 'EstimatesApi' do
|
20
|
+
before do
|
21
|
+
# run before each test
|
22
|
+
@api_instance = Patch::EstimatesApi.new
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
# run after each test
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'test an instance of EstimatesApi' do
|
30
|
+
it 'should create an instance of EstimatesApi' do
|
31
|
+
expect(@api_instance).to be_instance_of(Patch::EstimatesApi)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# unit tests for create_mass_estimate
|
36
|
+
# Create an estimate based on mass of CO2
|
37
|
+
# Creates an estimate for the mass of CO2 to be compensated. An order in the `draft` state will also be created, linked to the estimate.
|
38
|
+
# @param create_mass_estimate_request
|
39
|
+
# @param [Hash] opts the optional parameters
|
40
|
+
# @return [EstimateResponse]
|
41
|
+
describe 'create_mass_estimate test' do
|
42
|
+
it 'should work' do
|
43
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# unit tests for retrieve_estimate
|
48
|
+
# Retrieves an estimate
|
49
|
+
# Retrieves a given estimate and its associated order. You can only retrieve estimates associated with the organization you are querying for.
|
50
|
+
# @param id
|
51
|
+
# @param [Hash] opts the optional parameters
|
52
|
+
# @return [EstimateResponse]
|
53
|
+
describe 'retrieve_estimate test' do
|
54
|
+
it 'should work' do
|
55
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# unit tests for retrieve_estimates
|
60
|
+
# Retrieves a list of estimates
|
61
|
+
# Retrieves a list of estimates and their associated orders. You can only retrieve estimates associated with the organization you are querying for.
|
62
|
+
# @param [Hash] opts the optional parameters
|
63
|
+
# @option opts [Integer] :page
|
64
|
+
# @return [EstimateListResponse]
|
65
|
+
describe 'retrieve_estimates test' do
|
66
|
+
it 'should work' do
|
67
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
=begin
|
2
|
+
#Patch API V1
|
3
|
+
|
4
|
+
#The core API used to integrate with Patch's service
|
5
|
+
|
6
|
+
The version of the OpenAPI document: v1
|
7
|
+
Contact: developers@usepatch.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 4.3.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
# Unit tests for Patch::OrdersApi
|
17
|
+
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
18
|
+
# Please update as you see appropriate
|
19
|
+
describe 'OrdersApi' do
|
20
|
+
before do
|
21
|
+
# run before each test
|
22
|
+
@api_instance = Patch::OrdersApi.new
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
# run after each test
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'test an instance of OrdersApi' do
|
30
|
+
it 'should create an instance of OrdersApi' do
|
31
|
+
expect(@api_instance).to be_instance_of(Patch::OrdersApi)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# unit tests for cancel_order
|
36
|
+
# Cancel an order
|
37
|
+
# Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the `draft` state can be cancelled.
|
38
|
+
# @param id
|
39
|
+
# @param [Hash] opts the optional parameters
|
40
|
+
# @return [OrderResponse]
|
41
|
+
describe 'cancel_order test' do
|
42
|
+
it 'should work' do
|
43
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# unit tests for create_order
|
48
|
+
# Creates an order
|
49
|
+
# Creates an order in the `placed` state. To create a `draft` order, create an estimate first.
|
50
|
+
# @param create_order_request
|
51
|
+
# @param [Hash] opts the optional parameters
|
52
|
+
# @return [OrderResponse]
|
53
|
+
describe 'create_order test' do
|
54
|
+
it 'should work' do
|
55
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# unit tests for place_order
|
60
|
+
# Place an order
|
61
|
+
# Placing an order confirms an order's allocation of offsets. Only orders that are in the `draft` state can be placed
|
62
|
+
# @param id
|
63
|
+
# @param [Hash] opts the optional parameters
|
64
|
+
# @return [OrderResponse]
|
65
|
+
describe 'place_order test' do
|
66
|
+
it 'should work' do
|
67
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# unit tests for retrieve_order
|
72
|
+
# Retrieves an order
|
73
|
+
# Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
|
74
|
+
# @param id
|
75
|
+
# @param [Hash] opts the optional parameters
|
76
|
+
# @return [OrderResponse]
|
77
|
+
describe 'retrieve_order test' do
|
78
|
+
it 'should work' do
|
79
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# unit tests for retrieve_orders
|
84
|
+
# Retrieves a list of orders
|
85
|
+
# Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for.
|
86
|
+
# @param [Hash] opts the optional parameters
|
87
|
+
# @option opts [Integer] :page
|
88
|
+
# @return [OrderListResponse]
|
89
|
+
describe 'retrieve_orders test' do
|
90
|
+
it 'should work' do
|
91
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
=begin
|
2
|
+
#Patch API V1
|
3
|
+
|
4
|
+
#The core API used to integrate with Patch's service
|
5
|
+
|
6
|
+
The version of the OpenAPI document: v1
|
7
|
+
Contact: developers@usepatch.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 4.3.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
# Unit tests for Patch::PreferencesApi
|
17
|
+
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
18
|
+
# Please update as you see appropriate
|
19
|
+
describe 'PreferencesApi' do
|
20
|
+
before do
|
21
|
+
# run before each test
|
22
|
+
@api_instance = Patch::PreferencesApi.new
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
# run after each test
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'test an instance of PreferencesApi' do
|
30
|
+
it 'should create an instance of PreferencesApi' do
|
31
|
+
expect(@api_instance).to be_instance_of(Patch::PreferencesApi)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# unit tests for create_preference
|
36
|
+
# creates a project preference
|
37
|
+
# Creates a project preference for the given organization. If you have a `preference` in place, all of your orders will be directed to the project the preference points to.
|
38
|
+
# @param create_preference_request
|
39
|
+
# @param [Hash] opts the optional parameters
|
40
|
+
# @return [PreferenceResponse]
|
41
|
+
describe 'create_preference test' do
|
42
|
+
it 'should work' do
|
43
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# unit tests for delete_preference
|
48
|
+
# Deletes an organization's preference for a project
|
49
|
+
# Deletes the given `preference`. Once a preference is deleted, it cannot be undone. If you want to restore your previous preference, create a new one.
|
50
|
+
# @param id
|
51
|
+
# @param [Hash] opts the optional parameters
|
52
|
+
# @return [PreferenceResponse]
|
53
|
+
describe 'delete_preference test' do
|
54
|
+
it 'should work' do
|
55
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# unit tests for retrieve_preference
|
60
|
+
# Retrieve the preference
|
61
|
+
# Retrieve the preference and project of an organization. You can only retrieve preferences associated with your organization.
|
62
|
+
# @param id
|
63
|
+
# @param [Hash] opts the optional parameters
|
64
|
+
# @return [PreferenceResponse]
|
65
|
+
describe 'retrieve_preference test' do
|
66
|
+
it 'should work' do
|
67
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# unit tests for retrieve_preferences
|
72
|
+
# Retrieves a list of preferences
|
73
|
+
# Retrieves a list of preferences and associated projects of an organization. You can only retrieve preferences associated with your organization.
|
74
|
+
# @param [Hash] opts the optional parameters
|
75
|
+
# @option opts [Integer] :page
|
76
|
+
# @return [PreferenceListResponse]
|
77
|
+
describe 'retrieve_preferences test' do
|
78
|
+
it 'should work' do
|
79
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
=begin
|
2
|
+
#Patch API V1
|
3
|
+
|
4
|
+
#The core API used to integrate with Patch's service
|
5
|
+
|
6
|
+
The version of the OpenAPI document: v1
|
7
|
+
Contact: developers@usepatch.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 4.3.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
# Unit tests for Patch::ProjectsApi
|
17
|
+
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
18
|
+
# Please update as you see appropriate
|
19
|
+
describe 'ProjectsApi' do
|
20
|
+
before do
|
21
|
+
# run before each test
|
22
|
+
@api_instance = Patch::ProjectsApi.new
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
# run after each test
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'test an instance of ProjectsApi' do
|
30
|
+
it 'should create an instance of ProjectsApi' do
|
31
|
+
expect(@api_instance).to be_instance_of(Patch::ProjectsApi)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# unit tests for retrieve_project
|
36
|
+
# Retrieves a project
|
37
|
+
# Retrieves a project available on Patch's platform.
|
38
|
+
# @param id
|
39
|
+
# @param [Hash] opts the optional parameters
|
40
|
+
# @return [ProjectResponse]
|
41
|
+
describe 'retrieve_project test' do
|
42
|
+
it 'should work' do
|
43
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# unit tests for retrieve_projects
|
48
|
+
# Retrieves a list of projects
|
49
|
+
# Retrieves a list of projects available for purchase on Patch's platform.
|
50
|
+
# @param [Hash] opts the optional parameters
|
51
|
+
# @option opts [Integer] :page
|
52
|
+
# @return [ProjectListResponse]
|
53
|
+
describe 'retrieve_projects test' do
|
54
|
+
it 'should work' do
|
55
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,226 @@
|
|
1
|
+
=begin
|
2
|
+
#Patch API V1
|
3
|
+
|
4
|
+
#The core API used to integrate with Patch's service
|
5
|
+
|
6
|
+
The version of the OpenAPI document: v1
|
7
|
+
Contact: developers@usepatch.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 4.3.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
|
15
|
+
describe Patch::ApiClient do
|
16
|
+
context 'initialization' do
|
17
|
+
context 'URL stuff' do
|
18
|
+
context 'host' do
|
19
|
+
it 'removes http from host' do
|
20
|
+
Patch.configure { |c| c.host = 'http://example.com' }
|
21
|
+
expect(Patch::Configuration.default.host).to eq('example.com')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'removes https from host' do
|
25
|
+
Patch.configure { |c| c.host = 'https://wookiee.com' }
|
26
|
+
expect(Patch::ApiClient.default.config.host).to eq('wookiee.com')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'removes trailing path from host' do
|
30
|
+
Patch.configure { |c| c.host = 'hobo.com/v4' }
|
31
|
+
expect(Patch::Configuration.default.host).to eq('hobo.com')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'base_path' do
|
36
|
+
it "prepends a slash to base_path" do
|
37
|
+
Patch.configure { |c| c.base_path = 'v4/dog' }
|
38
|
+
expect(Patch::Configuration.default.base_path).to eq('/v4/dog')
|
39
|
+
end
|
40
|
+
|
41
|
+
it "doesn't prepend a slash if one is already there" do
|
42
|
+
Patch.configure { |c| c.base_path = '/v4/dog' }
|
43
|
+
expect(Patch::Configuration.default.base_path).to eq('/v4/dog')
|
44
|
+
end
|
45
|
+
|
46
|
+
it "ends up as a blank string if nil" do
|
47
|
+
Patch.configure { |c| c.base_path = nil }
|
48
|
+
expect(Patch::Configuration.default.base_path).to eq('')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'params_encoding in #build_request' do
|
55
|
+
let(:config) { Patch::Configuration.new }
|
56
|
+
let(:api_client) { Patch::ApiClient.new(config) }
|
57
|
+
|
58
|
+
it 'defaults to nil' do
|
59
|
+
expect(Patch::Configuration.default.params_encoding).to eq(nil)
|
60
|
+
expect(config.params_encoding).to eq(nil)
|
61
|
+
|
62
|
+
request = api_client.build_request(:get, '/test')
|
63
|
+
expect(request.options[:params_encoding]).to eq(nil)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'can be customized' do
|
67
|
+
config.params_encoding = :multi
|
68
|
+
request = api_client.build_request(:get, '/test')
|
69
|
+
expect(request.options[:params_encoding]).to eq(:multi)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'timeout in #build_request' do
|
74
|
+
let(:config) { Patch::Configuration.new }
|
75
|
+
let(:api_client) { Patch::ApiClient.new(config) }
|
76
|
+
|
77
|
+
it 'defaults to 0' do
|
78
|
+
expect(Patch::Configuration.default.timeout).to eq(0)
|
79
|
+
expect(config.timeout).to eq(0)
|
80
|
+
|
81
|
+
request = api_client.build_request(:get, '/test')
|
82
|
+
expect(request.options[:timeout]).to eq(0)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'can be customized' do
|
86
|
+
config.timeout = 100
|
87
|
+
request = api_client.build_request(:get, '/test')
|
88
|
+
expect(request.options[:timeout]).to eq(100)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#deserialize' do
|
93
|
+
it "handles Array<Integer>" do
|
94
|
+
api_client = Patch::ApiClient.new
|
95
|
+
headers = { 'Content-Type' => 'application/json' }
|
96
|
+
response = double('response', headers: headers, body: '[12, 34]')
|
97
|
+
data = api_client.deserialize(response, 'Array<Integer>')
|
98
|
+
expect(data).to be_instance_of(Array)
|
99
|
+
expect(data).to eq([12, 34])
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'handles Array<Array<Integer>>' do
|
103
|
+
api_client = Patch::ApiClient.new
|
104
|
+
headers = { 'Content-Type' => 'application/json' }
|
105
|
+
response = double('response', headers: headers, body: '[[12, 34], [56]]')
|
106
|
+
data = api_client.deserialize(response, 'Array<Array<Integer>>')
|
107
|
+
expect(data).to be_instance_of(Array)
|
108
|
+
expect(data).to eq([[12, 34], [56]])
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'handles Hash<String, String>' do
|
112
|
+
api_client = Patch::ApiClient.new
|
113
|
+
headers = { 'Content-Type' => 'application/json' }
|
114
|
+
response = double('response', headers: headers, body: '{"message": "Hello"}')
|
115
|
+
data = api_client.deserialize(response, 'Hash<String, String>')
|
116
|
+
expect(data).to be_instance_of(Hash)
|
117
|
+
expect(data).to eq(:message => 'Hello')
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "#object_to_hash" do
|
122
|
+
it 'ignores nils and includes empty arrays' do
|
123
|
+
# uncomment below to test object_to_hash for model
|
124
|
+
# api_client = Patch::ApiClient.new
|
125
|
+
# _model = Patch::ModelName.new
|
126
|
+
# update the model attribute below
|
127
|
+
# _model.id = 1
|
128
|
+
# update the expected value (hash) below
|
129
|
+
# expected = {id: 1, name: '', tags: []}
|
130
|
+
# expect(api_client.object_to_hash(_model)).to eq(expected)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#build_collection_param' do
|
135
|
+
let(:param) { ['aa', 'bb', 'cc'] }
|
136
|
+
let(:api_client) { Patch::ApiClient.new }
|
137
|
+
|
138
|
+
it 'works for csv' do
|
139
|
+
expect(api_client.build_collection_param(param, :csv)).to eq('aa,bb,cc')
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'works for ssv' do
|
143
|
+
expect(api_client.build_collection_param(param, :ssv)).to eq('aa bb cc')
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'works for tsv' do
|
147
|
+
expect(api_client.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc")
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'works for pipes' do
|
151
|
+
expect(api_client.build_collection_param(param, :pipes)).to eq('aa|bb|cc')
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'works for multi' do
|
155
|
+
expect(api_client.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc'])
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'fails for invalid collection format' do
|
159
|
+
expect { api_client.build_collection_param(param, :INVALID) }.to raise_error(RuntimeError, 'unknown collection format: :INVALID')
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '#json_mime?' do
|
164
|
+
let(:api_client) { Patch::ApiClient.new }
|
165
|
+
|
166
|
+
it 'works' do
|
167
|
+
expect(api_client.json_mime?(nil)).to eq false
|
168
|
+
expect(api_client.json_mime?('')).to eq false
|
169
|
+
|
170
|
+
expect(api_client.json_mime?('application/json')).to eq true
|
171
|
+
expect(api_client.json_mime?('application/json; charset=UTF8')).to eq true
|
172
|
+
expect(api_client.json_mime?('APPLICATION/JSON')).to eq true
|
173
|
+
|
174
|
+
expect(api_client.json_mime?('application/xml')).to eq false
|
175
|
+
expect(api_client.json_mime?('text/plain')).to eq false
|
176
|
+
expect(api_client.json_mime?('application/jsonp')).to eq false
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe '#select_header_accept' do
|
181
|
+
let(:api_client) { Patch::ApiClient.new }
|
182
|
+
|
183
|
+
it 'works' do
|
184
|
+
expect(api_client.select_header_accept(nil)).to be_nil
|
185
|
+
expect(api_client.select_header_accept([])).to be_nil
|
186
|
+
|
187
|
+
expect(api_client.select_header_accept(['application/json'])).to eq('application/json')
|
188
|
+
expect(api_client.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
|
189
|
+
expect(api_client.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
|
190
|
+
|
191
|
+
expect(api_client.select_header_accept(['application/xml'])).to eq('application/xml')
|
192
|
+
expect(api_client.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml')
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe '#select_header_content_type' do
|
197
|
+
let(:api_client) { Patch::ApiClient.new }
|
198
|
+
|
199
|
+
it 'works' do
|
200
|
+
expect(api_client.select_header_content_type(nil)).to eq('application/json')
|
201
|
+
expect(api_client.select_header_content_type([])).to eq('application/json')
|
202
|
+
|
203
|
+
expect(api_client.select_header_content_type(['application/json'])).to eq('application/json')
|
204
|
+
expect(api_client.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
|
205
|
+
expect(api_client.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
|
206
|
+
expect(api_client.select_header_content_type(['application/xml'])).to eq('application/xml')
|
207
|
+
expect(api_client.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain')
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe '#sanitize_filename' do
|
212
|
+
let(:api_client) { Patch::ApiClient.new }
|
213
|
+
|
214
|
+
it 'works' do
|
215
|
+
expect(api_client.sanitize_filename('sun')).to eq('sun')
|
216
|
+
expect(api_client.sanitize_filename('sun.gif')).to eq('sun.gif')
|
217
|
+
expect(api_client.sanitize_filename('../sun.gif')).to eq('sun.gif')
|
218
|
+
expect(api_client.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif')
|
219
|
+
expect(api_client.sanitize_filename('./sun.gif')).to eq('sun.gif')
|
220
|
+
expect(api_client.sanitize_filename('..\sun.gif')).to eq('sun.gif')
|
221
|
+
expect(api_client.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif')
|
222
|
+
expect(api_client.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif')
|
223
|
+
expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif')
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|