Class: Placemaker::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/placemaker/client.rb

Overview

Main interface to the Placemaker API.

Constant Summary collapse

POST_FIELDS =
%w[  appid document_content document_url document_type document_title
auto_disambiguate focus_woe_id input_language output_type         ].map(&:to_sym)

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
# File 'lib/placemaker/client.rb', line 10

def initialize(options = {})
  @options = options
  @options[:appid] ||= ENV['PLACEMAKER_APPID']
  
  @xml_parser = Placemaker::XmlParser.new('NODOC')
  
  verify_content_set
  verify_document_type_set
end

Instance Method Details

#document_lengthObject

length in bytes of the document



48
49
50
# File 'lib/placemaker/client.rb', line 48

def document_length
  @xml_parser.document_length
end

#documentsObject

Returns a collection of Placemaker::Document items as containers for content location information



33
34
35
# File 'lib/placemaker/client.rb', line 33

def documents
  @xml_parser.documents
end

#fetch!Object

Fetches the place information for input parameters from the Yahoo Placemaker service



21
22
23
24
25
26
27
28
29
30
# File 'lib/placemaker/client.rb', line 21

def fetch!
  fields = POST_FIELDS.reject{|f| @options[f].nil? }.map do |f|
    # Change ruby-form fields to url type, e.g., document_content => documentContent
    cgi_param = f.to_s.gsub(/\_(.)/) {|s| s.upcase}.gsub('_', '').sub(/url/i, 'URL')
    Curl::PostField.content(cgi_param, @options[f])
  end

  res         = Curl::Easy.http_post('http://wherein.yahooapis.com/v1/document', *fields)
  @xml_parser = Placemaker::XmlParser.new(res.body_str)
end

#processing_timeObject

time in seconds to process the document



38
39
40
# File 'lib/placemaker/client.rb', line 38

def processing_time
  @xml_parser.processing_time
end

#versionObject

version of the software used to process the document



43
44
45
# File 'lib/placemaker/client.rb', line 43

def version
  @xml_parser.version
end