tron_http 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8ff177426e0f309a3aa4a7914c06af4520920e6058324d4ba80411f7b7c96a8c
4
+ data.tar.gz: 02faa43812f7b26d9a4cb0081e6a1a745a5d01fccef16f81b6233f612e5fa0ec
5
+ SHA512:
6
+ metadata.gz: d499205131a8aacf28b10f2781cfcd78a0c8ece79452b308821b35c1f3bf399cefdd90383f6b2658673761dd96aef5bc12f4b6324850e977ebb1f25d895a6525
7
+ data.tar.gz: a73621c19ee1b68e92a44ef14d1510adfd74ed3f430beb4f30b58ea664c1945fdd10224b15d11a04e22d0474886c0309769e587cb5a93069a6c71c9ad1c8e9f7
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-01-22
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at sebscholl@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Sebastian Scholl
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # TronHttp Ruby
2
+
3
+ A simple interface to the Tron Network HTTP API.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add tron_http
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install tron_http
14
+
15
+ ## Usage
16
+
17
+ All endpoint declarations are defined in `lib/data/tron.yml` and get defined when the module is loaded using the `TronHTTP::Config.scaffold` method.
18
+
19
+ Network methodsare created automatically for Mainnet, Shashta, Tronex, and Nile.
20
+
21
+ ```rb
22
+ TronHttp.mainnet.get_transaction_by_id value: 'TX_ID'
23
+ TronHttp.tronex.get_transaction_by_id value: 'TX_ID'
24
+ TronHttp.shasta.get_transaction_by_id value: 'TX_ID'
25
+ TronHttp.nile.get_transaction_by_id value: 'TX_ID'
26
+ ```
27
+
28
+ Each instance will use its relevant host when making requests. Create a new instance of any network like so:
29
+
30
+ ```rb
31
+ # When no network is specified, defaults to 'shasta'
32
+ mainnet_client = TronHttp::Client.new 'mainnet'
33
+ ```
34
+
35
+ Every endpoint listed under `endpoints:` in the `lib/data/tron.yml` file is callable on a client instance.
36
+
37
+ ```rb
38
+ mainnet_client.get_transaction_by_id value: 'tx_id'
39
+ => {}
40
+ ```
41
+
42
+ Ever method requires parameters to be passed as a hash. The passed hash gets stringified and send directly to the relevant endpoint. This makes the interface 1-to-1 with parameters in the [API reference](https://developers.tron.network/reference/background).
43
+
44
+ ```rb
45
+ # BAD
46
+ mainnet_client.get_transaction_by_id 'bc1dddbf80346c1f67539f2e878170b9324128988dc5ec0fb717ed50135a1a8c'
47
+
48
+ # GOOD
49
+ mainnet_client.get_transaction_by_id value: 'bc1dddbf80346c1f67539f2e878170b9324128988dc5ec0fb717ed50135a1a8c'
50
+ ```
51
+
52
+ ### API Reference
53
+
54
+ Each entry in the `data/tron.yml` file specifies all parameters required to make requests to a TRON network.
55
+
56
+ ```yml
57
+ endpoints:
58
+ #
59
+ # https://developers.tron.network/reference/gettransactioninfobyid-1
60
+ get_transaction_info_by_id:
61
+ path: /walletsolidity/gettransactioninfobyid
62
+ method: post
63
+ variables:
64
+ value: string!
65
+ #
66
+ # https://developers.tron.network/reference/gettransactioninfobyblocknum-1
67
+ get_transaction_by_block_num:
68
+ path: /walletsolidity/gettransactioninfobyblocknum
69
+ method: post
70
+ variables:
71
+ value: int32
72
+ #
73
+ # List goes on...
74
+ ```
75
+
76
+ Any variable with a '!' mark suffixed to it's value is required. All other variables are optional.
77
+
78
+ To learn more about each method, visit the documentation link included above each methods YAML entry.
79
+
80
+ ## Development
81
+
82
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
83
+
84
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
85
+
86
+ ## Contributing
87
+
88
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sebscholl/tron-http. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/tron-http/blob/master/CODE_OF_CONDUCT.md).
89
+
90
+ ## License
91
+
92
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
93
+
94
+ ## Code of Conduct
95
+
96
+ Everyone interacting in the Tron::Http project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tron-http/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/lib/data/tron.yml ADDED
@@ -0,0 +1,298 @@
1
+ # All endpoints and hostnames are defined here.
2
+
3
+ # Hostnames
4
+ hostnames:
5
+ nile: https://api.nileex.io/
6
+ mainnet: https://api.trongrid.io/
7
+ tronex: https://testhttpapi.tronex.io/
8
+ shasta: https://api.shasta.trongrid.io/
9
+ #
10
+ # Endpoints
11
+ #
12
+ # Variables are defined with a ! at the end of the variable name when
13
+ # the variable is required. Variables with no ! at the end are optional.
14
+ #
15
+ endpoints:
16
+ #
17
+ # TRANSACTIONS
18
+ #
19
+ # https://developers.tron.network/reference/gettransactionbyid
20
+ get_transaction_by_id:
21
+ path: /wallet/gettransactionbyid
22
+ method: post
23
+ variables:
24
+ value: string!
25
+ #
26
+ # https://developers.tron.network/reference/gettransactioninfobyid-1
27
+ get_transaction_info_by_id:
28
+ path: /walletsolidity/gettransactioninfobyid
29
+ method: post
30
+ variables:
31
+ value: string!
32
+ #
33
+ # https://developers.tron.network/reference/gettransactioninfobyblocknum-1
34
+ get_transaction_by_block_num:
35
+ path: /walletsolidity/gettransactioninfobyblocknum
36
+ method: post
37
+ variables:
38
+ value: int32
39
+ #
40
+ # https://developers.tron.network/reference/gettransactioncountbyblocknum
41
+ get_transaction_count_by_block_num:
42
+ path: /walletsolidity/gettransactioncountbyblocknum
43
+ method: post
44
+ variables:
45
+ value: int32
46
+ #
47
+ # BLOCKS
48
+ #
49
+ # https://developers.tron.network/reference/getblock-2
50
+ get_block:
51
+ path: /walletsolidity/getblock
52
+ method: post
53
+ variables:
54
+ id_or_num: string
55
+ detail: boolean
56
+ #
57
+ # https://developers.tron.network/reference/getnowblock
58
+ get_now_block:
59
+ path: /walletsolidity/getnowblock
60
+ method: get
61
+ #
62
+ # https://developers.tron.network/reference/getblockbynum
63
+ get_block_by_num:
64
+ path: /walletsolidity/getblockbynum
65
+ method: post
66
+ variables:
67
+ num: int32
68
+ #
69
+ # https://developers.tron.network/reference/getblockbyid-1
70
+ get_block_by_id:
71
+ path: /walletsolidity/getblockbyid
72
+ method: post
73
+ variables:
74
+ value: string
75
+ #
76
+ # https://developers.tron.network/reference/getblockbylatestnum
77
+ get_block_by_latest_num:
78
+ path: /walletsolidity/getblockbylatestnum
79
+ method: post
80
+ variables:
81
+ num: int32!
82
+ #
83
+ # https://developers.tron.network/reference/getblockbylimitnext-1
84
+ get_block_by_limit_next:
85
+ path: /walletsolidity/getblockbylimitnext
86
+ method: post
87
+ variables:
88
+ startNum: int32
89
+ endNum: int32
90
+ #
91
+ # ACCOUNT REFERENCES
92
+ #
93
+ # https://developers.tron.network/reference/walletsolidity-getaccount
94
+ get_account:
95
+ path: /walletsolidity/getaccount
96
+ method: post
97
+ variables:
98
+ address: string!
99
+ visible: boolean
100
+
101
+ # https://developers.tron.network/reference/getdelegatedresource-1
102
+ get_delegated_resource:
103
+ path: /walletsolidity/getdelegatedresour
104
+ method: post
105
+ variables:
106
+ fromAddress: string!
107
+ toAddress: string!
108
+ visible: boolean
109
+ #
110
+ # https://developers.tron.network/reference/getdelegatedresourceaccountindex-1
111
+ get_delegated_resource_account_index:
112
+ path: /walletsolidity/getdelegatedresourceaccountindex
113
+ method: post
114
+ variables:
115
+ value: string
116
+ visible: boolean
117
+ #
118
+ # https://developers.tron.network/reference/getcandelegatedmaxsize-2
119
+ get_can_delegated_max_size:
120
+ path: /walletsolidity/getcandelegatedmaxsize
121
+ method: post
122
+ variables:
123
+ owner_address: string!
124
+ type: int32!
125
+ visible: boolean
126
+ #
127
+ # https://developers.tron.network/reference/getcanwithdrawunfreezeamount-2
128
+ get_can_withdraw_unfreeze_amount:
129
+ path: /walletsolidity/getcanwithdrawunfreezeamount
130
+ method: post
131
+ variables:
132
+ owner_address: string
133
+ timestamp: int64
134
+ visible: boolean
135
+ #
136
+ # https://developers.tron.network/reference/getdelegatedresourceaccountindexv2-2
137
+ get_delegated_resource_account_index_v2:
138
+ path: /walletsolidity/getdelegatedresourceaccountindexv2
139
+ method: post
140
+ variables:
141
+ value: string
142
+ visible: boolean
143
+ #
144
+ # https://developers.tron.network/reference/getavailableunfreezecount-2
145
+ get_available_unfreeze_count:
146
+ path: /walletsolidity/getavailableunfreezecount
147
+ method: post
148
+ variables:
149
+ owner_address: string
150
+ visible: boolean
151
+ #
152
+ # NODE & CHAIN
153
+ #
154
+ # https://developers.tron.network/reference/getnodeinfo-1
155
+ get_node_info:
156
+ path: /walletsolidity/getnodeinfo
157
+ method: get
158
+ #
159
+ # https://developers.tron.network/reference/getburntrx-1
160
+ get_burn_trx:
161
+ path: /walletsolidity/getburntrx
162
+ method: get
163
+ #
164
+ # SMART CONTRACTS
165
+ #
166
+ # https://developers.tron.network/reference/triggerconstantcontract-1
167
+ trigger_constant_contract:
168
+ path: /walletsolidity/triggerconstantcontract
169
+ method: post
170
+ variables:
171
+ owner_address: string
172
+ contract_address: string
173
+ function_selector: string
174
+ parameter: string
175
+ visible: boolean
176
+ #
177
+ # https://developers.tron.network/reference/estimateenergy-2
178
+ estimate_energy:
179
+ path: /walletsolidity/estimateenergy
180
+ method: post
181
+ variables:
182
+ owner_address: string
183
+ contract_address: string
184
+ function_selector: string
185
+ parameter: string
186
+ visible: boolean
187
+ #
188
+ # TRC10 TOKEN
189
+ #
190
+ # https://developers.tron.network/reference/getassetissuebyname
191
+ get_asset_issue_by_name:
192
+ path: /walletsolidity/getassetissuebyname
193
+ method: post
194
+ variables:
195
+ value: string
196
+ #
197
+ # https://developers.tron.network/reference/getassetissuebyid-1
198
+ get_asset_issue_by_id:
199
+ path: /walletsolidity/getassetissuebyid
200
+ method: post
201
+ variables:
202
+ value: int32
203
+ visible: boolean
204
+ #
205
+ # https://developers.tron.network/reference/getassetissuelist-1
206
+ get_asset_issue_list:
207
+ path: /walletsolidity/getassetissuelist
208
+ method: get
209
+ #
210
+ # https://developers.tron.network/reference/getassetissuelistbyname
211
+ get_asset_issue_list_by_name:
212
+ path: /walletsolidity/getassetissuelistbyname
213
+ method: post
214
+ variables:
215
+ value: string
216
+ #
217
+ # https://developers.tron.network/reference/getpaginatedassetissuelist-1
218
+ get_paginated_asset_issue_list:
219
+ path: /walletsolidity/getpaginatedassetissuelist
220
+ method: post
221
+ variables:
222
+ offset: int32
223
+ limit: int32
224
+ #
225
+ # DEX EXCHANGES
226
+ #
227
+ # https://developers.tron.network/reference/listexchanges-1
228
+ list_exchanges:
229
+ path: /walletsolidity/listexchanges
230
+ method: get
231
+ variables:
232
+ visible: boolean
233
+ #
234
+ # https://developers.tron.network/reference/getexchangebyid-1
235
+ get_exchange_by_id:
236
+ path: /walletsolidity/getexchangebyid
237
+ method: post
238
+ variables:
239
+ id: int32
240
+ #
241
+ # VOTING & SRs
242
+ #
243
+ # https://developers.tron.network/reference/listwitnesses-1
244
+ list_witnesses:
245
+ path: /walletsolidity/listwitnesses
246
+ method: get
247
+ #
248
+ # https://developers.tron.network/reference/getreward-1
249
+ get_reward:
250
+ path: /walletsolidity/getReward
251
+ method: post
252
+ variables:
253
+ address: string
254
+ visible: boolean
255
+ #
256
+ # https://developers.tron.network/reference/getbrokerage-1
257
+ get_brokerage:
258
+ path: /walletsolidity/getBrokerage
259
+ method: post
260
+ variables:
261
+ address: string
262
+ visible: boolean
263
+ #
264
+ # TRONZ Shielded Smart Contract
265
+ #
266
+ # https://developers.tron.network/reference/scanshieldedtrc20notesbyivk-1
267
+ scan_shielded_trc20_notes_by_ivk:
268
+ path: /walletsolidity/scanshieldedtrc20notesbyivk
269
+ method: post
270
+ variables:
271
+ start_block_index: int32!
272
+ end_block_index: int32!
273
+ shielded_TRC20_contract_address: string!
274
+ ivk: string!
275
+ ak: string!
276
+ nk: string!
277
+ visible: boolean
278
+ #
279
+ # https://developers.tron.network/reference/scanshieldedtrc20notesbyovk-1
280
+ scan_shielded_trc20_notes_by_ovk:
281
+ path: /walletsolidity/scanshieldedtrc20notesbyovk
282
+ method: post
283
+ variables:
284
+ start_block_index: int32!
285
+ end_block_index: int32!
286
+ shielded_TRC20_contract_address: string!
287
+ ovk: string!
288
+ visible: boolean
289
+ #
290
+ # https://developers.tron.network/reference/isshieldedtrc20contractnotespent-1
291
+ is_shielded_trc20_contract_note_spent:
292
+ path: /walletsolidity/isshieldedtrc20contractnotespent
293
+ method: post
294
+ variables:
295
+ ak: string!
296
+ nk: string!
297
+ position: int32!
298
+ shielded_TRC20_contract_address: string!
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # TronHttp
4
+ module TronHttp
5
+ #
6
+ # TronHttp::Client
7
+ # The main class for interacting with the Tron API.
8
+ #
9
+ class Client
10
+ attr_reader :hostname
11
+
12
+ def initialize(network = "shasta")
13
+ @hostname = hostname_for(network)
14
+ end
15
+
16
+ private
17
+
18
+ def hostname_for(network)
19
+ hostname = Config.hostnames[network]
20
+
21
+ raise "Network #{network} not found." unless hostname
22
+
23
+ hostname
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+
5
+ # TronHttp
6
+ module TronHttp
7
+ # Config
8
+ class Config
9
+ def self.hostnames
10
+ TronHttp::DATA["hostnames"]
11
+ end
12
+
13
+ def self.endpoints
14
+ TronHttp::DATA["endpoints"]
15
+ end
16
+
17
+ def self.scaffold
18
+ define_network_methods
19
+ define_endpoint_methods
20
+ end
21
+
22
+ def self.define_network_methods
23
+ hostnames.each_key do |network|
24
+ TronHttp.define_singleton_method(network) do
25
+ Client.new network
26
+ end
27
+ end
28
+ end
29
+
30
+ def self.define_endpoint_methods
31
+ endpoints.each do |endpoint, options|
32
+ path = options["path"]
33
+ method = options["method"]
34
+ variables = options["variables"]
35
+
36
+ Client.define_method(endpoint) do |params = {}|
37
+ Helpers.validate_variables variables, params
38
+ HTTP.send method, URI(@hostname + path), params
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # TronHttp
4
+ module TronHttp
5
+ # Helpers
6
+ module Helpers
7
+ # Checks each variable against the given variables. If type name
8
+ # includes a ! then it is required. If not and a variable is not
9
+ # present then it is ignored.
10
+ def self.validate_variables(vars_reference, vars_given)
11
+ return {} unless vars_reference
12
+
13
+ vars_reference.each do |name, type|
14
+ next unless type[-1] == "!" && vars_given[name.to_sym].nil?
15
+
16
+ raise "Missing required variable #{name} of type #{type}."
17
+ end
18
+
19
+ vars_given
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/http"
5
+
6
+ # TronHttp
7
+ module TronHttp
8
+ # HTTP
9
+ module HTTP
10
+ def self.get(uri, _params = {})
11
+ http = Net::HTTP.new(uri.host, 443)
12
+ http.use_ssl = true
13
+
14
+ request = Net::HTTP::Get.new(uri)
15
+
16
+ default_headers(request)
17
+
18
+ response = http.request(request)
19
+ JSON.parse response.body
20
+ end
21
+
22
+ def self.post(uri, params = {})
23
+ http = Net::HTTP.new(uri.host, 443)
24
+ http.use_ssl = true
25
+
26
+ request = Net::HTTP::Post.new(uri)
27
+ request.body = JSON.generate(params)
28
+
29
+ default_headers(request)
30
+
31
+ response = http.request(request)
32
+ JSON.parse response.body
33
+ end
34
+
35
+ # Set request default_headers
36
+ def self.default_headers(request)
37
+ request["accept"] = "application/json"
38
+ request["content-type"] = "application/json"
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TronHttp
4
+ VERSION = "0.1.1"
5
+ end
data/lib/tron_http.rb ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+ require_relative "tron_http/version"
5
+
6
+ # TronHttp
7
+ module TronHttp
8
+ require_relative "tron_http/http"
9
+ require_relative "tron_http/config"
10
+ require_relative "tron_http/client"
11
+ require_relative "tron_http/helpers"
12
+
13
+ DATA = YAML.load_file(
14
+ File.join(__dir__, "data/tron.yml")
15
+ )
16
+
17
+ # Scaffold the module
18
+ Config.scaffold
19
+ end
data/sig/tron_http.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module TronHttp
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/tron_http.gemspec ADDED
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/tron_http/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "tron_http"
7
+ spec.version = TronHttp::VERSION
8
+ spec.authors = ["Sebastian Scholl"]
9
+ spec.email = ["sebscholl@gmail.com"]
10
+
11
+ spec.summary = "A simple interface to the Tron Network HTTP API."
12
+ spec.description = "Interact with the Tron Network HTTP API for Mainnet, Shasta, Nile and TronEx."
13
+ spec.homepage = "https://github.com/sebscholl/tron_http"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/sebscholl/tron_http.git"
19
+ spec.metadata["changelog_uri"] = "https://github.com/sebscholl/tron_http/blob/master/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (File.expand_path(f) == __FILE__) ||
26
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ # Development dependencies
34
+ spec.add_development_dependency "irb"
35
+
36
+ # Runtime dependencies
37
+ spec.add_dependency "json"
38
+ spec.add_dependency "yaml"
39
+
40
+ # For more information and examples about making a new gem, check out our
41
+ # guide at: https://bundler.io/guides/creating_gem.html
42
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tron_http
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Sebastian Scholl
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-01-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: irb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yaml
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: Interact with the Tron Network HTTP API for Mainnet, Shasta, Nile and
56
+ TronEx.
57
+ email:
58
+ - sebscholl@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".rubocop.yml"
64
+ - CHANGELOG.md
65
+ - CODE_OF_CONDUCT.md
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/data/tron.yml
70
+ - lib/tron_http.rb
71
+ - lib/tron_http/client.rb
72
+ - lib/tron_http/config.rb
73
+ - lib/tron_http/helpers.rb
74
+ - lib/tron_http/http.rb
75
+ - lib/tron_http/version.rb
76
+ - sig/tron_http.rbs
77
+ - tron_http.gemspec
78
+ homepage: https://github.com/sebscholl/tron_http
79
+ licenses:
80
+ - MIT
81
+ metadata:
82
+ homepage_uri: https://github.com/sebscholl/tron_http
83
+ source_code_uri: https://github.com/sebscholl/tron_http.git
84
+ changelog_uri: https://github.com/sebscholl/tron_http/blob/master/CHANGELOG.md
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 2.6.0
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubygems_version: 3.4.10
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: A simple interface to the Tron Network HTTP API.
104
+ test_files: []