Class: OpenCalais::Client

Inherits:
Object
  • Object
show all
Includes:
Connection
Defined in:
lib/open_calais/client.rb

Constant Summary

Constants included from Connection

OpenCalais::Connection::ALLOWED_OPTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Connection

#connection, #merge_default_options

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



25
26
27
28
# File 'lib/open_calais/client.rb', line 25

def initialize(options={}, &block)
  setup(options)
  yield(self) if block_given?
end

Instance Attribute Details

#current_optionsObject

Returns the value of attribute current_options.



14
15
16
# File 'lib/open_calais/client.rb', line 14

def current_options
  @current_options
end

Instance Method Details

#analyze(text, opts = {}) ⇒ Object Also known as: enrich



39
40
41
42
43
44
45
46
47
# File 'lib/open_calais/client.rb', line 39

def analyze(text, opts={})
  raise 'Specify a value for the text' unless (text && text.length > 0)
  options = {params: current_options}.merge(opts)

  response = connection(options).post do |request|
    request.body = text
  end
  OpenCalais::Response.new(response)
end

#setup(options = {}) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/open_calais/client.rb', line 30

def setup(options={})
  opts = Hash[options.map{ |k, v| [k.to_sym, v] }]
  opts = OpenCalais.options.merge(opts)
  self.current_options = opts
  Configuration.keys.each do |key|
    send("#{key}=", opts[key])
  end
end