By Staplegun
This gem is a wrapper around the Intervals REST API which allows you to retrieve, create, update, and delete several different resources from their database. All API requests are made with the help of the HTTParty gem.
To begin, create an instance of your specific Intervals account using the account's API token. You can learn where to find that here.
intervals = IntervalsAPI::RequestHandler.new('your_token')
Now you're free to make your requests. The structure of a request looks like:
intervals.get(resource, query_options)
Type: String
The endpoint resource you are querying
Type: Hash
Default: {}
A hash of options, such as filter options for a GET request, new object options for a POST request, etc.
Available keys (See in the examples how they're used):
query
- Query parameters that you wish to pass, typically via GET requestsbody
- Data you wish to submit, typically via POST or PUT requestsheaders
- Request headers you wish to set
View the HTTParty gem to see more options about formatting your request, and view the Intervals documentation to learn about which resources are available to request.
The response from Intervals API will contain all returned json data from Intervals in the form of a hash.
# Retrieve all clients
response = intervals.get('/client/');
# Retrieve all active clients
response = intervals.get('/client/', query: {
active: true
});
# Create a task request
intervals.post('/request/', body: {
personid: 5,
projectid: 6,
title: 'Just an average title'
})
# Update a task request
intervals.put('/request/1/', body: {
priorityid: 1,
title: "Here's an updated title"
})
# Delete a task request
intervals.delete('/request/1/')
Build a test suite to test the API. If anyone has a great way to test an authenticated third-party API, throw out some ideas.
Intervals API is licensed under the [GPL](http://www.gnu.org/licenses/gpl.html) license.