blockfrost-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +39 -0
  5. data/CHANGELOG.md +5 -0
  6. data/Gemfile +10 -0
  7. data/LICENSE +201 -0
  8. data/README.md +134 -0
  9. data/Rakefile +8 -0
  10. data/blockfrost-ruby.gemspec +40 -0
  11. data/lib/blockfrost-ruby.rb +98 -0
  12. data/lib/blockfrostruby/config.yml +4 -0
  13. data/lib/blockfrostruby/configuration.rb +30 -0
  14. data/lib/blockfrostruby/constants.rb +9 -0
  15. data/lib/blockfrostruby/endpoints/cardano/accounts_endpoints.rb +99 -0
  16. data/lib/blockfrostruby/endpoints/cardano/addresses_endpoints.rb +47 -0
  17. data/lib/blockfrostruby/endpoints/cardano/assets_endpoints.rb +70 -0
  18. data/lib/blockfrostruby/endpoints/cardano/blocks_endpoints.rb +84 -0
  19. data/lib/blockfrostruby/endpoints/cardano/epochs_endpoints.rb +105 -0
  20. data/lib/blockfrostruby/endpoints/cardano/health_endpoints.rb +28 -0
  21. data/lib/blockfrostruby/endpoints/cardano/ledger_endpoints.rb +14 -0
  22. data/lib/blockfrostruby/endpoints/cardano/metadata_endpoints.rb +40 -0
  23. data/lib/blockfrostruby/endpoints/cardano/metrics_endpoints.rb +21 -0
  24. data/lib/blockfrostruby/endpoints/cardano/network_endpoints.rb +14 -0
  25. data/lib/blockfrostruby/endpoints/cardano/nutlink_endpoints.rb +50 -0
  26. data/lib/blockfrostruby/endpoints/cardano/pools_endpoints.rb +102 -0
  27. data/lib/blockfrostruby/endpoints/cardano/transactions_endpoints.rb +99 -0
  28. data/lib/blockfrostruby/endpoints/custom_endpoints.rb +26 -0
  29. data/lib/blockfrostruby/endpoints/ipfs/ipfs_endpoints.rb +58 -0
  30. data/lib/blockfrostruby/params.rb +66 -0
  31. data/lib/blockfrostruby/request.rb +216 -0
  32. data/lib/blockfrostruby/validator.rb +219 -0
  33. data/lib/blockfrostruby/version.rb +5 -0
  34. metadata +82 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6ce10dc5e5d7b6c656d0f0103447d52ce0bb746ba5a39bcc2821b9d249aba333
4
+ data.tar.gz: 7658854a8f655919f872141870fbf95d76ee9849ea362ae9dd4b0a20848bcd60
5
+ SHA512:
6
+ metadata.gz: 7c7ab31fb74e3a6c61b5beda94efdca316f2188e06b42799f8ff25106795850be54b110ae202165d679f68010607893645b01a979dca9e0c70b5fd1744e1cce8
7
+ data.tar.gz: 4481bf4742675a24b4d2049d4f88fdeaf996769bb7190ee452c46177651125e3f2c521b54ecf20dfb233efbc6a9d3fc4fb93ea66f82279dccbf9e02ea10cd84d
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ *.gem
11
+ *.lock
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,39 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ NewCops: enable
4
+
5
+ # Metrics
6
+
7
+ Metrics/BlockLength:
8
+ Max: 240
9
+
10
+ Metrics/MethodLength:
11
+ Max: 30
12
+
13
+ Metrics/ModuleLength:
14
+ Max: 240
15
+
16
+ Metrics/CyclomaticComplexity:
17
+ Max: 10
18
+
19
+ Metrics/PerceivedComplexity:
20
+ Max: 10
21
+
22
+ # Documentation
23
+
24
+ Style/Documentation:
25
+ Enabled: false
26
+
27
+ # Style
28
+
29
+ Style/HashSyntax:
30
+ EnforcedStyle: ruby19_no_mixed_keys
31
+
32
+ Style/SymbolArray:
33
+ Enabled: true
34
+
35
+ Naming/AccessorMethodName:
36
+ Enabled: false
37
+
38
+ Layout/LineLength:
39
+ Max: 150
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-08-13
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in blockfrostruby.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+ gem 'rspec', '~> 3.0'
10
+ gem 'webmock'
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # Blockfrostruby
2
+
3
+ Ruby SDK to work with Blockfrost (Cardano Blockchain API)
4
+ Blockfrost is a hosted API as a service serving the data from the Cardano blockchain.
5
+ This gem is Ruby SDK for Blockfrost.io to enable developers
6
+ to use full power of this API without having to create basic functions for it.
7
+ The OpenAPI documentation is hosted at https://github.com/blockfrost/openapi.\
8
+ This gem is licensed under ASL 2.0.
9
+
10
+ More information about using this API can be found on https://docs.blockfrost.io/
11
+ ## Installation
12
+
13
+ For now, it's not hosted on a RubyGems,
14
+ so you can install this SDK only from this repo.
15
+
16
+ To do this, download this repo to your machine, then go to the directory:
17
+
18
+ $ cd path-to-dir-with-this-repo
19
+
20
+ And run next commands:
21
+
22
+ $ git add .
23
+ $ gem build blockfrost-ruby
24
+ $ gem install ./blockfrost-ruby-0.1.0.gem
25
+
26
+ That's it! You may use the gem in your projects.
27
+
28
+ ## Usage
29
+
30
+ To use this SDK, you first need login into blockfrost.io and create your project to retrieve your API token.
31
+
32
+ And here are examples of how to use this SDK.
33
+
34
+ ```ruby
35
+
36
+ require 'blockfrost-ruby'
37
+
38
+ blockfrost = Blockfrostruby::CardanoMainNet.new('your-API-key')
39
+ blockfrost.get_health
40
+ blockfrost.get_transaction('f6780212...36f0c20b6')
41
+
42
+ # The result of request is a hash object with keys [:status, :body]. Examples:
43
+ # {:status=>"200", :body=>{"is_healthy"=>true}}
44
+ # {:status=>"404", :body=>{"status_code"=>404, "error"=>"Not Found", "message"=>"The requested component has not been found."}}
45
+
46
+ # Requests which returns a list of result can be called with params.
47
+ # Allowed params are:
48
+ # :count, :page, :order, :from, :to (the same as decribed in blockfrost docs)
49
+ # :from_page, :to_page, :parallel_requests, :sleep_between_retries_ms (see below)
50
+
51
+ # Example of usage:
52
+ blockfrost.get_asset_history('81791e9e..1303035', { count: 50, page: 3, order: 'desc' })
53
+
54
+
55
+ # You may define what value should be used by default when you initialize the object.
56
+ config = { use_asc_order_as_default: false, default_count_per_page: 10 } # See the list of params below
57
+ blockfrost_configured = Blockfrostruby::CardanoMainNet.new('your-API-key', config)
58
+ blockfrost_configured.get_block_latest_transactions # will add order=asc&count=10 to request
59
+
60
+ # But you're still able to set params for specific action:
61
+ blockfrost_configured.get_block_latest_transactions({ count: 20 }) # will add order=asc&count=20 to request
62
+
63
+ # ==================
64
+ # ==================
65
+ # ==================
66
+
67
+ # On the other words:
68
+
69
+ # 1. Install the gem and require it
70
+
71
+ require 'blockfrost-ruby'
72
+
73
+
74
+ # 2. Initialize the object with the network:
75
+
76
+ blockfrost_mainnet = Blockfrostruby::CardanoMainNet.new('your-API-key')
77
+
78
+ # Or if you want to access other networks:
79
+
80
+ blockfrost_testnet = Blockfrostruby::CardanoTestNet.new('your-API-key')
81
+ blockfrost_ipfs = Blockfrostruby::IPFS.new('your-API-key')
82
+
83
+
84
+ # 3. When you initialize, you may configure what params this object will use as default:
85
+
86
+ config = { default_count_per_page: 10 }
87
+ blockfrost = Blockfrostruby::CardanoMainNet.new('your-API-key', config)
88
+
89
+ # The list of values that can be defined in the config and its default values:
90
+
91
+ # config = {
92
+ # use_asc_order_as_default: true - the orders of lists will be asc by default
93
+ # default_count_per_page: 100 - 100 items per page
94
+ # parallel_requests: 10 - when fetching pages concurrently,
95
+ # that param defines how many request
96
+ # will be sent in one bunch
97
+ # sleep_between_retries_ms: 500 - when you send too many concurent requests,
98
+ # your account may reach the limit and the API will
99
+ # start to answer you with 4xx statuses. This value
100
+ # defines how long to wait between retries
101
+ # }
102
+
103
+
104
+ # 4. You may pass params explicitly for every request if that request accept params:
105
+
106
+ blockfrost.get_block_latest_transactions({ count: 20 })
107
+
108
+ # Allowed params are:
109
+ # :order, :page, :count, :from, :to - add ex. count= to the request
110
+ # :from_page, :to_page - when you want to get many pages you may define this params.
111
+ # Also note that you may define only :from_page and it will send requests until
112
+ # the not-nil response will be fetched.
113
+ # And 2 more params are:
114
+ # :parallel_requests, :sleep_between_retries_ms - the same as in config,
115
+ # but may be set directly to the request.
116
+
117
+ # Example of request:
118
+
119
+ blockfrost.get_list_of_next_blocks("hash_here", { count: 40, from_page: 11520, to_page: 11640, parallel_requests: 15 })
120
+
121
+ # That's it! Enjoy
122
+
123
+ ```
124
+ All endpoints can be found here: https://docs.blockfrost.io/
125
+
126
+ ## Development
127
+
128
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
129
+
130
+ 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).
131
+
132
+ ## Contributing
133
+
134
+ Bug reports and pull requests are welcome on GitHub at https://github.com/blockfrost/blockfrostruby.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/blockfrostruby/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'blockfrost-ruby'
7
+ spec.version = Blockfrostruby::VERSION
8
+ spec.authors = ['Ivan (https://github.com/18bitmood)']
9
+ spec.email = ['ivan.papushoi@mail.ru']
10
+
11
+ spec.summary = 'Ruby SDK to work with Blockfrost (Cardano Blockchain API)'
12
+ spec.description = "Blockfrost is a hosted API as a service serving the data from the Cardano blockchain.\
13
+ This gem is Ruby SDK for Blockfrost.io to enable developers\
14
+ to use full power of this API without having to create basic functions for it.\
15
+ The OpenAPI documentation is hosted at https://github.com/blockfrost/openapi.\
16
+ This gem is licensed under ASL 2.0."
17
+ spec.homepage = 'https://github.com/blockfrost/blockfrost-ruby'
18
+ spec.required_ruby_version = '>= 2.5.0'
19
+
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ spec.metadata['homepage_uri'] = spec.homepage
23
+ spec.metadata['source_code_uri'] = 'https://github.com/blockfrost/blockfrost-ruby'
24
+ spec.metadata['changelog_uri'] = 'https://github.com/blockfrost/blockfrost-ruby/blob/master/CHANGELOG.md'
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
30
+ end
31
+ spec.bindir = 'exe'
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ['lib']
34
+
35
+ # Uncomment to register a new dependency of your gem
36
+ # spec.add_dependency "example-gem", "~> 1.0"
37
+
38
+ # For more information and examples about making a new gem, checkout our
39
+ # guide at: https://bundler.io/guides/creating_gem.html
40
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ # gem build blockfrost-ruby
4
+ # gem install ./blockfrost-ruby-0.1.0.gem
5
+ # require 'blockfrost-ruby'
6
+ # blockfrost = Blockfrostruby::CardanoMainNet.new()
7
+
8
+ require_relative 'blockfrostruby/version'
9
+ require_relative 'blockfrostruby/constants'
10
+ require_relative 'blockfrostruby/configuration'
11
+
12
+ require_relative 'blockfrostruby/endpoints/cardano/health_endpoints'
13
+ require_relative 'blockfrostruby/endpoints/cardano/metrics_endpoints'
14
+ require_relative 'blockfrostruby/endpoints/cardano/accounts_endpoints'
15
+ require_relative 'blockfrostruby/endpoints/cardano/addresses_endpoints'
16
+ require_relative 'blockfrostruby/endpoints/cardano/assets_endpoints'
17
+ require_relative 'blockfrostruby/endpoints/cardano/blocks_endpoints'
18
+ require_relative 'blockfrostruby/endpoints/cardano/epochs_endpoints'
19
+ require_relative 'blockfrostruby/endpoints/cardano/ledger_endpoints'
20
+ require_relative 'blockfrostruby/endpoints/cardano/metadata_endpoints'
21
+ require_relative 'blockfrostruby/endpoints/cardano/network_endpoints'
22
+ require_relative 'blockfrostruby/endpoints/cardano/pools_endpoints'
23
+ require_relative 'blockfrostruby/endpoints/cardano/transactions_endpoints'
24
+ require_relative 'blockfrostruby/endpoints/cardano/nutlink_endpoints'
25
+ require_relative 'blockfrostruby/endpoints/ipfs/ipfs_endpoints'
26
+ require_relative 'blockfrostruby/endpoints/custom_endpoints'
27
+
28
+ module Blockfrostruby
29
+ class Net
30
+ include Configuration
31
+ include CustomEndpoints
32
+
33
+ attr_reader :config, :project_id, :url
34
+
35
+ def initialize(project_id, config = {})
36
+ @project_id = project_id
37
+ @url = nil
38
+ @config = Configuration.define_config(config)
39
+ end
40
+ end
41
+
42
+ class CardanoMainNet < Net
43
+ include HealthEndpoints
44
+ include MetricsEndpoints
45
+ include AccountsEndpoints
46
+ include AddressesEndpoints
47
+ include AssetsEndpoints
48
+ include BlocksEndpoints
49
+ include EpochsEndpoints
50
+ include LedgerEndpoints
51
+ include MetadataEndpoints
52
+ include NetworkEndpoints
53
+ include PoolsEndpoints
54
+ include TransactionsEndpoints
55
+ include NutlinkEndpoints
56
+
57
+ # Create an instanse of CardanoMainNet object.
58
+ # Using of SDK is a calling methods on such object.
59
+ #
60
+ # @param project_id [String] the project_id from API
61
+ # @param config [Hash] a config with params: use_asc_order_as_default, default_count_per_page, parallel_requests, sleep_between_retries_ms
62
+ # @return [Object] with attr_reader :config, :project_id, :url
63
+ def initialize(project_id, config = {})
64
+ super
65
+ @url = CARDANO_MAINNET_URL
66
+ end
67
+ end
68
+
69
+ class CardanoTestNet < CardanoMainNet
70
+ # Create an instanse of CardanoTestNet object.
71
+ # Using of SDK is a calling methods on such object.
72
+ #
73
+ # @param project_id [String] the project_id from API
74
+ # @param config [Hash] a config with params: use_asc_order_as_default, default_count_per_page, parallel_requests, sleep_between_retries_ms
75
+ # @return [Object] with attr_reader :config, :project_id, :url
76
+ def initialize(project_id, config = {})
77
+ super
78
+ @url = CARDANO_TESTNET_URL
79
+ end
80
+ end
81
+
82
+ class IPFS < Net
83
+ include IPFSEndpoints
84
+
85
+ # Create an instanse of IPFS object.
86
+ # Using of SDK is a calling methods on such object.
87
+ #
88
+ # @param project_id [String] the project_id from API
89
+ # @param config [Hash] a config with params: use_asc_order_as_default, default_count_per_page, parallel_requests, sleep_between_retries_ms
90
+ # @return [Object] with attr_reader :config, :project_id, :url
91
+ def initialize(project_id, config = {})
92
+ super
93
+ @url = IPFS_URL
94
+ end
95
+ end
96
+
97
+ class Error < StandardError; end
98
+ end
@@ -0,0 +1,4 @@
1
+ use_asc_order_as_default: true
2
+ default_count_per_page: 100
3
+ parallel_requests: 10
4
+ sleep_between_retries_ms: 500
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require_relative './validator'
5
+
6
+ module Configuration
7
+ include Validator
8
+
9
+ class << self
10
+ # Loads a default config from config.yml file.
11
+ def default_config
12
+ YAML.safe_load(
13
+ File.open("#{File.dirname(__FILE__)}/config.yml").read
14
+ ).transform_keys(&:to_sym)
15
+ end
16
+
17
+ # Calling when Net subclass object creating, validate passed hash, and apply parametres to the Net object.
18
+ #
19
+ # @param config [Hash] includes passed hash to constructor.
20
+ # @return [Hash] with valid params.
21
+ def define_config(config)
22
+ result = default_config
23
+ Validator.validate_init_params(config)
24
+ config.each do |key, value|
25
+ result[key] = value unless result[key].nil?
26
+ end
27
+ result
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ CARDANO_MAINNET_URL = 'https://cardano-mainnet.blockfrost.io/api/v0'
4
+ CARDANO_TESTNET_URL = 'https://cardano-testnet.blockfrost.io/api/v0'
5
+ IPFS_URL = 'https://ipfs.blockfrost.io/api/v0'
6
+
7
+ MAX_COUNT_PER_PAGE = 100
8
+ MAX_NUMBER_OF_PARALLEL_REQUESTS = 200
9
+ MAX_RETRIES_IN_PARALLEL_REQUESTS = 10