deta-ruby is an unofficial Deta Gem for Ruby
Add this line to your application's Gemfile:
gem 'deta'
or grab it from Github
gem 'deta', github: "arubinofaux/deta-ruby"
And then execute:
$ bundle install
Or install it yourself as:
$ gem install deta
To access the API, you'll need to create a Deta::Client
and pass in your project key. You can find your project key at https://web.deta.sh
client = Deta::Client.new(project_key: ENV["DETA_PROJECT_KEY"])
The client then gives you access to each of the resources.
Responses are created as objects like Deta::BaseObject
. Having types like Deta::DriveObject
is handy for understanding what type of object you're working with. They're built using OpenStruct so you can easily access data in a Ruby-ish way.
detabase = client.base("base_name")
# single item
put = detabase.put({name: "Mike Jones", age: 31, hometown: "Denver"})
put.processed.items.first.key
# multi items
puts = detabase.put([{name: "Mike Jones", age: 31, hometown: "Denver"}, {name: "Mike Dow", age: 25, hometown: "Miami"}])
puts.processed
detabase.get(key)
detabase.delete(key)
detabase.insert(name: "Mike Jones", age: 31, hometown: "Denver")
# specify the key
detabase.insert(key: "ab5tsstc9bh8", name: "Mike Jones", age: 31, hometown: "Denver")
detabase.update(key, set: {hometown: "Miami"})
detabase.fetch(query: {hometown: "Denver"})
detabase.fetch(query: [{hometown: "Boulder"}, {"age?lt": 33}])
detabase.fetch(query: [{hometown: "Boulder"}], limit: 1, last: "8523bdyxlqww")
detadrive = client.drive("drive_name")
detadrive.put("test.jpg", path: "./test.jpg", content_type: "image/jpeg")
detadrive.put("test.txt", data: "hello")
detadrive.put("test.json", data: {a: 1}.to_json)
detadrive.list(limit: 1, prefix: "avatar")
detadrive.get("image0.jpg")
# single delete
detadrive.delete("image0.jpg")
# multi delete
detadrive.delete(["image1.jpg", "image2.jpg"])
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.
Bug reports and pull requests are welcome on GitHub at https://github.com/arubinofaux/deta-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Deta project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.