decommas 0.0.2 → 0.2.0
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 +3 -47
- data/lib/decommas/base.rb +92 -0
- data/lib/decommas/price_service.rb +25 -0
- data/lib/decommas/response/api.rb +18 -0
- data/lib/decommas/response/base.rb +20 -0
- data/lib/decommas/response/price_service.rb +17 -0
- data/lib/decommas.rb +7 -1
- metadata +9 -5
- data/lib/decommas/response.rb +0 -30
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3293fea681cb42802fbf07dae91ad38fdcf63ce869ab4f020c0a677dd5c86409
|
|
4
|
+
data.tar.gz: 40904d6290f5584acc56568ea8efc63ead6a2a0c9fa7a205298f64d3c93dc8ad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a85a90a607a456836cdb8d4f1c708d77769019849d088afb227574288efcafe9f562632f448bb26daee9fd2516fa41c5aee5d132ca356686349a9bc9085fd4a1
|
|
7
|
+
data.tar.gz: eda72888887344c8e069d16011e56a9ed7c91c53ba0c96b692eadd03fa893775b67f77eca44e0e9b7d5c00387180fec7ae08ea3b3f18128ca7d962ddad245cd6
|
data/lib/decommas/api.rb
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
module Decommas
|
|
2
|
-
class Api
|
|
3
|
-
include HTTParty
|
|
2
|
+
class Api < Base
|
|
4
3
|
base_uri 'https://datalayer.decommas.net/datalayer/api/v1/'
|
|
5
4
|
|
|
6
5
|
class << self
|
|
@@ -58,51 +57,8 @@ module Decommas
|
|
|
58
57
|
wget("/token_metadata/#{chain_name}/#{contract_address}")
|
|
59
58
|
end
|
|
60
59
|
|
|
61
|
-
|
|
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
|
|
60
|
+
def response_class
|
|
61
|
+
Decommas::Response::Api
|
|
106
62
|
end
|
|
107
63
|
end
|
|
108
64
|
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
module Decommas
|
|
2
|
+
class Base
|
|
3
|
+
include ::HTTParty
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
PAGINATION_LIMIT = 100
|
|
7
|
+
|
|
8
|
+
protected
|
|
9
|
+
|
|
10
|
+
def with_retry(max_retries: 5, base_delay: 0.7, &block)
|
|
11
|
+
def attempt(retries_left, delay, &block)
|
|
12
|
+
block.call
|
|
13
|
+
rescue => e
|
|
14
|
+
if retries_left > 0
|
|
15
|
+
puts "#{e} has been raised, retries_left: #{retries_left}"
|
|
16
|
+
|
|
17
|
+
sleep(delay)
|
|
18
|
+
attempt(retries_left - 1, delay * 2, &block)
|
|
19
|
+
else
|
|
20
|
+
raise e
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
attempt(max_retries, base_delay, &block)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def wget(url, options = {})
|
|
28
|
+
options = authorize(options)
|
|
29
|
+
|
|
30
|
+
if safe_mode?
|
|
31
|
+
with_retry do
|
|
32
|
+
response = response_class.new(get(url, **options))
|
|
33
|
+
raise ThrottledResponseError.new(response) if response.throttled?
|
|
34
|
+
response
|
|
35
|
+
end
|
|
36
|
+
else
|
|
37
|
+
response_class.new(get(url, **options))
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def wpost(url, options = {})
|
|
42
|
+
options = authorize(options)
|
|
43
|
+
|
|
44
|
+
if options[:headers]
|
|
45
|
+
options[:headers].merge!("Content-Type" => "application/json")
|
|
46
|
+
else
|
|
47
|
+
options[:headers] = { "Content-Type" => "application/json"}
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
if options[:body] && !options[:body].kind_of?(String)
|
|
51
|
+
options[:body] = options[:body].to_json
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
if safe_mode?
|
|
55
|
+
with_retry do
|
|
56
|
+
response = response_class.new(post(url, **options))
|
|
57
|
+
raise ThrottledResponseError.new(response) if response.throttled?
|
|
58
|
+
response
|
|
59
|
+
end
|
|
60
|
+
else
|
|
61
|
+
response_class.new(post(url, **options))
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def authorize(options)
|
|
67
|
+
raise Decommas::TokenNotProvidedError.new unless token
|
|
68
|
+
|
|
69
|
+
if options[:query]
|
|
70
|
+
options[:query].merge!("api-key" => token)
|
|
71
|
+
else
|
|
72
|
+
options[:query] = { "api-key" => token }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
options
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def response_class
|
|
79
|
+
raise NotImplementedError.new
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def token
|
|
83
|
+
@token ||= Decommas.configuration.token
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def safe_mode?
|
|
87
|
+
@safe_mode ||= Decommas.configuration.safe_mode
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Decommas
|
|
2
|
+
class PriceService < Base
|
|
3
|
+
base_uri 'https://datalayer.decommas.net/priceservice/'
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
def dexes(chain:, options: {})
|
|
7
|
+
wget("/dexes/#{chain}", query: options)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def get_price(chain:, dex:, tokens: [], options: {})
|
|
11
|
+
body = options.merge(
|
|
12
|
+
chain: chain,
|
|
13
|
+
dex: dex,
|
|
14
|
+
tokens: tokens
|
|
15
|
+
)
|
|
16
|
+
wpost("/get_price", body: body)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def response_class
|
|
20
|
+
Decommas::Response::PriceService
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Decommas
|
|
2
|
+
module Response
|
|
3
|
+
class Api < Base
|
|
4
|
+
def initialize(response)
|
|
5
|
+
# Workaround for 429 response that returns text/html content-type for some reason
|
|
6
|
+
response_data = if response.parsed_response.kind_of?(String)
|
|
7
|
+
JSON.parse(response.parsed_response)
|
|
8
|
+
else
|
|
9
|
+
response.parsed_response
|
|
10
|
+
end
|
|
11
|
+
@code = response.code
|
|
12
|
+
|
|
13
|
+
@data = response_data["result"]
|
|
14
|
+
@message = response_data["message"]
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Decommas
|
|
2
|
+
module Response
|
|
3
|
+
class Base
|
|
4
|
+
VALID_RESPONSES = [200]
|
|
5
|
+
THROTTLED_RESPONSES = [429]
|
|
6
|
+
|
|
7
|
+
attr_reader :code
|
|
8
|
+
attr_reader :data
|
|
9
|
+
attr_reader :message
|
|
10
|
+
|
|
11
|
+
def success?
|
|
12
|
+
VALID_RESPONSES.include?(@code)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def throttled?
|
|
16
|
+
THROTTLED_RESPONSES.include?(@code)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Decommas
|
|
2
|
+
module Response
|
|
3
|
+
class PriceService < Base
|
|
4
|
+
def initialize(response)
|
|
5
|
+
# Workaround for 429 response that returns text/html content-type for some reason
|
|
6
|
+
response_data = if response.parsed_response.kind_of?(String)
|
|
7
|
+
JSON.parse(response.parsed_response)
|
|
8
|
+
else
|
|
9
|
+
response.parsed_response
|
|
10
|
+
end
|
|
11
|
+
@code = response.code
|
|
12
|
+
@data = response_data
|
|
13
|
+
@message = response_data["message"] unless success?
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/decommas.rb
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
|
|
3
|
+
require 'decommas/base'
|
|
1
4
|
require 'decommas/api'
|
|
5
|
+
require 'decommas/price_service'
|
|
2
6
|
require 'decommas/configuration'
|
|
3
7
|
require 'decommas/errors'
|
|
4
|
-
require 'decommas/response'
|
|
8
|
+
require 'decommas/response/base'
|
|
9
|
+
require 'decommas/response/api'
|
|
10
|
+
require 'decommas/response/price_service'
|
|
5
11
|
|
|
6
12
|
module Decommas
|
|
7
13
|
class << self
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: decommas
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ivan Takarlikov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-03-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: 0.21.0
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
26
|
+
version: 0.21.0
|
|
27
27
|
description: Developer friendly API for Decommas API written on Ruby
|
|
28
28
|
email: vtakarlikov@gmail.com
|
|
29
29
|
executables: []
|
|
@@ -32,9 +32,13 @@ extra_rdoc_files: []
|
|
|
32
32
|
files:
|
|
33
33
|
- lib/decommas.rb
|
|
34
34
|
- lib/decommas/api.rb
|
|
35
|
+
- lib/decommas/base.rb
|
|
35
36
|
- lib/decommas/configuration.rb
|
|
36
37
|
- lib/decommas/errors.rb
|
|
37
|
-
- lib/decommas/
|
|
38
|
+
- lib/decommas/price_service.rb
|
|
39
|
+
- lib/decommas/response/api.rb
|
|
40
|
+
- lib/decommas/response/base.rb
|
|
41
|
+
- lib/decommas/response/price_service.rb
|
|
38
42
|
homepage: https://rubygems.org/gems/decommas
|
|
39
43
|
licenses:
|
|
40
44
|
- MIT
|
data/lib/decommas/response.rb
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
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
|