Skip to content

onyxmueller/pinata-ruby

Repository files navigation

Pinata Ruby

header

Gem Version GitHub license Build Status
Onyx Mueller Blog Post

The Pinata Ruby library provides convenient access to the Pinata API from applications written in the Ruby language. It includes a pre-defined set of classes for API resources that initialize themselves dynamically from API responses.

Contents

Documentation

See the Pinata API docs.

Installation

Bundler

Add this line to your application's Gemfile:

    gem 'pinata'

And then execute:

    bundle install

Gem Install

Or install with:

    gem install pinata

Requirements

  • Ruby 2.6+.

Usage

To access the API, you'll need to create a Pinata::Client and pass in your API key. You can find your API key at https://app.pinata.cloud/developers/api-keys.

    client = Pinata::Client.new(jwt_key: ENV["PINATA_JWT"])

Resources

The gem maps as closely as we can to the Pinata API so you can easily convert API examples to gem code.

Responses are created as objects like Pinata::File. They're built using OpenStruct so you can easily access data in a Ruby-ish way.

Pagination

List endpoints return pages of results. The result object will have a data key to access the results, as well as metadata like next_page_token for retrieving the next page.

results = client.files.list
#=> Pinata::Collection

results.data.size
#=> 48

results.data
#=> [#<Pinata::File>, #<Pinata::File>]

results.next_page_token
#=> "MDE5MzJjNzctMDg2Ny03ZTdhLWE2ZDEtMDRhZWRlZDNjMWI5"

# Retrieve the next page
client.files.list(pageToken: "MDE5MzJjNzctMDg2Ny03ZTdhLWE2ZDEtMDRhZWRlZDNjMWI5")
#=> Pinata::Collection

Authentication

client.authentication.test

Files

client.files.upload(file: "/path/to/file")
client.files.list
client.files.list("metadata[key]": "value")
client.files.get(file_id: "1234567890")
client.files.sign("gateway": "yourgatewaydomain", "file_cid": "thefilecid", "expires": 500000)
client.files.update(file_id: "thefilesid", "name": "thenameoffile")
client.files.delete(file_id: "1234567890")

Groups

client.groups.create({})
client.groups.get(group_id: "id")
client.groups.list
client.groups.add_file(group_id: "id", file_id: "id")
client.groups.remove_file(group_id: "id", file_id: "id")
client.groups.update(group_id: "id", {})
client.groups.delete(group_id: "id")

Development

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.

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.

Contributing

  1. Fork it ( https://github.com/onyxmueller/pinata-ruby/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Find this library useful? 🙌

Support it by joining stargazers for this repository. ⭐ And follow me for other creations.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Pinata project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

Ruby library for the Pinata API.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published