Class: Placemaker::Client
- Inherits:
-
Object
- Object
- Placemaker::Client
- 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{|f| f.to_sym}
Instance Method Summary collapse
-
#document_length ⇒ Object
length in bytes of the document.
-
#documents ⇒ Object
Returns a collection of Placemaker::Document items as containers for content location information.
-
#fetch! ⇒ Object
Fetches the place information for input parameters from the Yahoo Placemaker service.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#processing_time ⇒ Object
time in seconds to process the document.
-
#version ⇒ Object
version of the software used to process the document.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 |
# File 'lib/placemaker/client.rb', line 8 def initialize( = {}) = [:appid] ||= ENV['PLACEMAKER_APPID'] @xml_parser = Placemaker::XmlParser.new('NODOC') verify_content_set verify_document_type_set end |
Instance Method Details
#document_length ⇒ Object
length in bytes of the document
46 47 48 |
# File 'lib/placemaker/client.rb', line 46 def document_length @xml_parser.document_length end |
#documents ⇒ Object
Returns a collection of Placemaker::Document items as containers for content location information
31 32 33 |
# File 'lib/placemaker/client.rb', line 31 def documents @xml_parser.documents end |
#fetch! ⇒ Object
Fetches the place information for input parameters from the Yahoo Placemaker service
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/placemaker/client.rb', line 19 def fetch! fields = POST_FIELDS.reject{|f| [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, [f]) end res = Curl::Easy.http_post('http://wherein.yahooapis.com/v1/document', *fields) @xml_parser = Placemaker::XmlParser.new(res.body_str) end |
#processing_time ⇒ Object
time in seconds to process the document
36 37 38 |
# File 'lib/placemaker/client.rb', line 36 def processing_time @xml_parser.processing_time end |
#version ⇒ Object
version of the software used to process the document
41 42 43 |
# File 'lib/placemaker/client.rb', line 41 def version @xml_parser.version end |