Strawberry
A simple Ruby gem acting as a client for Flavoursys Strawberry REST API.
This unofficial implementation covers most of the features offered by Strawberry API.
Installation
Add this line to your application's Gemfile:
gem 'strawberry_api'
And then execute:
$ bundle
Or install it yourself as:
$ gem install strawberry_api
Usage
Authentication
Authenticate to the server via regular credentials or by using an API key. A standard error will be raised if authentication fails.
API key based authentication
require 'strawberry_api'
StrawberryAPI.configure do |c|
c.host = 'server_IP_or_hostname'
c.api_key = 'api_key'
end
strawberry = StrawberryAPI::Client.new
# Returns currently logged in user info
strawberry.user
# => "#<Strawberry::API::User: id=2, username="api", ...
User credentials based authentication
require 'strawberry_api'
StrawberryAPI.configure do |c|
c.host = 'server_IP_or_hostname'
c.username = 'username'
c.password = 'password'
end
strawberry = StrawberryAPI::Client.new
# Returns currently logged in user info
strawberry.user
# => "#<Strawberry::API::User: id=2, username="api", ...
Making requests
Strawberry API client
API methods are available as client instance methods.
strawberry = Strawberry::Client.new
# Returns all Strawberry projects
strawberry.projects
# => [#<Strawberry::API::Project: id=6, name="test_project", ...
Samples
Most API methods return an object which provide dot notation access for fields returned in the API response.
See the samples directory for more examples.
Methods returning an object
strawberry.project(id: 6)
# => #<Strawberry::API::Project: id=6, name="test_project", ...
Methods returning an array of project objects
Some methods return an array of objects .
strawberry.projects
# => [#<Strawberry::API::Project: id=6, name="test_project", ...
Methods returning a Boolean
A few other methods return a Boolean.
The following example uses the video?
method which indicates whether the asset is a video or not.
assets = strawberry.assets
# => [#<Strawberry::API::Asset: id=6, name="test_asset", ...
assets.each do |asset|
# Returns true of false
if asset.video?
puts "Asset #{asset.name} is a video"
else
puts "Asset #{asset.name} is not a video"
end
end
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 tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/strawberry. 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.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Strawberry project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.