coinmarketcap_client 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +7 -0
- data/README.md +121 -0
- data/Rakefile +8 -0
- data/coinmarketcap_api.gemspec +45 -0
- data/coinmarketcap_client.gemspec +45 -0
- data/docs/DefaultApi.md +262 -0
- data/docs/Info.md +18 -0
- data/docs/InfoUrls.md +15 -0
- data/docs/InlineResponse200.md +9 -0
- data/docs/InlineResponse2001.md +9 -0
- data/docs/InlineResponse2002.md +9 -0
- data/docs/InlineResponse2003.md +9 -0
- data/docs/InlineResponse2004.md +9 -0
- data/docs/InlineResponse2005.md +9 -0
- data/docs/InlineResponseDefault.md +8 -0
- data/docs/InlineResponseDefault1.md +8 -0
- data/docs/Map.md +15 -0
- data/docs/MarketData.md +21 -0
- data/docs/Platform.md +12 -0
- data/docs/Quote.md +14 -0
- data/docs/Status.md +12 -0
- data/git_push.sh +55 -0
- data/lib/coinmarketcap_api.rb +50 -0
- data/lib/coinmarketcap_api/api/default_api.rb +145 -0
- data/lib/coinmarketcap_api/api_client.rb +389 -0
- data/lib/coinmarketcap_api/api_error.rb +38 -0
- data/lib/coinmarketcap_api/configuration.rb +209 -0
- data/lib/coinmarketcap_api/models/info.rb +276 -0
- data/lib/coinmarketcap_api/models/info_urls.rb +263 -0
- data/lib/coinmarketcap_api/models/inline_response_200.rb +194 -0
- data/lib/coinmarketcap_api/models/inline_response_200_1.rb +185 -0
- data/lib/coinmarketcap_api/models/inline_response_200_2.rb +194 -0
- data/lib/coinmarketcap_api/models/inline_response_200_3.rb +185 -0
- data/lib/coinmarketcap_api/models/inline_response_default.rb +183 -0
- data/lib/coinmarketcap_api/models/inline_response_default_1.rb +183 -0
- data/lib/coinmarketcap_api/models/map.rb +246 -0
- data/lib/coinmarketcap_api/models/status.rb +219 -0
- data/lib/coinmarketcap_api/version.rb +15 -0
- data/lib/coinmarketcap_client.rb +55 -0
- data/lib/coinmarketcap_client/api/default_api.rb +300 -0
- data/lib/coinmarketcap_client/api_client.rb +389 -0
- data/lib/coinmarketcap_client/api_error.rb +38 -0
- data/lib/coinmarketcap_client/configuration.rb +209 -0
- data/lib/coinmarketcap_client/models/info.rb +276 -0
- data/lib/coinmarketcap_client/models/info_urls.rb +263 -0
- data/lib/coinmarketcap_client/models/inline_response_200.rb +194 -0
- data/lib/coinmarketcap_client/models/inline_response_200_1.rb +194 -0
- data/lib/coinmarketcap_client/models/inline_response_200_2.rb +194 -0
- data/lib/coinmarketcap_client/models/inline_response_200_3.rb +194 -0
- data/lib/coinmarketcap_client/models/inline_response_200_4.rb +194 -0
- data/lib/coinmarketcap_client/models/inline_response_200_5.rb +194 -0
- data/lib/coinmarketcap_client/models/inline_response_default.rb +183 -0
- data/lib/coinmarketcap_client/models/inline_response_default_1.rb +183 -0
- data/lib/coinmarketcap_client/models/map.rb +246 -0
- data/lib/coinmarketcap_client/models/market_data.rb +304 -0
- data/lib/coinmarketcap_client/models/platform.rb +220 -0
- data/lib/coinmarketcap_client/models/quote.rb +237 -0
- data/lib/coinmarketcap_client/models/status.rb +219 -0
- data/lib/coinmarketcap_client/version.rb +15 -0
- data/spec/api/default_api_spec.rb +63 -0
- data/spec/api_client_spec.rb +226 -0
- data/spec/configuration_spec.rb +42 -0
- data/spec/models/info_spec.rb +101 -0
- data/spec/models/info_urls_spec.rb +83 -0
- data/spec/models/inline_response_200_1_spec.rb +41 -0
- data/spec/models/inline_response_200_2_spec.rb +47 -0
- data/spec/models/inline_response_200_3_spec.rb +41 -0
- data/spec/models/inline_response_200_4_spec.rb +47 -0
- data/spec/models/inline_response_200_5_spec.rb +47 -0
- data/spec/models/inline_response_200_spec.rb +47 -0
- data/spec/models/inline_response_default_1_spec.rb +41 -0
- data/spec/models/inline_response_default_spec.rb +41 -0
- data/spec/models/map_spec.rb +83 -0
- data/spec/models/market_data_spec.rb +119 -0
- data/spec/models/platform_spec.rb +65 -0
- data/spec/models/quote_spec.rb +77 -0
- data/spec/models/status_spec.rb +65 -0
- data/spec/spec_helper.rb +111 -0
- metadata +320 -0
@@ -0,0 +1,219 @@
|
|
1
|
+
=begin
|
2
|
+
#Coinmarketcap API Swagger Implementation
|
3
|
+
|
4
|
+
#Define coinmarketcap's api in swagger 2.0 openapi standard
|
5
|
+
|
6
|
+
OpenAPI spec version: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 2.4.4
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
|
15
|
+
module CoinmarketcapAPI
|
16
|
+
class Status
|
17
|
+
attr_accessor :timestamp
|
18
|
+
|
19
|
+
attr_accessor :error_code
|
20
|
+
|
21
|
+
attr_accessor :error_message
|
22
|
+
|
23
|
+
attr_accessor :elapsed
|
24
|
+
|
25
|
+
attr_accessor :credit_count
|
26
|
+
|
27
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
28
|
+
def self.attribute_map
|
29
|
+
{
|
30
|
+
:'timestamp' => :'timestamp',
|
31
|
+
:'error_code' => :'error_code',
|
32
|
+
:'error_message' => :'error_message',
|
33
|
+
:'elapsed' => :'elapsed',
|
34
|
+
:'credit_count' => :'credit_count'
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
# Attribute type mapping.
|
39
|
+
def self.swagger_types
|
40
|
+
{
|
41
|
+
:'timestamp' => :'DateTime',
|
42
|
+
:'error_code' => :'Integer',
|
43
|
+
:'error_message' => :'String',
|
44
|
+
:'elapsed' => :'Integer',
|
45
|
+
:'credit_count' => :'Integer'
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
# Initializes the object
|
50
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
51
|
+
def initialize(attributes = {})
|
52
|
+
return unless attributes.is_a?(Hash)
|
53
|
+
|
54
|
+
# convert string to symbol for hash key
|
55
|
+
attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
|
56
|
+
|
57
|
+
if attributes.has_key?(:'timestamp')
|
58
|
+
self.timestamp = attributes[:'timestamp']
|
59
|
+
end
|
60
|
+
|
61
|
+
if attributes.has_key?(:'error_code')
|
62
|
+
self.error_code = attributes[:'error_code']
|
63
|
+
end
|
64
|
+
|
65
|
+
if attributes.has_key?(:'error_message')
|
66
|
+
self.error_message = attributes[:'error_message']
|
67
|
+
end
|
68
|
+
|
69
|
+
if attributes.has_key?(:'elapsed')
|
70
|
+
self.elapsed = attributes[:'elapsed']
|
71
|
+
end
|
72
|
+
|
73
|
+
if attributes.has_key?(:'credit_count')
|
74
|
+
self.credit_count = attributes[:'credit_count']
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
79
|
+
# @return Array for valid properties with the reasons
|
80
|
+
def list_invalid_properties
|
81
|
+
invalid_properties = Array.new
|
82
|
+
invalid_properties
|
83
|
+
end
|
84
|
+
|
85
|
+
# Check to see if the all the properties in the model are valid
|
86
|
+
# @return true if the model is valid
|
87
|
+
def valid?
|
88
|
+
true
|
89
|
+
end
|
90
|
+
|
91
|
+
# Checks equality by comparing each attribute.
|
92
|
+
# @param [Object] Object to be compared
|
93
|
+
def ==(o)
|
94
|
+
return true if self.equal?(o)
|
95
|
+
self.class == o.class &&
|
96
|
+
timestamp == o.timestamp &&
|
97
|
+
error_code == o.error_code &&
|
98
|
+
error_message == o.error_message &&
|
99
|
+
elapsed == o.elapsed &&
|
100
|
+
credit_count == o.credit_count
|
101
|
+
end
|
102
|
+
|
103
|
+
# @see the `==` method
|
104
|
+
# @param [Object] Object to be compared
|
105
|
+
def eql?(o)
|
106
|
+
self == o
|
107
|
+
end
|
108
|
+
|
109
|
+
# Calculates hash code according to all attributes.
|
110
|
+
# @return [Fixnum] Hash code
|
111
|
+
def hash
|
112
|
+
[timestamp, error_code, error_message, elapsed, credit_count].hash
|
113
|
+
end
|
114
|
+
|
115
|
+
# Builds the object from hash
|
116
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
117
|
+
# @return [Object] Returns the model itself
|
118
|
+
def build_from_hash(attributes)
|
119
|
+
return nil unless attributes.is_a?(Hash)
|
120
|
+
self.class.swagger_types.each_pair do |key, type|
|
121
|
+
if type =~ /\AArray<(.*)>/i
|
122
|
+
# check to ensure the input is an array given that the the attribute
|
123
|
+
# is documented as an array but the input is not
|
124
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
125
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
126
|
+
end
|
127
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
128
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
129
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
130
|
+
end
|
131
|
+
|
132
|
+
self
|
133
|
+
end
|
134
|
+
|
135
|
+
# Deserializes the data based on type
|
136
|
+
# @param string type Data type
|
137
|
+
# @param string value Value to be deserialized
|
138
|
+
# @return [Object] Deserialized data
|
139
|
+
def _deserialize(type, value)
|
140
|
+
case type.to_sym
|
141
|
+
when :DateTime
|
142
|
+
DateTime.parse(value)
|
143
|
+
when :Date
|
144
|
+
Date.parse(value)
|
145
|
+
when :String
|
146
|
+
value.to_s
|
147
|
+
when :Integer
|
148
|
+
value.to_i
|
149
|
+
when :Float
|
150
|
+
value.to_f
|
151
|
+
when :BOOLEAN
|
152
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
153
|
+
true
|
154
|
+
else
|
155
|
+
false
|
156
|
+
end
|
157
|
+
when :Object
|
158
|
+
# generic object (usually a Hash), return directly
|
159
|
+
value
|
160
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
161
|
+
inner_type = Regexp.last_match[:inner_type]
|
162
|
+
value.map { |v| _deserialize(inner_type, v) }
|
163
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
164
|
+
k_type = Regexp.last_match[:k_type]
|
165
|
+
v_type = Regexp.last_match[:v_type]
|
166
|
+
{}.tap do |hash|
|
167
|
+
value.each do |k, v|
|
168
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
else # model
|
172
|
+
temp_model = CoinmarketcapAPI.const_get(type).new
|
173
|
+
temp_model.build_from_hash(value)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# Returns the string representation of the object
|
178
|
+
# @return [String] String presentation of the object
|
179
|
+
def to_s
|
180
|
+
to_hash.to_s
|
181
|
+
end
|
182
|
+
|
183
|
+
# to_body is an alias to to_hash (backward compatibility)
|
184
|
+
# @return [Hash] Returns the object in the form of hash
|
185
|
+
def to_body
|
186
|
+
to_hash
|
187
|
+
end
|
188
|
+
|
189
|
+
# Returns the object in the form of hash
|
190
|
+
# @return [Hash] Returns the object in the form of hash
|
191
|
+
def to_hash
|
192
|
+
hash = {}
|
193
|
+
self.class.attribute_map.each_pair do |attr, param|
|
194
|
+
value = self.send(attr)
|
195
|
+
next if value.nil?
|
196
|
+
hash[param] = _to_hash(value)
|
197
|
+
end
|
198
|
+
hash
|
199
|
+
end
|
200
|
+
|
201
|
+
# Outputs non-array value in the form of hash
|
202
|
+
# For object, use to_hash. Otherwise, just return the value
|
203
|
+
# @param [Object] value Any valid value
|
204
|
+
# @return [Hash] Returns the value in the form of hash
|
205
|
+
def _to_hash(value)
|
206
|
+
if value.is_a?(Array)
|
207
|
+
value.compact.map { |v| _to_hash(v) }
|
208
|
+
elsif value.is_a?(Hash)
|
209
|
+
{}.tap do |hash|
|
210
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
211
|
+
end
|
212
|
+
elsif value.respond_to? :to_hash
|
213
|
+
value.to_hash
|
214
|
+
else
|
215
|
+
value
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
=begin
|
2
|
+
#Coinmarketcap API Swagger Implementation
|
3
|
+
|
4
|
+
#Define coinmarketcap's api in swagger 2.0 openapi standard
|
5
|
+
|
6
|
+
OpenAPI spec version: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 2.4.4
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
module CoinmarketcapAPI
|
14
|
+
VERSION = '1.0.0'
|
15
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
=begin
|
2
|
+
#Coinmarketcap API Swagger Implementation
|
3
|
+
|
4
|
+
#Define coinmarketcap's api in swagger 2.0 openapi standard
|
5
|
+
|
6
|
+
OpenAPI spec version: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 2.4.4
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
# Unit tests for CoinmarketcapAPI::DefaultApi
|
17
|
+
# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
|
18
|
+
# Please update as you see appropriate
|
19
|
+
describe 'DefaultApi' do
|
20
|
+
before do
|
21
|
+
# run before each test
|
22
|
+
@instance = CoinmarketcapAPI::DefaultApi.new
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
# run after each test
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'test an instance of DefaultApi' do
|
30
|
+
it 'should create an instance of DefaultApi' do
|
31
|
+
expect(@instance).to be_instance_of(CoinmarketcapAPI::DefaultApi)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# unit tests for cryptocurrency_info_get
|
36
|
+
# Get metadata
|
37
|
+
# Returns all static metadata for one or more cryptocurrencies including name, symbol, logo, and its various registered URLs.
|
38
|
+
# @param [Hash] opts the optional parameters
|
39
|
+
# @option opts [String] :id One or more comma-separated CoinMarketCap cryptocurrency IDs. Example: \"1,2\"
|
40
|
+
# @option opts [String] :symbol Alternatively pass one or more comma-separated cryptocurrency symbols. Example: \"BTC,ETH\". At least one \"id\" or \"symbol\" is required.
|
41
|
+
# @return [InlineResponse2003]
|
42
|
+
describe 'cryptocurrency_info_get test' do
|
43
|
+
it 'should work' do
|
44
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# unit tests for cryptocurrency_map_get
|
49
|
+
# Get CoinMarketCap ID map
|
50
|
+
# Returns a paginated list of all cryptocurrencies by CoinMarketCap ID. We recommend using this convenience endpoint to lookup and utilize our unique cryptocurrency id across all endpoints as typical identifiers like ticker symbols can match multiple cryptocurrencies and change over time. As a convenience you may pass a comma-separated list of cryptocurrency symbols as symbol to filter this list to only those you require.
|
51
|
+
# @param [Hash] opts the optional parameters
|
52
|
+
# @option opts [String] :listing_status Only active coins are returned by default. Pass 'inactive' to get a list of coins that are no longer active.
|
53
|
+
# @option opts [Integer] :start Optionally offset the start (1-based index) of the paginated list of items to return.
|
54
|
+
# @option opts [Integer] :limit Optionally specify the number of results to return. Use this parameter and the \"start\" parameter to determine your own pagination size.
|
55
|
+
# @option opts [String] :symbol Optionally pass a comma-separated list of cryptocurrency symbols to return CoinMarketCap IDs for. If this option is passed, other options will be ignored.
|
56
|
+
# @return [InlineResponse2002]
|
57
|
+
describe 'cryptocurrency_map_get test' do
|
58
|
+
it 'should work' do
|
59
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,226 @@
|
|
1
|
+
=begin
|
2
|
+
#Coinmarketcap API Swagger Implementation
|
3
|
+
|
4
|
+
#Define coinmarketcap's api in swagger 2.0 openapi standard
|
5
|
+
|
6
|
+
OpenAPI spec version: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 2.4.4
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
|
15
|
+
describe CoinmarketcapAPI::ApiClient do
|
16
|
+
context 'initialization' do
|
17
|
+
context 'URL stuff' do
|
18
|
+
context 'host' do
|
19
|
+
it 'removes http from host' do
|
20
|
+
CoinmarketcapAPI.configure { |c| c.host = 'http://example.com' }
|
21
|
+
expect(CoinmarketcapAPI::Configuration.default.host).to eq('example.com')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'removes https from host' do
|
25
|
+
CoinmarketcapAPI.configure { |c| c.host = 'https://wookiee.com' }
|
26
|
+
expect(CoinmarketcapAPI::ApiClient.default.config.host).to eq('wookiee.com')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'removes trailing path from host' do
|
30
|
+
CoinmarketcapAPI.configure { |c| c.host = 'hobo.com/v4' }
|
31
|
+
expect(CoinmarketcapAPI::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
|
+
CoinmarketcapAPI.configure { |c| c.base_path = 'v4/dog' }
|
38
|
+
expect(CoinmarketcapAPI::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
|
+
CoinmarketcapAPI.configure { |c| c.base_path = '/v4/dog' }
|
43
|
+
expect(CoinmarketcapAPI::Configuration.default.base_path).to eq('/v4/dog')
|
44
|
+
end
|
45
|
+
|
46
|
+
it "ends up as a blank string if nil" do
|
47
|
+
CoinmarketcapAPI.configure { |c| c.base_path = nil }
|
48
|
+
expect(CoinmarketcapAPI::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) { CoinmarketcapAPI::Configuration.new }
|
56
|
+
let(:api_client) { CoinmarketcapAPI::ApiClient.new(config) }
|
57
|
+
|
58
|
+
it 'defaults to nil' do
|
59
|
+
expect(CoinmarketcapAPI::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) { CoinmarketcapAPI::Configuration.new }
|
75
|
+
let(:api_client) { CoinmarketcapAPI::ApiClient.new(config) }
|
76
|
+
|
77
|
+
it 'defaults to 0' do
|
78
|
+
expect(CoinmarketcapAPI::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 = CoinmarketcapAPI::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 = CoinmarketcapAPI::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 = CoinmarketcapAPI::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 = CoinmarketcapAPI::ApiClient.new
|
125
|
+
# _model = CoinmarketcapAPI::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) { CoinmarketcapAPI::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(proc { 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) { CoinmarketcapAPI::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) { CoinmarketcapAPI::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) { CoinmarketcapAPI::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) { CoinmarketcapAPI::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
|