Coupakit

Build Status

DISCLAIMER: Coupakit is still under heavy development! The API may change at any moment! Use at your own risk!

Under construction!

Coupakit is a Ruby API-wrapper for the Coupa REST API. Coupakit allows you to easily write code to access the Coupa REST API without having to worry about constructing queries, sending requests, and parsing responses yourself. Additionally, Coupakit provides a natural query interface that makes constructing more complex queries easier and less painful.

Installation

Currently Coupakit is not available on Rubygems.

If you are using Bundler, you can bundle the master branch from GitHub:

gem "coupakit", :github => "aergonaut/coupakit", :branch => "master"

Or any of the currently tagged versions:

gem "coupakit", :github => "aergonaut/coupakit", :tag => "v0.0.1"

If you are not using Bundler, you can also download and install Coupakit to your system by running rake install from the project root.

JSON library

Coupakit uses MultiJSON to allow you to choose your own JSON backend. If you are already using one of the JSON libraries that MultiJSON supports, Coupakit will use that one too. If you don't already have a JSON library added to your project, we suggest that you do add one, such as Oj.

Usage

For complete details, see the documentation.

API methods are available both as module-level functions and instance functions on authenticated clients.

Module usage:

Coupakit.configure do |config|
  config.instance_url = "https://widgetco.coupahost.com"
  config.api_key = "0123456789abcdef"
end

orders = Coupakit.purchase_orders :exported => false, :created_at => ["2011-01-01", "2011-02-01"]

With a client object:

client = Coupakit::Client.new :instance_url => "https://widgetco.coupahost.com", :api_key => "0123456789abcdef"

orders = client.purchase_orders :exported => false, :created_at => ["2011-01-01", "2011-02-01"]

Querying records

If you know a record's ID, you can retrieve it directly.

client.purchase_orders 25

Otherwsie, you can perform a search by passing a hash of query parameters instead

client.purchase_orders :exported => false

In addition to simple equality, you can specify inclusion in a range by passing an array. This has the same semantics as ranges with two dots: the beginning is included but the end is excluded.

client.purchase_orders :exported => false, :created_at => ["2011-01-01", "2011-02-01"]

Other operators are supported by passing another hash as the value, with the operator as a key and the argument as a value.

client.purchase_orders :exported => false, :created_at => { :gt => "2011-01-01" }

Supported operators include:

  • :gt
  • :gte
  • :lt
  • :lte
  • :starts_with
  • :ends_with
  • :contains
  • :not_eq
  • :blank - only accepts true or false

To query properties of associated objects, specify these as sub-hashes:

client.order_lines :account => { :code => "0010" }

Creating and modifying records

To update a record, use any of the update_* methods along with the object's ID and a hash of attributes to update.

client.update_purchase_order 25, :exported => true

Creating records can be done through the create_* methods. The new record's attributes should be specified in a hash.

client.create_item {
  :active => true, 
  :description => "Example API Item",
  :item_number => "1101",
  :name => "Example API Item",
  :commodity => {
    :name => "IT"
  },
  :uom => {
    :code => "EA"
  }
}

Contributing

Coupakit is hosted on GitHub.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Running and writing tests

Run the test suite by executing bundle exec rake test.

Coupakit uses VCR for recording and playing back API fixtures during test runs. API fixtures are stored in the spec/cassettes folder in the project.

The tests rely upon an instance URL stored in ENV["COUPAKIT_TEST_INSTANCE_URL"] and an API key stored in ENV["COUPAKIT_TEST_API_KEY"]. If you're not recording new fixtures, you don't need to have these set. If you are, these can point to any reachable Coupa instance; they will be blacked out before the cassette is saved.

Supported Ruby Versions

This library aims to support and is tested against the following Ruby implementations:

  • MRI 1.9.3
  • MRI 2.0.0

If something doesn't work on one of these Ruby versions, it's a bug.

This library may inadvertently work (or seem to work) on other Ruby implementations, however support will only be provided for the versions listed above.

Versioning

This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, that version should be immediately yanked and/or a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions. As a result of this policy, you can (and should) specify a dependency on this gem using the Pessimistic Version Constraint with two digits of precision. For example:

spec.add_dependency 'coupakit', '~> 2.0'

License

The MIT License (MIT)

Copyright (c) 2013 Chris Fung

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.