coincap 0.1.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 769b5aae59da08d6280a6982da0ca953443cd35b9652c94b5a1120d365563416
4
- data.tar.gz: 7fb79111622a4237e07696889c7fa5c70f68e8c1a495426bb7c665b72120abfa
3
+ metadata.gz: 3804fc6897bedeab59d3433b78d966c9ead78b479ddda7fa68224dc82ab3269a
4
+ data.tar.gz: e1d4b18de106069036912318ae4fe7c5fab9bfa9eee8f2ec148933f6642a2061
5
5
  SHA512:
6
- metadata.gz: 7a6b8b0c5773cdc3784a3fa353e3054be921e2e8d44a8057d52d06b6a2291c666fbfed5b2d7fc32246db1751ed9bc3d8828d32e098e1b83412b9f4e02d936e5e
7
- data.tar.gz: a54d75fa5f9f0a1c9d1332bf99f07ec025c61d9516342296dfce90785c157a138007058d48c5cf328dd8f4daea69b18bd503a215e0bce396acb96423421a8b1e
6
+ metadata.gz: 8460be7cd7edce7958d0648e71703777f4330901a53b19cab7e461d88f86bbb42d4050bd87681e422e09d9a8f54ded167b5ef293a846e863e26f2b38efdccc55
7
+ data.tar.gz: 27d35e1375e21db51c987d76ac0404bb654cf4511d1e472ec8110bbfccc193219175aacd578797a0908a4f90952884bcf53957e059855e1452387277474b03dc
data/.rubocop.yml ADDED
@@ -0,0 +1,178 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ Gemspec/DeprecatedAttributeAssignment: # new in 1.30
4
+ Enabled: true
5
+ Gemspec/DevelopmentDependencies: # new in 1.44
6
+ Enabled: true
7
+ Gemspec/RequireMFA: # new in 1.23
8
+ Enabled: false
9
+ Layout/LineContinuationLeadingSpace: # new in 1.31
10
+ Enabled: true
11
+ Layout/LineContinuationSpacing: # new in 1.31
12
+ Enabled: true
13
+ Layout/LineEndStringConcatenationIndentation: # new in 1.18
14
+ Enabled: true
15
+ Layout/SpaceBeforeBrackets: # new in 1.7
16
+ Enabled: true
17
+ Lint/AmbiguousAssignment: # new in 1.7
18
+ Enabled: true
19
+ Lint/AmbiguousOperatorPrecedence: # new in 1.21
20
+ Enabled: true
21
+ Lint/AmbiguousRange: # new in 1.19
22
+ Enabled: true
23
+ Lint/ConstantOverwrittenInRescue: # new in 1.31
24
+ Enabled: true
25
+ Lint/DeprecatedConstants: # new in 1.8
26
+ Enabled: true
27
+ Lint/DuplicateBranch: # new in 1.3
28
+ Enabled: true
29
+ Lint/DuplicateMagicComment: # new in 1.37
30
+ Enabled: true
31
+ Lint/DuplicateMatchPattern: # new in 1.50
32
+ Enabled: true
33
+ Lint/DuplicateRegexpCharacterClassElement: # new in 1.1
34
+ Enabled: true
35
+ Lint/EmptyBlock: # new in 1.1
36
+ Enabled: true
37
+ Lint/EmptyClass: # new in 1.3
38
+ Enabled: true
39
+ Lint/EmptyInPattern: # new in 1.16
40
+ Enabled: true
41
+ Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
42
+ Enabled: true
43
+ Lint/LambdaWithoutLiteralBlock: # new in 1.8
44
+ Enabled: true
45
+ Lint/NoReturnInBeginEndBlocks: # new in 1.2
46
+ Enabled: true
47
+ Lint/NonAtomicFileOperation: # new in 1.31
48
+ Enabled: true
49
+ Lint/NumberedParameterAssignment: # new in 1.9
50
+ Enabled: true
51
+ Lint/OrAssignmentToConstant: # new in 1.9
52
+ Enabled: true
53
+ Lint/RedundantDirGlobSort: # new in 1.8
54
+ Enabled: true
55
+ Lint/RefinementImportMethods: # new in 1.27
56
+ Enabled: true
57
+ Lint/RequireRangeParentheses: # new in 1.32
58
+ Enabled: true
59
+ Lint/RequireRelativeSelfPath: # new in 1.22
60
+ Enabled: true
61
+ Lint/SymbolConversion: # new in 1.9
62
+ Enabled: false
63
+ Lint/ToEnumArguments: # new in 1.1
64
+ Enabled: true
65
+ Lint/TripleQuotes: # new in 1.9
66
+ Enabled: true
67
+ Lint/UnexpectedBlockArity: # new in 1.5
68
+ Enabled: true
69
+ Lint/UnmodifiedReduceAccumulator: # new in 1.1
70
+ Enabled: true
71
+ Lint/UselessRescue: # new in 1.43
72
+ Enabled: true
73
+ Lint/UselessRuby2Keywords: # new in 1.23
74
+ Enabled: true
75
+ Metrics/CollectionLiteralLength: # new in 1.47
76
+ Enabled: true
77
+ Naming/BlockForwarding: # new in 1.24
78
+ Enabled: true
79
+ Security/CompoundHash: # new in 1.28
80
+ Enabled: true
81
+ Security/IoMethods: # new in 1.22
82
+ Enabled: true
83
+ Style/ArgumentsForwarding: # new in 1.1
84
+ Enabled: true
85
+ Style/ArrayIntersect: # new in 1.40
86
+ Enabled: true
87
+ Style/CollectionCompact: # new in 1.2
88
+ Enabled: true
89
+ Style/ComparableClamp: # new in 1.44
90
+ Enabled: true
91
+ Style/ConcatArrayLiterals: # new in 1.41
92
+ Enabled: true
93
+ Style/DataInheritance: # new in 1.49
94
+ Enabled: true
95
+ Style/DirEmpty: # new in 1.48
96
+ Enabled: true
97
+ Style/DocumentDynamicEvalDefinition: # new in 1.1
98
+ Enabled: false
99
+ Style/EmptyHeredoc: # new in 1.32
100
+ Enabled: true
101
+ Style/EndlessMethod: # new in 1.8
102
+ Enabled: true
103
+ Style/EnvHome: # new in 1.29
104
+ Enabled: true
105
+ Style/FetchEnvVar: # new in 1.28
106
+ Enabled: true
107
+ Style/FileEmpty: # new in 1.48
108
+ Enabled: true
109
+ Style/FileRead: # new in 1.24
110
+ Enabled: true
111
+ Style/FileWrite: # new in 1.24
112
+ Enabled: true
113
+ Style/HashConversion: # new in 1.10
114
+ Enabled: true
115
+ Style/HashExcept: # new in 1.7
116
+ Enabled: true
117
+ Style/IfWithBooleanLiteralBranches: # new in 1.9
118
+ Enabled: true
119
+ Style/InPatternThen: # new in 1.16
120
+ Enabled: true
121
+ Style/MagicCommentFormat: # new in 1.35
122
+ Enabled: true
123
+ Style/MapCompactWithConditionalBlock: # new in 1.30
124
+ Enabled: true
125
+ Style/MapToHash: # new in 1.24
126
+ Enabled: true
127
+ Style/MapToSet: # new in 1.42
128
+ Enabled: true
129
+ Style/MinMaxComparison: # new in 1.42
130
+ Enabled: true
131
+ Style/MultilineInPatternThen: # new in 1.16
132
+ Enabled: true
133
+ Style/NegatedIfElseCondition: # new in 1.2
134
+ Enabled: true
135
+ Style/NestedFileDirname: # new in 1.26
136
+ Enabled: true
137
+ Style/NilLambda: # new in 1.3
138
+ Enabled: true
139
+ Style/NumberedParameters: # new in 1.22
140
+ Enabled: true
141
+ Style/NumberedParametersLimit: # new in 1.22
142
+ Enabled: true
143
+ Style/ObjectThen: # new in 1.28
144
+ Enabled: true
145
+ Style/OpenStructUse: # new in 1.23
146
+ Enabled: true
147
+ Style/OperatorMethodCall: # new in 1.37
148
+ Enabled: true
149
+ Style/QuotedSymbols: # new in 1.16
150
+ Enabled: true
151
+ Style/RedundantArgument: # new in 1.4
152
+ Enabled: true
153
+ Style/RedundantConstantBase: # new in 1.40
154
+ Enabled: true
155
+ Style/RedundantDoubleSplatHashBraces: # new in 1.41
156
+ Enabled: true
157
+ Style/RedundantEach: # new in 1.38
158
+ Enabled: true
159
+ Style/RedundantHeredocDelimiterQuotes: # new in 1.45
160
+ Enabled: true
161
+ Style/RedundantInitialize: # new in 1.27
162
+ Enabled: true
163
+ Style/RedundantLineContinuation: # new in 1.49
164
+ Enabled: true
165
+ Style/RedundantSelfAssignmentBranch: # new in 1.19
166
+ Enabled: true
167
+ Style/RedundantStringEscape: # new in 1.37
168
+ Enabled: true
169
+ Style/SelectByRegexp: # new in 1.22
170
+ Enabled: true
171
+ Style/StringChars: # new in 1.12
172
+ Enabled: true
173
+ Style/SwapValues: # new in 1.1
174
+ Enabled: true
175
+ Layout/LineLength:
176
+ Enabled: false
177
+ Style/EvalWithLocation:
178
+ Enabled: false
data/Gemfile CHANGED
@@ -13,3 +13,5 @@ group :test do
13
13
  gem 'minitest', '~> 5.18'
14
14
  gem 'rake', '~> 13.0'
15
15
  end
16
+
17
+ gem "websocket-client-simple", "~> 0.8.0"
data/Gemfile.lock CHANGED
@@ -1,20 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coincap (0.1.3)
4
+ coincap (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ event_emitter (0.2.6)
9
10
  json (2.6.3)
10
- minitest (5.18.0)
11
+ minitest (5.20.0)
11
12
  net-http (0.3.2)
12
13
  uri
13
- openssl (3.1.0)
14
+ openssl (3.2.0)
14
15
  rake (13.0.6)
15
- uri (0.12.1)
16
+ uri (0.12.2)
17
+ websocket (1.2.10)
18
+ websocket-client-simple (0.8.0)
19
+ event_emitter
20
+ websocket
16
21
 
17
22
  PLATFORMS
23
+ x86_64-darwin-22
18
24
  x86_64-linux
19
25
 
20
26
  DEPENDENCIES
@@ -25,6 +31,7 @@ DEPENDENCIES
25
31
  openssl (~> 3.1)
26
32
  rake (~> 13.0)
27
33
  uri (~> 0.12.1)
34
+ websocket-client-simple (~> 0.8.0)
28
35
 
29
36
  BUNDLED WITH
30
- 2.4.10
37
+ 2.5.6
data/README.md CHANGED
@@ -20,7 +20,7 @@ Detailed information [here](https://docs.coincap.io/).
20
20
 
21
21
  ## Assets Price
22
22
  ```Ruby
23
- data = Coincap::AssetsPrice.cryptocurrencies
23
+ data = Coincap::Assets.list
24
24
  ```
25
25
  ```JSON
26
26
  {
@@ -45,7 +45,7 @@ data = Coincap::AssetsPrice.cryptocurrencies
45
45
  ```
46
46
 
47
47
  ```Ruby
48
- data = Coincap::AssetsPrice.cryptocurrency('bitcoin')
48
+ data = Coincap::Assets.single('bitcoin')
49
49
  ```
50
50
  ```JSON
51
51
  {
@@ -67,7 +67,15 @@ data = Coincap::AssetsPrice.cryptocurrency('bitcoin')
67
67
  ```
68
68
 
69
69
  ```Ruby
70
- data = Coincap::AssetsPrice.cryptocurrency_history('bitcoin', :one_minute)
70
+ data = Coincap::Assets.history('bitcoin', :one_minute)
71
+ ```
72
+ or
73
+ ```Ruby
74
+ data = Coincap::Assets.history_one_minute('bitcoin')
75
+ ```
76
+ and with timestamp
77
+ ```Ruby
78
+ data = Coincap::Assets.history_one_minute('bitcoin', 1530403200000, 1533581103627)
71
79
  ```
72
80
  ```JSON
73
81
  {
@@ -83,7 +91,7 @@ data = Coincap::AssetsPrice.cryptocurrency_history('bitcoin', :one_minute)
83
91
  ```
84
92
 
85
93
  ```Ruby
86
- data = Coincap::AssetsPrice.cryptocurrency_with_markets('bitcoin')
94
+ data = Coincap::Assets.markets('bitcoin')
87
95
  ```
88
96
  ```JSON
89
97
  {
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
5
 
6
6
  Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/test_*.rb"]
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/test_*.rb']
10
10
  end
11
11
 
12
- task default: :test
12
+ task default: :test
@@ -8,8 +8,8 @@ module Coincap
8
8
  # meaning higher volume exchanges have more affect on this global price.
9
9
  # All values are translated into USD (United States Dollar)
10
10
  # and can be translated into other units of measurement through the /rates endpoint.
11
- module AssetsPrice
12
- URI_API = 'https://api.coincap.io/v2/assets'
11
+ module Assets
12
+ URI_API = "#{BASE_URI}#{VERSION_API}/assets"
13
13
 
14
14
  TIME_INTERVAL = {
15
15
  one_minute: 'm1',
@@ -49,9 +49,9 @@ module Coincap
49
49
  # @param [String] ids (nil) Query with multiple ids=bitcoin,ethereum,monero
50
50
  # @param [Integer] limit (nil) Max limit of 2000
51
51
  # @param [Integer] offset (nil) Offset
52
- # @return [String]
53
- def self.cryptocurrencies(search: nil, ids: nil, limit: nil, offset: nil)
54
- Helper.request_to_read_data(URI_API, search: search, ids: ids, limit: limit, offset: offset)
52
+ # @return [Hash]
53
+ def self.list(search: nil, ids: nil, limit: nil, offset: nil)
54
+ Helper.fetch_data(URI_API, search: search, ids: ids, limit: limit, offset: offset)
55
55
  end
56
56
 
57
57
  # Get single cryptocurrency
@@ -73,10 +73,10 @@ module Coincap
73
73
  # "timestamp": 1533581098863
74
74
  # }
75
75
  #
76
- # @param [String] asset_id Asset id, for example, bitcoin
77
- # @return [String]
78
- def self.cryptocurrency(asset_id)
79
- Helper.request_to_read_data("#{URI_API}/#{asset_id}")
76
+ # @param asset_id [String] Asset id, for example, bitcoin
77
+ # @return [Hash]
78
+ def self.single(asset_id)
79
+ Helper.fetch_data("#{URI_API}/#{asset_id}")
80
80
  end
81
81
 
82
82
  # Get cryptocurrency history price
@@ -92,12 +92,36 @@ module Coincap
92
92
  # "timestamp": 1533581103627
93
93
  # }
94
94
  #
95
- # @param [String] asset_id Asset id, for example, bitcoin
96
- # @param [Symbol] interval Select one from the list m1,m5,m15,m30,h1,h2,h6,h12,d1, for example, m1 or write a symbol, for example, :one_minute
97
- # @return [String]
98
- def self.cryptocurrency_history(asset_id, interval)
99
- Helper.request_to_read_data("#{URI_API}/#{asset_id}/history",
100
- interval: interval.is_a?(Symbol) ? TIME_INTERVAL[interval] : interval)
95
+ # You can call the method like this:
96
+ #
97
+ # Coincap::AssetsPrice.cryptocurrency_history('bitcoin', :one_minute)
98
+ #
99
+ # Coincap::AssetsPrice.cryptocurrency_history('bitcoin', 'm1')
100
+ #
101
+ #
102
+ # Or like this:
103
+ #
104
+ # Coincap::AssetsPrice.cryptocurrency_history_one_minute('bitcoin')
105
+ #
106
+ # @param asset_id [String] Asset id, for example, bitcoin
107
+ # @param interval [Symbol|String] Select one from the list of TIME_INTERVAL values
108
+ # for example, a string 'm1' or a symbol :one_minute
109
+ # @param start_at [Integer] Start time in milliseconds
110
+ # @param end_at [Integer] End time in milliseconds
111
+ # @return [Hash]
112
+ def self.history(asset_id, interval, start_at = nil, end_at = nil)
113
+ Helper.fetch_data("#{URI_API}/#{asset_id}/history",
114
+ interval: interval.is_a?(Symbol) ? TIME_INTERVAL[interval] : interval,
115
+ start: start_at,
116
+ end: end_at)
117
+ end
118
+
119
+ TIME_INTERVAL.each do |key, value|
120
+ class_eval <<~RUBY
121
+ def self.history_#{key}(asset_id, start_at = nil, end_at = nil)
122
+ self.history(asset_id, '#{value}', start_at, end_at)
123
+ end
124
+ RUBY
101
125
  end
102
126
 
103
127
  # Get price cryptocurrency with markets
@@ -119,12 +143,12 @@ module Coincap
119
143
  # "timestamp": 1539289444052
120
144
  # }
121
145
  #
122
- # @param [String] asset_id Asset id, for example, bitcoin
123
- # @param [Integer] limit Max limit of 2000
124
- # @param [Integer] offset Offset
125
- # @return [String]
126
- def self.cryptocurrency_with_markets(asset_id, limit: nil, offset: nil)
127
- Helper.request_to_read_data("#{URI_API}/#{asset_id}/markets", limit: limit, offset: offset)
146
+ # @param asset_id [String] Asset id, for example, bitcoin
147
+ # @param limit [Integer] Max limit of 2000
148
+ # @param offset [Integer] Offset
149
+ # @return [Hash]
150
+ def self.markets(asset_id, limit: nil, offset: nil)
151
+ Helper.fetch_data("#{URI_API}/#{asset_id}/markets", limit: limit, offset: offset)
128
152
  end
129
153
  end
130
154
  end
@@ -11,7 +11,7 @@ module Coincap
11
11
  # For that purpose you will find an "updated" key for each exchange.
12
12
  # For more details into coin pairs and volume, see the /markets endpoint.
13
13
  module Exchanges
14
- URI_API = 'https://api.coincap.io/v2/exchanges'
14
+ URI_API = "#{BASE_URI}#{VERSION_API}/exchanges"
15
15
 
16
16
  # Returns a list of all exchanges.
17
17
  #
@@ -33,9 +33,9 @@ module Coincap
33
33
  # "timestamp": 1536605835421
34
34
  # }
35
35
  #
36
- # @return [String]
36
+ # @return [Hash]
37
37
  def self.list
38
- Helper.request_to_read_data(URI_API)
38
+ Helper.fetch_data(URI_API)
39
39
  end
40
40
 
41
41
  # Returns a single exchange.
@@ -55,10 +55,10 @@ module Coincap
55
55
  # "timestamp": 1536605874069
56
56
  # }
57
57
  #
58
- # @param exchange_id [String]
59
- # @return [String]
58
+ # @param exchange_id [String] Search by exchange name, for example, kraken
59
+ # @return [Hash]
60
60
  def self.single(exchange_id)
61
- Helper.request_to_read_data("#{URI_API}/#{exchange_id}")
61
+ Helper.fetch_data("#{URI_API}/#{exchange_id}")
62
62
  end
63
63
  end
64
64
  end
@@ -6,31 +6,37 @@ require 'net/http'
6
6
  require 'openssl'
7
7
 
8
8
  module Coincap
9
+ BASE_URI = 'https://api.coincap.io/'
10
+ VERSION_API = 'v2'
11
+
9
12
  # Helper module
10
13
  module Helper
11
14
  class << self
12
15
  # Request to read data
13
- # @param uri_string [String] string of the uri
14
- # @param queries_hash [Hash] queries hash for the request
15
- # @return [String]
16
- def request_to_read_data(uri_string, **queries_hash)
17
- http_get convert_hash_to_uri(uri_string, **queries_hash)
16
+ #
17
+ # @param uri_string [String] String of the uri
18
+ # @param queries_hash [Hash] Queries hash for the request
19
+ # @return [Hash] Hash of the response
20
+ def fetch_data(uri_string, **queries_hash)
21
+ url = build_uri(uri_string, **queries_hash)
22
+ data = http_get url
23
+ JSON.parse data
18
24
  end
19
25
 
20
26
  private
21
27
 
22
28
  def http_get(uri)
23
- config = Coincap.instance_variable_get(:@config)
29
+ config = Coincap.config
24
30
 
25
31
  headers = {
26
- 'Accept-Encoding': config.accept_encoding.nil? ? nil : config.accept_encoding,
32
+ 'Accept-Encoding': config.accept_encoding,
27
33
  'Authorization': config.api_key.nil? ? nil : "Bearer #{config.api_key}"
28
34
  }.compact
29
35
 
30
36
  Net::HTTP.get(uri, headers)
31
37
  end
32
38
 
33
- def convert_hash_to_uri(uri, **queries_hash)
39
+ def build_uri(uri, **queries_hash)
34
40
  queries_str = queries_hash.compact.map { |key, value| "#{key}=#{value}" }.join('&')
35
41
  URI("#{uri}#{queries_str.empty? ? '' : "?#{queries_str}"}")
36
42
  end
@@ -0,0 +1,46 @@
1
+ require 'websocket-client-simple'
2
+
3
+ module Coincap
4
+ class LiveAssets
5
+ BASE_URI = 'wss://ws.coincap.io/prices?assets='
6
+
7
+ # Initialize the websocket
8
+ # @param assets [Array] List of assets
9
+ def initialize(assets = 'ALL')
10
+ @assets = assets
11
+ end
12
+
13
+ # Connect to the websocket
14
+ def connect
15
+ uri = "#{BASE_URI}#{@assets == 'ALL' ? @assets : @assets.join(',')}"
16
+ @ws = WebSocket::Client::Simple.connect(uri)
17
+ end
18
+
19
+ # Close the websocket
20
+ def disconnect
21
+ @ws.close
22
+ end
23
+
24
+ # When receive the price
25
+ def on_price(&on_message)
26
+ @ws.on :message do |event|
27
+ on_message.call(event.data)
28
+ end
29
+ end
30
+
31
+ # When open the websocket
32
+ def on_open(&on_open)
33
+ @ws.on :open, &on_open
34
+ end
35
+
36
+ # When close the websocket
37
+ def on_close(&on_close)
38
+ @ws.on :close, &on_close
39
+ end
40
+
41
+ # When error
42
+ def on_error(&on_error)
43
+ @ws.on :error, &on_error
44
+ end
45
+ end
46
+ end
@@ -10,7 +10,7 @@ module Coincap
10
10
  # All market data represents actual trades processed, orders on an exchange are not represented.
11
11
  # Data received from individual markets is used to calculate the current price of an asset.
12
12
  module Markets
13
- URI_API = 'https://api.coincap.io/v2/markets'
13
+ URI_API = "#{BASE_URI}#{VERSION_API}/markets"
14
14
 
15
15
  # Returns a list of all markets.
16
16
  #
@@ -35,27 +35,27 @@ module Coincap
35
35
  # "timestamp": 1533581173350
36
36
  # }
37
37
  #
38
- # @param [String] exchange_id (nil) Search by exchange id (e.g. 'binance')
39
- # @param [String] base_symbol (nil) Returns all containing the base symbol
40
- # @param [String] quote_symbol (nil) Returns all containing the quote symbol
41
- # @param [String] base_id (nil) Returns all containing the base id
42
- # @param [String] quote_id (nil) Returns all containing the quote id
43
- # @param [String] asset_symbol (nil) Returns all assets containing symbol (base and quote)
44
- # @param [String] asset_id (nil) Returns all assets containing id (base and quote)
45
- # @param [Integer] limit (nil) Max limit of 2000
46
- # @param [Integer] offset (nil) The number of results to skip
47
- # @return [String]
38
+ # @param exchange_id (nil) [String] Search by exchange id (e.g. 'binance')
39
+ # @param base_symbol (nil) [String] Returns all containing the base symbol
40
+ # @param quote_symbol (nil) [String] Returns all containing the quote symbol
41
+ # @param base_id (nil) [String] Returns all containing the base id
42
+ # @param quote_id (nil) [String] Returns all containing the quote id
43
+ # @param asset_symbol (nil) [String] Returns all assets containing symbol (base and quote)
44
+ # @param asset_id (nil) [String] Returns all assets containing id (base and quote)
45
+ # @param limit (nil) [Integer] Max limit of 2000
46
+ # @param offset (nil) [Integer] The number of results to skip
47
+ # @return [Hash]
48
48
  def self.list(**options)
49
- Helper.request_to_read_data(URI_API,
50
- 'exchangeId': options[:exchange_id],
51
- 'baseSymbol': options[:base_symbol],
52
- 'quoteSymbol': options[:quote_symbol],
53
- 'baseId': options[:base_id],
54
- 'quoteId': options[:quote_id],
55
- 'assetSymbol': options[:asset_symbol],
56
- 'assetId': options[:asset_id],
57
- 'limit': options[:limit],
58
- 'offset': options[:offset])
49
+ Helper.fetch_data(URI_API,
50
+ exchangeId: options[:exchange_id],
51
+ baseSymbol: options[:base_symbol],
52
+ quoteSymbol: options[:quote_symbol],
53
+ baseId: options[:base_id],
54
+ quoteId: options[:quote_id],
55
+ assetSymbol: options[:asset_symbol],
56
+ assetId: options[:asset_id],
57
+ limit: options[:limit],
58
+ offset: options[:offset])
59
59
  end
60
60
  end
61
61
  end
data/lib/coincap/rates.rb CHANGED
@@ -8,7 +8,7 @@ module Coincap
8
8
  # We offer fiat and top cryptocurrency translated rates.
9
9
  # Fiat rates are available through OpenExchangeRates.org.
10
10
  module Rates
11
- URI_API = 'https://api.coincap.io/v2/rates'
11
+ URI_API = "#{BASE_URI}#{VERSION_API}/rates"
12
12
 
13
13
  # Returns a list of all rates.
14
14
  #
@@ -26,9 +26,9 @@ module Coincap
26
26
  # "timestamp": 1536347807471
27
27
  # }
28
28
  #
29
- # @return [String]
29
+ # @return [Hash]
30
30
  def self.list
31
- Helper.request_to_read_data(URI_API)
31
+ Helper.fetch_data(URI_API)
32
32
  end
33
33
 
34
34
  # Returns a single rate.
@@ -45,9 +45,9 @@ module Coincap
45
45
  # }
46
46
  #
47
47
  # @param asset_id [String] The asset id (bitcoin)
48
- # @return [String]
48
+ # @return [Hash]
49
49
  def self.single(asset_id)
50
- Helper.request_to_read_data("#{URI_API}/#{asset_id}")
50
+ Helper.fetch_data("#{URI_API}/#{asset_id}")
51
51
  end
52
52
  end
53
53
  end
@@ -1,5 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Coincap
4
- VERSION = '0.1.3'
4
+ MAJOR = 0
5
+ MINOR = 3
6
+ PATCH = 0
7
+
8
+ private_constant :MAJOR, :MINOR, :PATCH
9
+
10
+ VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
5
11
  end
data/lib/coincap.rb CHANGED
@@ -1,18 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'coincap/version'
4
- require_relative 'coincap/assets_price'
3
+ require_relative 'coincap/assets'
4
+ require_relative 'coincap/exchanges'
5
5
  require_relative 'coincap/helper'
6
+ require_relative 'coincap/live_assets'
6
7
  require_relative 'coincap/markets'
7
8
  require_relative 'coincap/rates'
8
- require_relative 'coincap/exchanges'
9
+ require_relative 'coincap/version'
9
10
 
10
11
  # CoinCap 2.0 RESTful API is currently in production!
11
12
  # The CoinCap team is excited to offer you new endpoints and more clarity on pricing!
13
+ #
12
14
  # CoinCap 2.0 launched on September 26, 2018.
13
15
  # Please let us know what you like, what you would hope to see, or any bugs/changes that you'd like to document.
16
+ #
14
17
  # The easiest way to submit feedback to our team is to fill out a support ticket here.
15
18
  # The old CoinCap API is deprecated and was shut down on March 1, 2019.
19
+ #
16
20
  # For any issues with transitioning from the old CoinCap API to the new,
17
21
  # please submit feedback via the zendesk link above!
18
22
  module Coincap
@@ -29,10 +33,16 @@ module Coincap
29
33
  end
30
34
  end
31
35
 
32
- @config = Configuration.new
36
+ class << self
37
+ # Configuration the Coincap API
38
+ # @return [Coincap::Configuration]
39
+ def config
40
+ @config ||= Configuration.new
41
+ end
33
42
 
34
- # Configuration the Coincap API
35
- def self.configure
36
- yield @config
43
+ # Configuration the Coincap API
44
+ def self.configure
45
+ yield config
46
+ end
37
47
  end
38
48
  end
metadata CHANGED
@@ -1,43 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coincap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - cosmic-1
8
- autorequire:
7
+ - Vitalii Bakun
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-18 00:00:00.000000000 Z
11
+ date: 2024-04-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: CoinCap is a useful tool for real-time pricing and market activity for
14
- over 1,000 cryptocurrencies.
13
+ description: " CoinCap is a useful tool for real-time pricing and market activity
14
+ for over 1,000 cryptocurrencies.\n"
15
15
  email:
16
16
  - crossdoh@gmail.com
17
17
  executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - ".rubocop.yml"
21
22
  - Gemfile
22
23
  - Gemfile.lock
23
24
  - LICENSE.txt
24
25
  - README.md
25
26
  - Rakefile
26
- - coincap.gemspec
27
27
  - lib/coincap.rb
28
- - lib/coincap/assets_price.rb
28
+ - lib/coincap/assets.rb
29
29
  - lib/coincap/exchanges.rb
30
30
  - lib/coincap/helper.rb
31
+ - lib/coincap/live_assets.rb
31
32
  - lib/coincap/markets.rb
32
33
  - lib/coincap/rates.rb
33
34
  - lib/coincap/version.rb
34
- homepage:
35
+ homepage:
35
36
  licenses:
36
37
  - MIT
37
38
  metadata:
38
39
  allowed_push_host: https://rubygems.org
39
- source_code_uri: https://github.com/Cosmic-1/coincap
40
- post_install_message:
40
+ source_code_uri: https://github.com/vitalii-bakun/coincap
41
+ post_install_message:
41
42
  rdoc_options: []
42
43
  require_paths:
43
44
  - lib
@@ -45,15 +46,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
46
  requirements:
46
47
  - - ">="
47
48
  - !ruby/object:Gem::Version
48
- version: 2.6.0
49
+ version: 2.7.0
49
50
  required_rubygems_version: !ruby/object:Gem::Requirement
50
51
  requirements:
51
52
  - - ">="
52
53
  - !ruby/object:Gem::Version
53
54
  version: '0'
54
55
  requirements: []
55
- rubygems_version: 3.4.10
56
- signing_key:
56
+ rubygems_version: 3.5.6
57
+ signing_key:
57
58
  specification_version: 4
58
59
  summary: CoinCap is a useful tool for real-time pricing and market activity for over
59
60
  1,000 cryptocurrencies.
data/coincap.gemspec DELETED
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/coincap/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'coincap'
7
- spec.version = Coincap::VERSION
8
- spec.authors = ['cosmic-1']
9
- spec.email = ['crossdoh@gmail.com']
10
-
11
- spec.summary = 'CoinCap is a useful tool for real-time pricing and market activity for over 1,000 cryptocurrencies.'
12
- spec.description = 'CoinCap is a useful tool for real-time pricing and market activity for over 1,000 cryptocurrencies.'
13
- spec.license = 'MIT'
14
- spec.required_ruby_version = '>= 2.6.0'
15
-
16
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
17
-
18
- spec.metadata['source_code_uri'] = 'https://github.com/Cosmic-1/coincap'
19
-
20
- # Specify which files should be added to the gem when it is released.
21
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
- spec.files = Dir.chdir(__dir__) do
23
- `git ls-files -z`.split("\x0").reject do |f|
24
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
- end
26
- end
27
- spec.bindir = 'exe'
28
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
- spec.require_paths = ['lib']
30
-
31
- # Uncomment to register a new dependency of your gem
32
- # spec.add_dependency "example-gem", "~> 1.0"
33
-
34
- # For more information and examples about making a new gem, check out our
35
- # guide at: https://bundler.io/guides/creating_gem.html
36
- end