{"id":19791464,"url":"https://github.com/blockfrost/blockfrost-ruby","last_synced_at":"2025-05-01T01:32:27.677Z","repository":{"id":46817584,"uuid":"395312560","full_name":"blockfrost/blockfrost-ruby","owner":"blockfrost","description":"Ruby SDK for Blockfrost.io","archived":false,"fork":false,"pushed_at":"2024-01-15T13:34:49.000Z","size":186,"stargazers_count":7,"open_issues_count":3,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-19T18:05:07.040Z","etag":null,"topics":["api","blockfrost","cardano","ipfs","ruby","sdk"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blockfrost.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-08-12T12:33:09.000Z","updated_at":"2024-05-30T12:11:31.000Z","dependencies_parsed_at":"2024-01-05T21:50:06.430Z","dependency_job_id":null,"html_url":"https://github.com/blockfrost/blockfrost-ruby","commit_stats":{"total_commits":182,"total_committers":3,"mean_commits":"60.666666666666664","dds":0.05494505494505497,"last_synced_commit":"6ef8747163e0866f120055bcb7668e91b1de7cd4"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blockfrost%2Fblockfrost-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blockfrost%2Fblockfrost-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blockfrost%2Fblockfrost-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blockfrost%2Fblockfrost-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blockfrost","download_url":"https://codeload.github.com/blockfrost/blockfrost-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224085236,"owners_count":17253156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","blockfrost","cardano","ipfs","ruby","sdk"],"created_at":"2024-11-12T07:03:12.211Z","updated_at":"2024-11-12T07:03:12.835Z","avatar_url":"https://github.com/blockfrost.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Gem Version](https://badge.fury.io/rb/blockfrost-ruby.svg)](https://rubygems.org/gems/blockfrost-ruby)  \u003ca href=\"https://fivebinaries.com/\"\u003e\u003cimg src=\"https://img.shields.io/badge/made%20by-Five%20Binaries-darkviolet.svg?style=flat-square\" /\u003e\u003c/a\u003e\n\n\u003cimg src=\"https://blockfrost.io/images/logo.svg\" width=\"250\" align=\"right\" height=\"90\"\u003e\n\n# blockfrost-ruby\n\n\u003cbr/\u003e\n\n\u003cp align=\"center\"\u003eRuby SDK for \u003ca href=\"https://blockfrost.io\"\u003eBlockfrost.io\u003c/a\u003e API.\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e •\n  \u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e •\n  \u003ca href=\"#development\"\u003eDevelopment\u003c/a\u003e\n\u003c/p\u003e\n\u003cbr\u003e\n\n## Installation\n\nAdd the gem to your Gemfile\n\n    gem \"blockfrost-ruby\"\n\nOr download the latest release directly from rubygems.org:\n\n    $ gem install blockfrost-ruby\n\nTo build the current master, download this repo to your machine, then go to the directory:\n\n    $ cd blockfrost-ruby\n\nAnd run next commands:\n\n    $ git add .\n    $ gem build blockfrost-ruby\n    $ gem install ./blockfrost-ruby-0.1.0.gem\n\nThat's it! You may use the gem in your projects.\n\n## Usage\n\nTo use this SDK, you first need to login into blockfrost.io and create your project to retrieve your API token.\n\nAnd here are examples of how to use this SDK.\n\n```ruby\n\nrequire 'blockfrost-ruby'\n\nblockfrost = Blockfrostruby::CardanoMainNet.new('your-API-key')\nblockfrost.get_health\nblockfrost.get_transaction('f6780212...36f0c20b6')\n\n# The result of request is a hash object with keys [:status, :body]. Examples:\n# {:status=\u003e\"200\", :body=\u003e{\"is_healthy\"=\u003etrue}}\n# {:status=\u003e\"404\", :body=\u003e{\"status_code\"=\u003e404, \"error\"=\u003e\"Not Found\", \"message\"=\u003e\"The requested component has not been found.\"}}\n\n# Requests which returns a list of result can be called with params.\n# Allowed params are:\n# :count, :page, :order, :from, :to     (the same as decribed in blockfrost docs)\n# :from_page, :to_page, :parallel_requests, :sleep_between_retries_ms    (see below)\n\n# Example of usage:\nblockfrost.get_asset_history('81791e9e..1303035', { count: 50, page: 3, order: 'desc' })\n\n\n# You may define what value should be used by default when you initialize the object.\nconfig = { use_asc_order_as_default: false, default_count_per_page: 10 } # See the list of params below\nblockfrost_configured = Blockfrostruby::CardanoMainNet.new('your-API-key', config)\nblockfrost_configured.get_block_latest_transactions # will add order=asc\u0026count=10 to request\n\n# But you're still able to set params for specific action:\nblockfrost_configured.get_block_latest_transactions({ count: 20 }) # will add order=asc\u0026count=20 to request\n\n# ==================\n# ==================\n# ==================\n\n# On the other words:\n\n# 1. Install the gem and require it\n\nrequire 'blockfrost-ruby'\n\n\n# 2. Initialize the object with the network:\n\nblockfrost_mainnet = Blockfrostruby::CardanoMainNet.new('your-API-key')\n\n# Or if you want to access other networks: \n\nblockfrost_preview = Blockfrostruby::CardanoPreview.new('your-API-key')\nblockfrost_preprod = Blockfrostruby::CardanoPreprod.new('your-API-key')\nblockfrost_ipfs = Blockfrostruby::IPFS.new('your-API-key')\n\n\n# 3. When you initialize, you may configure what params this object will use as default:\n\nconfig = { default_count_per_page: 10 }\nblockfrost = Blockfrostruby::CardanoMainNet.new('your-API-key', config)\n\n# The list of values that can be defined in the config and its default values:\n\n# config = {\n#  use_asc_order_as_default: true    - the orders of lists will be asc by default\n#  default_count_per_page: 100       - 100 items per page\n#  parallel_requests: 10             - when fetching pages concurrently,\n#                                      that param defines how many request\n#                                      will be sent in one bunch\n#  sleep_between_retries_ms: 500     - when you send too many concurent requests,\n#                                      your account may reach the limit and the API will\n#                                      start to answer you with 4xx statuses. This value\n#                                      defines how long to wait between retries\n# }\n\n\n# 4. You may pass params explicitly for every request if that request accept params:\n\nblockfrost.get_block_latest_transactions({ count: 20 })\n\n# Allowed params are:\n# :order, :page, :count, :from, :to - add ex. count= to the request\n# :from_page, :to_page - when you want to get many pages you may define this params.\n# Also note that you may define only :from_page and it will send requests until\n# the not-nil response will be fetched.\n# And 2 more params are:\n# :parallel_requests, :sleep_between_retries_ms - the same as in config,\n# but may be set directly to the request.\n\n# Example of request:\n\nblockfrost.get_list_of_next_blocks(\"hash_here\", { count: 40, from_page: 11520, to_page: 11640, parallel_requests: 15 })\n\n# 5. Webhooks\n\n# Read about the available webhooks here: https://blockfrost.dev/docs/start-building/webhooks\n\n# This SDK provides a module BlockfrostRuby::Webhooks you can use as a mixin in your classes. It provides you with a method for verifying the signature sent with the webhook.\n\n# Example for Rails\n\n# config/routes.rb\npost \"/webhook\", to: \"cardano_webhooks#create\"\n\n# app/controllers/cardano_webhooks_controller.rb\nclass CardanoWebhooksController \u003c ApplicationController\n  include BlockfrostRuby::Webhooks\n\n  # You will find your webhook secret auth token in your webhook settings in the Blockfrost Dashboard\n  BLOCKFROST_SECRET_AUTH_TOKEN = \"BLOCKFROST-SECRET-AUTH-TOKEN\"\n\n  before_action :verify_request\n\n  def create\n    type = params.fetch(\"type\")\n    payload = params.fetch('payload')\n\n    case type\n    when \"transaction\"\n      # payload is an array of Transaction events\n      payload.each do |tx|\n        puts \"Transaction id: #{tx.dig 'tx', 'hash'}\",\n             \"block: #{tx.dig 'tx', 'block'} (#{tx.dig 'tx', 'block_height'})\"\n      end\n    when \"block\"\n      # process Block event\n      puts \"Received block hash #{payload['hash']}\"\n    when \"delegation\"\n      # payload is an array of objects with fields: \"tx\" (an object) and \"delegations\" (an array)\n      payload.each do |tx|\n        tx['delegations'].each do |delegation|\n          puts \"Delegation from an address #{delegation['address']} included in tx #{tx['tx']['hash']}\"\n        end\n      end\n    when \"epoch\"\n      # process Epoch event\n      puts \"Epoch switch from #{payload.dig 'previous_epoch', 'epoch'} to #{payload.dig 'current_epoch', 'epoch'}\"\n    else\n      puts \"Unexpected event type #{type}\"\n    end\n\n    head 200\n  end\n\n  private\n\n  def verify_request\n    verify_webhook_signature(\n      request.raw_post,\n      request.headers['Blockfrost-Signature'],\n      BLOCKFROST_SECRET_AUTH_TOKEN\n    )\n\n  # In case of invalid signature SignatureVerificationError will be raised\n  rescue BlockfrostRuby::Webhooks::SignatureVerificationError =\u003e e\n    puts \"Webhook signature is invalid. #{e.message}\"\n    head 403 and return\n  end\nend\n\n# That's it! Enjoy\n\n```\nAll endpoints can be found here: https://docs.blockfrost.io/\n\n## Development\n\nAfter 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.\n\nTo 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).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/blockfrost/blockfrost-ruby.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblockfrost%2Fblockfrost-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblockfrost%2Fblockfrost-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblockfrost%2Fblockfrost-ruby/lists"}