Gem Version Build Status Commits Since Release Maintainability Test Coverage Red The Docs SayThanks.io

Trav3

A simple abstraction layer for Travis CI API v3. The results from queries return either Success or RequestError which both repsond with Hash like query methods for the JSON data or the Net::HTTP resonse object methods.

Installation

Add this line to your application's Gemfile:

gem 'trav3'

And then execute:

$ bundle

Or install it yourself as:

$ gem install trav3

Usage

You can get started with the following.

require 'trav3'
project = Trav3::Travis.new("name/example")

When you instantiate an instance of Trav3::Travis you get some default headers and default options.

Default Options

  • limit: 25 — for limiting data queries to 25 items at most

Options can be changed via the #options getter method which will give you a Trav3::Options instance. All changes to it affect the options that the Trav3::Travis instance will submit in url requests.

Default Headers

  • 'Content-Type': 'application/json'
  • 'Accept': 'application/json'
  • 'Travis-API-Version': 3

Headers can be changed via the #headers getter method which will give you a Trav3::Headers instance. All changes to it affect the headers that the Trav3::Travis instance will submit in url requests.

API

The client has the full API implemented. Here are the methods.

#active #beta_feature #beta_features
#branch #branches #broadcasts
#build #builds #build_jobs
#caches #cron #crons
#email_resubscribe #email_unsubscribe #env_var
#env_vars #installation #job
#key_pair #key_pair_generated #lint
#log #messages #organization
#organizations #owner #preference
#preferences #repositories #repository
#request #requests #stages
#setting #settings #user

General Usage

project.owner
project.owner("owner")
project.repositories
project.repositories("owner")
project.repository
project.repository("owner/repo")
project.builds
project.build(12345)
project.build_jobs(12345)
project.job(1234)
project.log(1234)

# API Request Options
project.options.build({limit: 25})

# Pagination
builds = project.builds
builds.page.next
builds.page.first
builds.page.last

# Recommended inspection
builds.keys
builds.dig("some_key")

Follow

Each request returns a Trav3::Response type of either Trav3::Success or Trav3::RequestError. When you have an instance of Trav3::Success each response collection of either Hash or Array will be an instance of Trav3::ResponseCollection. If the #hash? method responds as true the #follow method will follow any immediate @href link provided in the collection. If #hash? produces false then the collection is an Array of items and you may use the index of the item you want to follow the @href with; like so #follow(3).

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. 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/danielpclark/trav3.

License

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