Project

zesty

0.0
No release in over a year
A Ruby interface to the Zesty.io API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 4.0
 Project Readme

The Zesty.io Ruby Gem

Gem Version CI Build

A Ruby interface to the Zesty REST API. Requires Ruby 2.5 and up. Not all API actions are supported yet. Since the Zesty API uses mostly camelCase, this gem will handle converting to and from snake_case for you.

Installation

Add the following to your application's Gemfile:

gem 'zesty'

Or install directly with gem install zesty.

To try out the gem, just follow the Development section instructions as the bin/setup script will direct you on how to provide the necessary API info to get started.

Usage

Client Configuration

Request a valid token by logging in.

token = Zesty::Auth.get_token("email", "password")

Then initialize a client with that token and an instance zuid.

client = Zesty::Client.new(token, "instance_zuid")

Making Requests

Make an API request with a payload in the structure documented by the Zesty REST API but using snake_case. The request payload will be converted to camelCase for you.

head_tag = client.create_head_tag(
  resource_zuid: "instance_zuid",
  type: "link",
  attributes: {
    rel: :icon,
    href: "favicon.ico",
    "data-manual": true
  },
  sort: 1
)

So in the example above, resource_zuid gets converted to resourceZUID in the request payload.

Handling Responses

Response data is in snake_case form as it converted automatically from camelCase. This includes nested objects as shown below:

head_tag = client.get_head_tag("zuid")
pp head_tag
# {:_meta=>
#   {:timestamp=>"2019-09-24T16:39:30.571076035Z",
#    :total_results=>1,
#    :start=>0,
#    :offset=>0,
#    :limit=>1},
#  :data=>
#   {:zuid=>"zuid",
#    :type=>"link",
#    :attributes=>
#     {:"data-manual"=>true,
#      :href=>"favicon-64.png",
#      :rel=>"icon",
#      :type=>"image/png"},
#    :resource_zuid=>"resource_zuid",
#    :sort=>1,
#    :created_by_user_zuid=>"created_by_user_zuid",
#    :updated_by_user_zuid=>"created_by_user_zuid",
#    :created_at=>"2019-09-24T16:39:30.561203655Z",
#    :updated_at=>"2019-09-24T16:39:30.561210119Z"}}

Development

  1. git clone https://github.com/jackpocket/zesty-rb.git

  2. Run ./bin/setup to install dependencies and fill out API info

  3. Run ./bin/console for an interactive prompt with an authenticated client for you to experiment:

    instance = client.get_instance
    instance[:data][:name]
    # => My Test Instance

All code is written in snake_case since requests and responses are converted to and from camelCase for you.

Tests

To run tests use rspec. To re-record VCR cassettes use RECORD_MODE=all rspec or with specific test cases.

Releasing

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/jackpocket/zesty-rb. 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 Zesty project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.