beaconcha 1.0.0

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: 38bda97ce7fea8fe8440d0adfa3f33a4c12203ceeaabff5f11c4ed7c5bb81e6c
4
+ data.tar.gz: ea23d6c39c05093a919ae7109e4de01c8337887c5fb684ac058d17d7c446501e
5
+ SHA512:
6
+ metadata.gz: 6ad1e5be6f6303f86bae0eae122e0fa6e9f43f272b5b9039ce079a04f2274c50a651095a1e6c5e7282a02d2d8362255b53bccbf3290ad5fa91373b150eb93353
7
+ data.tar.gz: fd55204bb2ae65dd053fc1fcdb5bbfacdc61cfda3d89e7ff00158583d7cf7c38bc862d2891b9afb494b539727806312c90e1cc1dc9ff73e4f1ff4180fac768a8
@@ -0,0 +1,45 @@
1
+ version: 2.1 # Use 2.1 to enable using orbs and other features.
2
+
3
+ # Declare the orbs that we'll use in our config.
4
+ orbs:
5
+ ruby: circleci/ruby@1.0
6
+
7
+ jobs:
8
+ rubocop:
9
+ parallelism: 1
10
+ docker:
11
+ - image: cimg/ruby:3.1-node
12
+ steps:
13
+ - checkout
14
+ - ruby/install-deps
15
+ - run:
16
+ name: Run Rubocop
17
+ command: bundle exec rubocop
18
+ test:
19
+ parameters:
20
+ ruby-image:
21
+ type: string
22
+ parallelism: 1
23
+ docker:
24
+ - image: << parameters.ruby-image >>
25
+ steps:
26
+ - checkout
27
+ - ruby/install-deps
28
+ - run:
29
+ name: Run tests
30
+ command: bundle exec rspec -fd
31
+
32
+ workflows:
33
+ version: 2
34
+ checks:
35
+ jobs:
36
+ - rubocop
37
+ - test:
38
+ matrix:
39
+ parameters:
40
+ ruby-image:
41
+ - cimg/ruby:2.6-node
42
+ - cimg/ruby:2.7-node
43
+ - cimg/ruby:3.0-node
44
+ - cimg/ruby:3.1-node
45
+ - cimg/ruby:3.2-node
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior:
15
+ 1. Go to '...'
16
+ 2. Click on '....'
17
+ 3. Scroll down to '....'
18
+ 4. See error
19
+
20
+ **Expected behavior**
21
+ A clear and concise description of what you expected to happen.
22
+
23
+ **Screenshots**
24
+ If applicable, add screenshots to help explain your problem.
25
+
26
+ **Desktop (please complete the following information):**
27
+ - OS: [e.g. iOS]
28
+ - Browser [e.g. chrome, safari]
29
+ - Version [e.g. 22]
30
+
31
+ **Smartphone (please complete the following information):**
32
+ - Device: [e.g. iPhone6]
33
+ - OS: [e.g. iOS8.1]
34
+ - Browser [e.g. stock browser, safari]
35
+ - Version [e.g. 22]
36
+
37
+ **Additional context**
38
+ Add any other context about the problem here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,15 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ open-pull-requests-limit: 10
8
+ ignore:
9
+ - dependency-name: webmock
10
+ versions:
11
+ - 3.11.1
12
+ - 3.11.3
13
+ - dependency-name: rspec
14
+ versions:
15
+ - 3.10.0
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ .byebug_history
14
+ .env
15
+
16
+ *.gem
17
+ *.ruby-*
18
+ .envrc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Style/Documentation:
7
+ # Skips checking to make sure top level modules / classes have a comment.
8
+ Enabled: false
9
+
10
+ Layout/LineLength:
11
+ Max: 100
12
+ Exclude:
13
+ - "**/*.gemspec"
14
+
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - "spec/**/*"
18
+
19
+ Style/StringLiterals:
20
+ EnforcedStyle: double_quotes
21
+
22
+ Style/FrozenStringLiteralComment:
23
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ## [1.0.0]
2
+
3
+ ### Added
4
+
5
+ - Initialise repository.
6
+ - Add Beaconcha::Client to connect to Beaconcha API using user credentials.
7
+ - Add spec for Client with a cached response using VCR.
8
+ - Add CircleCI to run the specs on pull requests.
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at liuliang@users.noreply.github.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,3 @@
1
+ ## Contributing
2
+
3
+ Bug reports and pull requests are welcome on GitHub at https://github.com/liuliang/beaconcha. 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/liuliang/beaconcha/blob/main/CODE_OF_CONDUCT.md).
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Include gem dependencies from beaconcha.gemspec
4
+ gemspec
5
+
6
+ gem "byebug", "~> 11.1.3"
7
+ gem "dotenv", "~> 2.8.1"
8
+ gem "rake", "~> 13.0"
9
+ gem "rspec", "~> 3.12"
10
+ gem "rubocop", "~> 1.47.0"
11
+ gem "vcr", "~> 6.1.0"
12
+ gem "webmock", "~> 3.18.1"
data/Gemfile.lock ADDED
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ beaconcha (1.0.0)
5
+ httparty (>= 0.18.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.1)
11
+ public_suffix (>= 2.0.2, < 6.0)
12
+ ast (2.4.2)
13
+ byebug (11.1.3)
14
+ crack (0.4.5)
15
+ rexml
16
+ diff-lcs (1.5.0)
17
+ dotenv (2.8.1)
18
+ hashdiff (1.0.1)
19
+ httparty (0.21.0)
20
+ mini_mime (>= 1.0.0)
21
+ multi_xml (>= 0.5.2)
22
+ json (2.6.3)
23
+ mini_mime (1.1.2)
24
+ multi_xml (0.6.0)
25
+ parallel (1.22.1)
26
+ parser (3.2.1.0)
27
+ ast (~> 2.4.1)
28
+ public_suffix (5.0.1)
29
+ rainbow (3.1.1)
30
+ rake (13.0.6)
31
+ regexp_parser (2.7.0)
32
+ rexml (3.2.5)
33
+ rspec (3.12.0)
34
+ rspec-core (~> 3.12.0)
35
+ rspec-expectations (~> 3.12.0)
36
+ rspec-mocks (~> 3.12.0)
37
+ rspec-core (3.12.1)
38
+ rspec-support (~> 3.12.0)
39
+ rspec-expectations (3.12.2)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.12.0)
42
+ rspec-mocks (3.12.3)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.12.0)
45
+ rspec-support (3.12.0)
46
+ rubocop (1.47.0)
47
+ json (~> 2.3)
48
+ parallel (~> 1.10)
49
+ parser (>= 3.2.0.0)
50
+ rainbow (>= 2.2.2, < 4.0)
51
+ regexp_parser (>= 1.8, < 3.0)
52
+ rexml (>= 3.2.5, < 4.0)
53
+ rubocop-ast (>= 1.26.0, < 2.0)
54
+ ruby-progressbar (~> 1.7)
55
+ unicode-display_width (>= 2.4.0, < 3.0)
56
+ rubocop-ast (1.27.0)
57
+ parser (>= 3.2.1.0)
58
+ ruby-progressbar (1.12.0)
59
+ unicode-display_width (2.4.2)
60
+ vcr (6.1.0)
61
+ webmock (3.18.1)
62
+ addressable (>= 2.8.0)
63
+ crack (>= 0.3.2)
64
+ hashdiff (>= 0.4.0, < 2.0.0)
65
+
66
+ PLATFORMS
67
+ x86_64-darwin-22
68
+
69
+ DEPENDENCIES
70
+ beaconcha!
71
+ byebug (~> 11.1.3)
72
+ dotenv (~> 2.8.1)
73
+ rake (~> 13.0)
74
+ rspec (~> 3.12)
75
+ rubocop (~> 1.47.0)
76
+ vcr (~> 6.1.0)
77
+ webmock (~> 3.18.1)
78
+
79
+ BUNDLED WITH
80
+ 2.4.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Alex
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,105 @@
1
+ # Ruby Beaconcha
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/beaconcha.svg)](https://badge.fury.io/rb/beaconcha)
4
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/liuliang/beaconcha/blob/main/LICENSE.txt)
5
+ [![CircleCI Build Status](https://circleci.com/gh/liuliang/beaconcha.svg?style=shield)](https://circleci.com/gh/liuliang/beaconcha)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/a99a88d28ad37a79dbf6/maintainability)](https://codeclimate.com/github/codeclimate/codeclimate/maintainability)
7
+
8
+ Use the [Beaconcha API](https://beaconcha.in/api/v1/docs/index.html) with Ruby!
9
+
10
+ ## Installation
11
+
12
+ ### Bundler
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem "beaconcha"
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle install
23
+
24
+ ### Gem install
25
+
26
+ Or install with:
27
+
28
+ $ gem install beaconcha
29
+
30
+ and require with:
31
+
32
+ ```ruby
33
+ require "beaconcha"
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ - Get your API key from [https://beaconcha.in/user/settings#api](https://beaconcha.in/user/settings#api)
39
+
40
+ ### Quickstart
41
+
42
+ For a quick test you can pass your token directly to a new client:
43
+
44
+ ```ruby
45
+ client = Beaconcha::Client.new(api_key: "api_key_goes_here", uri_base: "https://beaconcha.in")
46
+ ```
47
+
48
+ ### With Config
49
+
50
+ For a more robust setup, you can configure the gem with your API keys, for example in an `beaconcha.rb` initializer file. Never hardcode secrets into your codebase - instead use something like [dotenv](https://github.com/motdotla/dotenv) to pass the keys safely into your environments.
51
+
52
+ ```ruby
53
+ Beaconcha.configure do |config|
54
+ config.api_key = ENV.fetch('BEACONCHA_API_KEY')
55
+ config.uri_base = ENV.fetch('BEACONCHA_URI_BASE')
56
+ end
57
+ ```
58
+
59
+ Then you can create a client like this:
60
+
61
+ ```ruby
62
+ client = Beaconcha::Client.new
63
+ ```
64
+
65
+ ### Example
66
+
67
+ ```ruby
68
+ client.epoch.retrieve(id: 10000)
69
+ client.eth_store.retrieve(day: "latest")
70
+ client.execution.eth1deposit(txhash: "xxxx")
71
+ client.execution.produced(id: "xxxx", limit: 1, offset: 1)
72
+ client.misc.healthz
73
+ client.rocketpool.stats
74
+ client.slot.retrieve(id: "xxxx")
75
+ client.sync_committee.retrieve(period: "xxxx")
76
+ client.validator.retrieve(id: "xxxx")
77
+ ```
78
+
79
+ ## Development
80
+
81
+ After checking out the repo, run `bin/setup` to install dependencies. You can run `bin/console` for an interactive prompt that will allow you to experiment.
82
+
83
+ To install this gem onto your local machine, run `bundle exec rake install`.
84
+
85
+ ## Release
86
+
87
+ First run the specs without VCR so they actually hit the API. This will cost about 2 cents. You'll need to add your `BEACONCHA_API_KEY=` in `.env`.
88
+
89
+ ```
90
+ NO_VCR=true bundle exec rspec
91
+ ```
92
+
93
+ Then update the version number in `version.rb`, update `CHANGELOG.md`, run `bundle install` to update Gemfile.lock, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
94
+
95
+ ## Contributing
96
+
97
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/liuliang/beaconcha>. 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/liuliang/beaconcha/blob/main/CODE_OF_CONDUCT.md).
98
+
99
+ ## License
100
+
101
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
102
+
103
+ ## Code of Conduct
104
+
105
+ Everyone interacting in the Ruby Beaconcha project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/liuliang/beaconcha/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/beaconcha.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ require_relative "lib/beaconcha/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "beaconcha"
5
+ spec.version = Beaconcha::VERSION
6
+ spec.authors = ["liuliang"]
7
+ spec.email = ["liuliang@users.noreply.github.com"]
8
+
9
+ spec.summary = "A Ruby gem for the Beaconcha API"
10
+ spec.homepage = "https://github.com/liuliang/beaconcha"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/liuliang/beaconcha"
16
+ spec.metadata["changelog_uri"] = "https://github.com/liuliang/beaconcha/blob/main/CHANGELOG.md"
17
+ spec.metadata["rubygems_mfa_required"] = "true"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency "httparty", ">= 0.18.1"
29
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "beaconcha"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,79 @@
1
+ module Beaconcha
2
+ class Client
3
+ def initialize(api_key: nil, uri_base: nil)
4
+ Beaconcha.configuration.api_key = api_key if api_key
5
+ Beaconcha.configuration.uri_base = uri_base if uri_base
6
+ end
7
+
8
+ def epoch
9
+ @epoch ||= Beaconcha::Epoch.new
10
+ end
11
+
12
+ def slot
13
+ @slot ||= Beaconcha::Slot.new
14
+ end
15
+
16
+ def validator
17
+ @validator ||= Beaconcha::Validator.new
18
+ end
19
+
20
+ def sync_committee
21
+ @sync_committee ||= Beaconcha::SyncCommittee.new
22
+ end
23
+
24
+ def execution
25
+ @execution ||= Beaconcha::Execution.new
26
+ end
27
+
28
+ def eth_store
29
+ @eth_store ||= Beaconcha::EthStore.new
30
+ end
31
+
32
+ def misc
33
+ @misc ||= Beaconcha::Misc.new
34
+ end
35
+
36
+ def rocketpool
37
+ @rocketpool ||= Beaconcha::Rocketpool.new
38
+ end
39
+
40
+ def self.get(path:, query: {})
41
+ HTTParty.get(
42
+ uri(path: path),
43
+ query: query&.compact,
44
+ headers: headers
45
+ )
46
+ end
47
+
48
+ def self.get_without_version(path:, query: {})
49
+ HTTParty.get(
50
+ uri_without_version(path: path),
51
+ query: query&.compact,
52
+ headers: headers
53
+ )
54
+ end
55
+
56
+ def self.post(path:, parameters:)
57
+ HTTParty.post(
58
+ uri(path: path),
59
+ headers: headers,
60
+ body: parameters&.compact&.to_json
61
+ )
62
+ end
63
+
64
+ private_class_method def self.uri(path:)
65
+ "#{Beaconcha.configuration.uri_base}/api/#{Beaconcha.configuration.api_version}#{path}"
66
+ end
67
+
68
+ private_class_method def self.uri_without_version(path:)
69
+ "#{Beaconcha.configuration.uri_base}/api#{path}"
70
+ end
71
+
72
+ private_class_method def self.headers
73
+ {
74
+ "Content-Type" => "application/json",
75
+ "apikey" => Beaconcha.configuration.api_key.to_s
76
+ }
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,16 @@
1
+ module Beaconcha
2
+ class Epoch
3
+ def initialize(api_key: nil, uri_base: nil)
4
+ Beaconcha.configuration.api_key = api_key if api_key
5
+ Beaconcha.configuration.uri_base = uri_base if uri_base
6
+ end
7
+
8
+ def retrieve(id:)
9
+ Beaconcha::Client.get(path: "/epoch/#{id}")
10
+ end
11
+
12
+ def slots(id:)
13
+ Beaconcha::Client.get(path: "/epoch/#{id}/slots")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module Beaconcha
2
+ class EthStore
3
+ def initialize(api_key: nil, uri_base: nil)
4
+ Beaconcha.configuration.api_key = api_key if api_key
5
+ Beaconcha.configuration.uri_base = uri_base if uri_base
6
+ end
7
+
8
+ def retrieve(day:)
9
+ Beaconcha::Client.get(path: "/ethstore/#{day}")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ module Beaconcha
2
+ class Execution
3
+ def initialize(api_key: nil, uri_base: nil)
4
+ Beaconcha.configuration.api_key = api_key if api_key
5
+ Beaconcha.configuration.uri_base = uri_base if uri_base
6
+ end
7
+
8
+ def eth1deposit(txhash:)
9
+ Beaconcha::Client.get(path: "/eth1deposit/#{txhash}")
10
+ end
11
+
12
+ def address(address:, token: nil)
13
+ Beaconcha::Client.get(path: "/execution/address/#{address}", query: { token: token })
14
+ end
15
+
16
+ def block(block_number:)
17
+ Beaconcha::Client.get(path: "/execution/block/#{block_number}")
18
+ end
19
+
20
+ def gasnow
21
+ Beaconcha::Client.get(path: "/execution/gasnow")
22
+ end
23
+
24
+ def produced(id:, limit: nil, offset: nil)
25
+ Beaconcha::Client.get(path: "/execution/#{id}/produced",
26
+ query: { limit: limit, offset: offset })
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ module Beaconcha
2
+ class Misc
3
+ def initialize(api_key: nil, uri_base: nil)
4
+ Beaconcha.configuration.api_key = api_key if api_key
5
+ Beaconcha.configuration.uri_base = uri_base if uri_base
6
+ end
7
+
8
+ def healthz
9
+ Beaconcha::Client.get_without_version(path: "/healthz")
10
+ end
11
+
12
+ def healthz_loadbalancer
13
+ Beaconcha::Client.get_without_version(path: "/healthz-loadbalancer")
14
+ end
15
+
16
+ def chart(chart:)
17
+ Beaconcha::Client.get(path: "/chart/#{chart}")
18
+ end
19
+
20
+ def graffitiwall(slot: nil)
21
+ Beaconcha::Client.get(path: "/graffitiwall", query: { slot: slot })
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module Beaconcha
2
+ class Rocketpool
3
+ def initialize(api_key: nil, uri_base: nil)
4
+ Beaconcha.configuration.api_key = api_key if api_key
5
+ Beaconcha.configuration.uri_base = uri_base if uri_base
6
+ end
7
+
8
+ def validator(id:)
9
+ Beaconcha::Client.get(path: "/rocketpool/validator/#{id}")
10
+ end
11
+
12
+ def stats
13
+ Beaconcha::Client.get(path: "/rocketpool/stats")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ module Beaconcha
2
+ class Slot
3
+ def initialize(api_key: nil, uri_base: nil)
4
+ Beaconcha.configuration.api_key = api_key if api_key
5
+ Beaconcha.configuration.uri_base = uri_base if uri_base
6
+ end
7
+
8
+ def retrieve(id:)
9
+ Beaconcha::Client.get(path: "/slot/#{id}")
10
+ end
11
+
12
+ def attestations(id:)
13
+ Beaconcha::Client.get(path: "/slot/#{id}/attestations")
14
+ end
15
+
16
+ def attesterslashings(id:)
17
+ Beaconcha::Client.get(path: "/slot/#{id}/attesterslashings")
18
+ end
19
+
20
+ def deposits(id:)
21
+ Beaconcha::Client.get(path: "/slot/#{id}/deposits")
22
+ end
23
+
24
+ def proposerslashings(id:)
25
+ Beaconcha::Client.get(path: "/slot/#{id}/proposerslashings")
26
+ end
27
+
28
+ def voluntaryexits(id:)
29
+ Beaconcha::Client.get(path: "/slot/#{id}/voluntaryexits")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ module Beaconcha
2
+ class SyncCommittee
3
+ def initialize(api_key: nil, uri_base: nil)
4
+ Beaconcha.configuration.api_key = api_key if api_key
5
+ Beaconcha.configuration.uri_base = uri_base if uri_base
6
+ end
7
+
8
+ def retrieve(period:)
9
+ Beaconcha::Client.get(path: "/sync_committee/#{period}")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,67 @@
1
+ module Beaconcha
2
+ class Validator
3
+ def initialize(api_key: nil, uri_base: nil)
4
+ Beaconcha.configuration.api_key = api_key if api_key
5
+ Beaconcha.configuration.uri_base = uri_base if uri_base
6
+ end
7
+
8
+ def eth1(address:, limit: nil, offset: nil)
9
+ Beaconcha::Client.get(path: "/validator/eth1/#{address}",
10
+ query: { limit: limit, offset: offset })
11
+ end
12
+
13
+ def leaderboard
14
+ Beaconcha::Client.get(path: "/validator/leaderboard")
15
+ end
16
+
17
+ def stats(id:)
18
+ Beaconcha::Client.get(path: "/validator/stats/#{id}")
19
+ end
20
+
21
+ def retrieve(id:)
22
+ Beaconcha::Client.get(path: "/validator/#{id}")
23
+ end
24
+
25
+ def attestationeffectiveness(id:)
26
+ Beaconcha::Client.get(path: "/validator/#{id}/attestationeffectiveness")
27
+ end
28
+
29
+ def attestationefficiency(id:)
30
+ Beaconcha::Client.get(path: "/validator/#{id}/attestationefficiency")
31
+ end
32
+
33
+ def attestations(id:)
34
+ Beaconcha::Client.get(path: "/validator/#{id}/attestations")
35
+ end
36
+
37
+ def balancehistory(id:, latest_epoch: nil, limit: nil, offset: nil)
38
+ Beaconcha::Client.get(path: "/validator/#{id}/balancehistory",
39
+ query: { latest_epoch: latest_epoch,
40
+ limit: limit, offset: offset })
41
+ end
42
+
43
+ def deposits(id:)
44
+ Beaconcha::Client.get(path: "/validator/#{id}/deposits")
45
+ end
46
+
47
+ def execution_performance(id:)
48
+ Beaconcha::Client.get(path: "/validator/#{id}/execution/performance")
49
+ end
50
+
51
+ def incomedetailhistory(id:)
52
+ Beaconcha::Client.get(path: "/validator/#{id}/incomedetailhistory")
53
+ end
54
+
55
+ def performance(id:)
56
+ Beaconcha::Client.get(path: "/validator/#{id}/performance")
57
+ end
58
+
59
+ def proposals(id:, epoch: nil)
60
+ Beaconcha::Client.get(path: "/validator/#{id}/proposals", query: { epoch: epoch })
61
+ end
62
+
63
+ def queue
64
+ Beaconcha::Client.get(path: "/validators/queue")
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module Beaconcha
2
+ VERSION = "1.0.0".freeze
3
+ end
data/lib/beaconcha.rb ADDED
@@ -0,0 +1,53 @@
1
+ require "httparty"
2
+
3
+ require_relative "beaconcha/client"
4
+ require_relative "beaconcha/epoch"
5
+ require_relative "beaconcha/slot"
6
+ require_relative "beaconcha/validator"
7
+ require_relative "beaconcha/sync_committee"
8
+ require_relative "beaconcha/execution"
9
+ require_relative "beaconcha/eth_store"
10
+ require_relative "beaconcha/rocketpool"
11
+ require_relative "beaconcha/misc"
12
+ require_relative "beaconcha/version"
13
+
14
+ module Beaconcha
15
+ class Error < StandardError; end
16
+ class ConfigurationError < Error; end
17
+
18
+ class Configuration
19
+ attr_writer :api_key, :uri_base
20
+ attr_accessor :api_version
21
+
22
+ DEFAULT_API_VERSION = "v1".freeze
23
+
24
+ def initialize
25
+ @api_key = nil
26
+ @api_version = DEFAULT_API_VERSION
27
+ @uri_base = nil
28
+ end
29
+
30
+ def api_key
31
+ @api_key
32
+ end
33
+
34
+ def uri_base
35
+ return @uri_base if @uri_base
36
+
37
+ error_text = "Beaconcha uri base missing! See https://github.com/liuliang/beaconcha#usage"
38
+ raise ConfigurationError, error_text
39
+ end
40
+ end
41
+
42
+ class << self
43
+ attr_writer :configuration
44
+ end
45
+
46
+ def self.configuration
47
+ @configuration ||= Beaconcha::Configuration.new
48
+ end
49
+
50
+ def self.configure
51
+ yield(configuration)
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beaconcha
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - liuliang
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.18.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.18.1
27
+ description:
28
+ email:
29
+ - liuliang@users.noreply.github.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".circleci/config.yml"
35
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
36
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
37
+ - ".github/dependabot.yml"
38
+ - ".gitignore"
39
+ - ".rspec"
40
+ - ".rubocop.yml"
41
+ - CHANGELOG.md
42
+ - CODE_OF_CONDUCT.md
43
+ - CONTRIBUTING.md
44
+ - Gemfile
45
+ - Gemfile.lock
46
+ - LICENSE.txt
47
+ - README.md
48
+ - Rakefile
49
+ - beaconcha.gemspec
50
+ - bin/console
51
+ - bin/setup
52
+ - lib/beaconcha.rb
53
+ - lib/beaconcha/client.rb
54
+ - lib/beaconcha/epoch.rb
55
+ - lib/beaconcha/eth_store.rb
56
+ - lib/beaconcha/execution.rb
57
+ - lib/beaconcha/misc.rb
58
+ - lib/beaconcha/rocketpool.rb
59
+ - lib/beaconcha/slot.rb
60
+ - lib/beaconcha/sync_committee.rb
61
+ - lib/beaconcha/validator.rb
62
+ - lib/beaconcha/version.rb
63
+ homepage: https://github.com/liuliang/beaconcha
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ homepage_uri: https://github.com/liuliang/beaconcha
68
+ source_code_uri: https://github.com/liuliang/beaconcha
69
+ changelog_uri: https://github.com/liuliang/beaconcha/blob/main/CHANGELOG.md
70
+ rubygems_mfa_required: 'true'
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 2.6.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.4.6
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: A Ruby gem for the Beaconcha API
90
+ test_files: []