Class: WatsonAPIClient

Inherits:
Object
  • Object
show all
Defined in:
lib/watson-api-client.rb

Direct Known Subclasses

Alchemy

Defined Under Namespace

Classes: Alchemy

Constant Summary collapse

VERSION =
'0.0.6'
Gateways =
{
  :gateway   => api_docs.delete(:gateway),
  :gateway_a => api_docs.delete(:gateway_a)
}
Options =
api_docs
Services =
JSON.parse(ENV['VCAP_SERVICES'] || '{}')
DefaultParams =
{:user=>'username', :password=>'password'}
AvailableAPIs =
[]

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ WatsonAPIClient

Note:

VCAP_SERVICES is IBM Bluemix™ environment variable.

All subclass constructors use following hash parameter -

Parameters:

  • options (Hash) (defaults to: {})

    See following..

Options Hash (options):

  • :url (String)

    API URL (default: the url described in listings or VCAP_SERVICES)

  • :user (String)

    USER ID (default: the username described in VCAP_SERVICES)

  • :password (String)

    USER Password (default: the password described in VCAP_SERVICES)

  • :apikey (String)

    or :api_key API key for the Alchemy API (default: the apikey or api_key described in VCAP_SERVICES)

  • :version (String)

    The release date of the version of the Alchemy API.

  • other_options (Object)

    Other options are passed to RestClient::Resource.new as it is.



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/watson-api-client.rb', line 142

def initialize(options={})
  define_api_methods
  set_variables(options)
  @url   ||= Gateways[:gateway] + self.class::API['apis']['basePath']
  @options = {}
  self.class.superclass::DefaultParams.each_pair do |sym, key|
    @options[sym] = @credential[key] if @credential.key?(key)
  end
  @options.update(options)
  @service = RestClient::Resource.new(@url, @options)
end