huginn_coinmarketcap_agent 0.1.10

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 53e2437d84b5006c60bc5f05343ea21c0b226f3f2a5edc4474f4e8a12687bba1
4
+ data.tar.gz: d104972225423aebbfdf34cf2ee5d300aaebdc87413f41f15f22d3c550fb981f
5
+ SHA512:
6
+ metadata.gz: 298491bed53f05f4998ee73a28e79526b97f45061cc501a43651e5be15fb7726330e7026b53466fd3de3d500607d0664cc0f45939da0717c872012769bd056d7
7
+ data.tar.gz: dcec8faad9b154072c83f912e357967155e75c75f04e3d7097e4337d00975d0efa6b591a03cb54b89d0cd741c6abe9cfdcbc2c056ea066a19ee6f4b091523219
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2021 Nicolas Germain
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,187 @@
1
+ module Agents
2
+ class CoinmarketcapAgent < Agent
3
+ include FormConfigurable
4
+
5
+ can_dry_run!
6
+ no_bulk_receive!
7
+ default_schedule 'every_1h'
8
+
9
+ description do
10
+ <<-MD
11
+ The Coinmarketcap Agent checks rank and can create events if there is a change.
12
+
13
+ `debug` is used to verbose mode.
14
+
15
+ `action` is the wanted action, like checking token rank.
16
+
17
+ `token` is the id of the token.
18
+
19
+ `api_key` is needed for auth.
20
+
21
+ `changes_only` is only used to emit event about an event's change.
22
+ MD
23
+ end
24
+
25
+ event_description <<-MD
26
+ Events look like this:
27
+
28
+ {
29
+ "status": {
30
+ "timestamp": "2021-12-29T09:24:12.666Z",
31
+ "error_code": 0,
32
+ "error_message": null,
33
+ "elapsed": 28,
34
+ "credit_count": 1,
35
+ "notice": null
36
+ },
37
+ "data": {
38
+ "1697": {
39
+ "id": 1697,
40
+ "name": "Basic Attention Token",
41
+ "symbol": "BAT",
42
+ "slug": "basic-attention-token",
43
+ "num_market_pairs": 244,
44
+ "date_added": "2017-06-01T00:00:00.000Z",
45
+ "tags": [
46
+ "marketing",
47
+ "content-creation",
48
+ "defi",
49
+ "payments",
50
+ "binance-smart-chain",
51
+ "dcg-portfolio",
52
+ "1confirmation-portfolio",
53
+ "pantera-capital-portfolio",
54
+ "web3"
55
+ ],
56
+ "max_supply": 1500000000,
57
+ "circulating_supply": 1493865018.4473505,
58
+ "total_supply": 1500000000,
59
+ "platform": {
60
+ "id": 1027,
61
+ "name": "Ethereum",
62
+ "symbol": "ETH",
63
+ "slug": "ethereum",
64
+ "token_address": "0x0d8775f648430679a709e98d2b0cb6250d2887ef"
65
+ },
66
+ "is_active": 1,
67
+ "cmc_rank": 71,
68
+ "is_fiat": 0,
69
+ "last_updated": "2021-12-29T09:23:09.000Z",
70
+ "quote": {
71
+ "USD": {
72
+ "price": 1.1981546955807796,
73
+ "volume_24h": 292305456.1489774,
74
+ "volume_change_24h": -22.7985,
75
+ "percent_change_1h": -1.45132346,
76
+ "percent_change_24h": -8.53447767,
77
+ "percent_change_7d": -0.30962906,
78
+ "percent_change_30d": -25.57747572,
79
+ "percent_change_60d": 48.17017438,
80
+ "percent_change_90d": 96.606884,
81
+ "market_cap": 1789881386.416561,
82
+ "market_cap_dominance": 0.0801,
83
+ "fully_diluted_market_cap": 1797232043.37,
84
+ "last_updated": "2021-12-29T09:23:09.000Z"
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+ MD
91
+
92
+ def default_options
93
+ {
94
+ 'api_key' => '',
95
+ 'action' => 'rank',
96
+ 'token' => '',
97
+ 'debug' => 'false'
98
+ }
99
+ end
100
+
101
+ form_configurable :api_key, type: :string
102
+ form_configurable :action, type: :array, values: ['rank']
103
+ form_configurable :token, type: :string
104
+ form_configurable :changes_only, type: :boolean
105
+ form_configurable :debug, type: :boolean
106
+ def validate_options
107
+
108
+ unless options['token'].present?
109
+ errors.add(:base, "token is a required field")
110
+ end
111
+
112
+ if options.has_key?('changes_only') && boolify(options['changes_only']).nil?
113
+ errors.add(:base, "if provided, changes_only must be true or false")
114
+ end
115
+
116
+ if options.has_key?('debug') && boolify(options['debug']).nil?
117
+ errors.add(:base, "if provided, debug must be true or false")
118
+ end
119
+ end
120
+
121
+ def working?
122
+ !recent_error_logs?
123
+ end
124
+
125
+ def check
126
+ fetch
127
+ end
128
+
129
+ private
130
+
131
+ def get_rank(token)
132
+ uri = URI.parse("https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?id=#{token}")
133
+ request = Net::HTTP::Get.new(uri)
134
+ request["X-Cmc_pro_api_key"] = "#{interpolated['api_key']}"
135
+ request["Accept"] = "application/json"
136
+
137
+ req_options = {
138
+ use_ssl: uri.scheme == "https",
139
+ }
140
+
141
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
142
+ http.request(request)
143
+ end
144
+
145
+ log "request status : #{response.code}"
146
+
147
+ if interpolated['debug'] == 'true'
148
+ log "response.body"
149
+ log response.body
150
+ end
151
+ return response.body
152
+ end
153
+
154
+ def fetch
155
+ case interpolated['action']
156
+ when "rank"
157
+ payload = JSON.parse(get_rank(interpolated['token']))
158
+ if interpolated['changes_only'] == 'true'
159
+ if payload.to_s != memory['last_status']
160
+ if !memory['last_status'].nil?
161
+ last_status = JSON.parse(memory['last_status'].gsub("=>", ": ").gsub(": nil", ": null"))
162
+ end
163
+ if interpolated['debug'] == 'true'
164
+ log "payload rank = #{payload['data']["#{interpolated['token']}"]['cmc_rank']}"
165
+ if !memory['last_status'].nil?
166
+ log "last status rank = #{last_status['data']["#{interpolated['token']}"]['cmc_rank']}"
167
+ end
168
+ end
169
+ if !memory['last_status'].nil?
170
+ if payload['data']["#{interpolated['token']}"]['cmc_rank'] != last_status['data']["#{interpolated['token']}"]['cmc_rank']
171
+ create_event payload: payload
172
+ end
173
+ else
174
+ create_event payload: payload
175
+ end
176
+ memory['last_status'] = payload.to_s
177
+ end
178
+ else
179
+ create_event payload: payload
180
+ if payload.to_s != memory['last_status']
181
+ memory['last_status'] = payload.to_s
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
187
+ end
@@ -0,0 +1,4 @@
1
+ require 'huginn_agent'
2
+
3
+ #HuginnAgent.load 'huginn_coinmarketcap_agent/concerns/my_agent_concern'
4
+ HuginnAgent.register 'huginn_coinmarketcap_agent/coinmarketcap_agent'
@@ -0,0 +1,13 @@
1
+ require 'rails_helper'
2
+ require 'huginn_agent/spec_helper'
3
+
4
+ describe Agents::CoinmarketcapAgent do
5
+ before(:each) do
6
+ @valid_options = Agents::CoinmarketcapAgent.new.default_options
7
+ @checker = Agents::CoinmarketcapAgent.new(:name => "CoinmarketcapAgent", :options => @valid_options)
8
+ @checker.user = users(:bob)
9
+ @checker.save!
10
+ end
11
+
12
+ pending "add specs here"
13
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: huginn_coinmarketcap_agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.10
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Germain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-02-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: huginn_agent
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Write a longer description or delete this line.
56
+ email:
57
+ - ngermain@hihouhou.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE.txt
63
+ - lib/huginn_coinmarketcap_agent.rb
64
+ - lib/huginn_coinmarketcap_agent/coinmarketcap_agent.rb
65
+ - spec/coinmarketcap_agent_spec.rb
66
+ homepage: https://github.com/hihouhou/huginn_coinmarketcap_agent
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.3.3
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Write a short summary, because Rubygems requires one.
89
+ test_files:
90
+ - spec/coinmarketcap_agent_spec.rb