Business Insight API client gem

A gem to interact with the Business Insight API

Installation

The Business Insight API Gem is available as gem.

Add these lines to your application's Gemfile:

gem 'business_insight_api_client', '~> 0.2'

And then execute:

$ bundle

Or install it yourself as:

$ gem install business_insight_api_client

Usage

Configuration

Configure the gem for staging or the live (production) api.

Staging

The staging server can be used for testing. To access the staging server you can use the following configuration.

BusinessInsightApiClient.configure do |conf|
  conf.api_url = 'https://staging-api.nedap-bi.com'
  conf.authorization_url = 'https://staging.nedap-bi.com'
  conf.client_id = 'your_application_id'
  conf.client_secret = 'your_application_secret'
end

Production

BusinessInsightApiClient.configure do |conf|
  conf.api_url = 'https://api.nedap-bi.com'
  conf.authorization_url = 'https://nedap-bi.com'
  conf.client_id = 'your_application_id'
  conf.client_secret = 'your_application_secret'
end

Requests

Once configured, requests can be made with Client. The example chapter contains examples of how a request should be made.

Example

This section contains an example getting data in ruby (without callbacks).

Ruby

This section contains an example to query the Business Insight API from ruby. We assume you already have an application id and secret.

require 'business_insight_api_client'

BusinessInsightApiClient.configure do |conf|
  conf.api_url = 'https://staging-api.nedap-bi.com'
  conf.authorization_url = 'https://staging.nedap-bi.com'
  conf.client_id = 'your_application_id'
  conf.client_secret = 'your_application_secret'
end

client = BusinessInsightApiClient::Client.new
installation_tokens = client.get_access_tokens # queries the API for all access tokens granted to your application.
installation_tokens.each do |installation , access_token|
    puts "The access token belonging to installation #{installation} is #{access_token.token}"
    client.access_token= access_token # set the access token (installation) you would like to use to.

    installation_request = client.installations # query what installation additional information.
    puts "Installation id #{installation_request.installation.id} and serial number #{installation_request.installation.serial_number}"

    animals_request = client.animals # query all animals belonging to the installation.

    status_code = animals_request.status # => 200 , http code status
    installation_animals = animals_request.animals # => Mash containing all animals of the installation.
    installation_animals.each |animal|
          puts animal.name # iterate all animals and print their name
    end
end

BusinessInsightApiClient::Client

This is the class that should be used to make authorized calls to the Business Insight API. You can browse the classes for the operations that can be accessed.

If you need to authorize with the Business Insight authorization server you can access the Authorizations Helper from the client. BusinessInsightApiClient::Helpers::Authorization.

Documentation about the Client can be found at BusinessInsightApiClient::Client.

BusinessInsightApiClient::Helpers::Authorization

The authorizations helper contains methods to authorization with the authorization server.

Documentation about the Authorization helper can be found at BusinessInsightApiClient::Helpers::Authorization.

BusinessInsightApiClient::Errors

If a request can't be accepted the API throws errors. Detailed documentation about the errors classes can be found at BusinessInsightApiClient::Errors.