Gladius is a zero-setup tool for accessing JSONAPI Resources.
agent = Gladius::Agent.new("http://jsonapi-example.com/posts")
post = agent.index[0]
print post
Posts: 0223c8ea-0c31-4901-b20e-99123b408e08
author_id: 80013143-e3fe-435e-8d86-b3da896625fa
name: Great Post
post_type: blog
#<Gladius::Resource:0x007f83a98fefb0>=> nil
post.name = "Even Better"
updated_post = post.save!
print updated_post
Posts: 0223c8ea-0c31-4901-b20e-99123b408e08
author_id: 80013143-e3fe-435e-8d86-b3da896625fa
name: Even Better
post_type: blog
#<Gladius::Resource:0x007f83a8bea6f8>=> nilAdd this line to your application's Gemfile:
gem 'gladius'And then execute:
$ bundle
Or install it yourself as:
$ gem install gladius
First start up a Gladius::Agent with a root resource URI:
agent = Gladius::Agent.new("https://jsonapi-example.org/users")#indexreturnsResource-wrapped resuls fromGET.#get(id)makes aGETcall to the member(id) path of the base.#new(attributes)creates a newResource.
When you have a Resource:
#<attribute>: Returns value of attribute#<attribute>=: Sets the value#save!: Create or Update the resource#to_s: Pretty print the resource
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 tags, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/Carl Thuringer/gladius. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the Apache-2.0 License.