decommas 0.0.1 → 0.0.3
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 +4 -4
- data/lib/decommas/api.rb +110 -0
- data/lib/decommas/configuration.rb +10 -0
- data/lib/decommas/errors.rb +19 -0
- data/lib/decommas/response.rb +30 -0
- data/lib/decommas.rb +1 -0
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f55429693ca0fc4fc811a666746f6c26dbbb02309447fcb4ba7e5d535f46d865
|
|
4
|
+
data.tar.gz: db7ad11fad45630ae80b4a5cb07490681b0504216194a52483da8b3febbd2600
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 490c06e53822dc41c23c6ed88c0e6f0771aaff6a8227d66d1a99d9dd48ef72205dc81c28791c3c56d6dac1068de286437a2d5066691e979b566d77742aa3e594
|
|
7
|
+
data.tar.gz: a1f728154738d38df98fef4c0454ee7c1258916e072a5676890d0b2e7a7888cc3b8926080b3da152f847f9170c051b0309417295ef3d874cd21ac5c2b3e2d204
|
data/lib/decommas/api.rb
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
module Decommas
|
|
2
|
+
class Api
|
|
3
|
+
include ::HTTParty
|
|
4
|
+
base_uri 'https://datalayer.decommas.net/datalayer/api/v1/'
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
PAGINATION_LIMIT = 100
|
|
8
|
+
|
|
9
|
+
def coins(address:, options: {})
|
|
10
|
+
wget("/coins/#{address}", query: options)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def tokens(address:, options: {})
|
|
14
|
+
wget("/tokens/#{address}", query: options)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def nfts(address:, options: {})
|
|
18
|
+
wget("/nfts/#{address}", query: options)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def transactions(address:, limit: nil, offset: nil)
|
|
22
|
+
query_params = {
|
|
23
|
+
"limit" => limit || PAGINATION_LIMIT,
|
|
24
|
+
"offset" => (offset if offset)
|
|
25
|
+
}.compact
|
|
26
|
+
wget("/transactions/#{address}", query: query_params)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def transfers_erc20(address:, limit: nil, offset: nil)
|
|
30
|
+
query_params = {
|
|
31
|
+
"limit" => limit || PAGINATION_LIMIT,
|
|
32
|
+
"offset" => (offset if offset)
|
|
33
|
+
}.compact
|
|
34
|
+
wget("/transfers_erc20/#{address}", query: query_params)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def transfers_nft(address:, options: {})
|
|
38
|
+
wget("/transfers_nft/#{address}", query: options)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def protocols(address:, options: {})
|
|
42
|
+
wget("/protocols/#{address}", query: options)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def transaction_erc20_transfers(chain_name:, tx:)
|
|
46
|
+
wget("/transaction_erc20_transfers/#{chain_name}/#{tx}")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def all_tokens_metadata
|
|
50
|
+
wget("/all_tokens_metadata")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def all_coins_metadata
|
|
54
|
+
wget("/all_coins_metadata")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def token_metadata(chain_name:, contract_address:)
|
|
58
|
+
wget("/token_metadata/#{chain_name}/#{contract_address}")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
private
|
|
62
|
+
|
|
63
|
+
def with_retry(max_retries: 5, base_delay: 0.7, &block)
|
|
64
|
+
def attempt(retries_left, delay, &block)
|
|
65
|
+
block.call
|
|
66
|
+
rescue => e
|
|
67
|
+
if retries_left > 0
|
|
68
|
+
puts "#{e} has been raised, retries_left: #{retries_left}"
|
|
69
|
+
|
|
70
|
+
sleep(delay)
|
|
71
|
+
attempt(retries_left - 1, delay * 2, &block)
|
|
72
|
+
else
|
|
73
|
+
raise e
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
attempt(max_retries, base_delay, &block)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def wget(url, options = {})
|
|
81
|
+
raise Decommas::TokenNotProvidedError.new unless token
|
|
82
|
+
|
|
83
|
+
if options[:query]
|
|
84
|
+
options[:query].merge!("api-key" => token)
|
|
85
|
+
else
|
|
86
|
+
options[:query] = { "api-key" => token }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
if safe_mode?
|
|
90
|
+
with_retry do
|
|
91
|
+
response = Response.new(get(url, **options))
|
|
92
|
+
raise ThrottledResponseError.new(response) if response.throttled?
|
|
93
|
+
response
|
|
94
|
+
end
|
|
95
|
+
else
|
|
96
|
+
Response.new(get(url, **options))
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def token
|
|
101
|
+
@token ||= Decommas.configuration.token
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def safe_mode?
|
|
105
|
+
@safe_mode ||= Decommas.configuration.safe_mode
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Decommas
|
|
2
|
+
class TokenNotProvidedError < StandardError
|
|
3
|
+
def initialize
|
|
4
|
+
super("Please provide token in configuration!")
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class ResponseError < StandardError
|
|
9
|
+
def initialize(response)
|
|
10
|
+
super("DecommasApi returned: #{response.code} #{response.message}")
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class ThrottledResponseError < StandardError
|
|
15
|
+
def initialize(response)
|
|
16
|
+
super("DecommasApi throttled you with: #{response.code} #{response.message}")
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Decommas
|
|
2
|
+
class Response
|
|
3
|
+
VALID_RESPONSES = [200]
|
|
4
|
+
THROTTLED_RESPONSES = [429]
|
|
5
|
+
|
|
6
|
+
attr_reader :code
|
|
7
|
+
attr_reader :data
|
|
8
|
+
attr_reader :message
|
|
9
|
+
|
|
10
|
+
def initialize(response)
|
|
11
|
+
# Workaround for 429 response that returns text/html content-type for some reason
|
|
12
|
+
response_data = if response.parsed_response.kind_of?(String)
|
|
13
|
+
JSON.parse(response.parsed_response)
|
|
14
|
+
else
|
|
15
|
+
response.parsed_response
|
|
16
|
+
end
|
|
17
|
+
@code = response.code
|
|
18
|
+
@data = response_data["result"]
|
|
19
|
+
@message = response_data["message"]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def success?
|
|
23
|
+
@code.in?(VALID_RESPONSES)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def throttled?
|
|
27
|
+
@code.in?(THROTTLED_RESPONSES)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lib/decommas.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: decommas
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ivan Takarlikov
|
|
@@ -31,6 +31,10 @@ extensions: []
|
|
|
31
31
|
extra_rdoc_files: []
|
|
32
32
|
files:
|
|
33
33
|
- lib/decommas.rb
|
|
34
|
+
- lib/decommas/api.rb
|
|
35
|
+
- lib/decommas/configuration.rb
|
|
36
|
+
- lib/decommas/errors.rb
|
|
37
|
+
- lib/decommas/response.rb
|
|
34
38
|
homepage: https://rubygems.org/gems/decommas
|
|
35
39
|
licenses:
|
|
36
40
|
- MIT
|