class Placemaker::Client

Main interface to the Placemaker API.

Constants

POST_FIELDS

Public Class Methods

new(options = {}) click to toggle source
   # File lib/placemaker/client.rb
10 def initialize(options = {})
11   @options = options
12   @options[:appid] ||= ENV['PLACEMAKER_APPID']
13   
14   @xml_parser = Placemaker::XmlParser.new('NODOC')
15   
16   verify_content_set
17   verify_document_type_set
18 end

Public Instance Methods

document_length() click to toggle source

length in bytes of the document

   # File lib/placemaker/client.rb
48 def document_length
49   @xml_parser.document_length
50 end
documents() click to toggle source

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

   # File lib/placemaker/client.rb
33 def documents
34   @xml_parser.documents
35 end
fetch!() click to toggle source

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

   # File lib/placemaker/client.rb
21 def fetch!
22   fields = POST_FIELDS.reject{|f| @options[f].nil? }.map do |f|
23     # Change ruby-form fields to url type, e.g., document_content => documentContent
24     cgi_param = f.to_s.gsub(/\_(.)/) {|s| s.upcase}.gsub('_', '').sub(/url/i, 'URL')
25     Curl::PostField.content(cgi_param, @options[f])
26   end
27 
28   res         = Curl::Easy.http_post('http://wherein.yahooapis.com/v1/document', *fields)
29   @xml_parser = Placemaker::XmlParser.new(res.body_str)
30 end
processing_time() click to toggle source

time in seconds to process the document

   # File lib/placemaker/client.rb
38 def processing_time
39   @xml_parser.processing_time
40 end
version() click to toggle source

version of the software used to process the document

   # File lib/placemaker/client.rb
43 def version
44   @xml_parser.version
45 end

Private Instance Methods

verify_content_set() click to toggle source
   # File lib/placemaker/client.rb
71 def verify_content_set 
72   raise ArgumentError, "Either document_url or document_content must be set" if (@options[:document_content].nil? && @options[:document_url].nil?)
73 end
verify_document_type_set() click to toggle source
   # File lib/placemaker/client.rb
61 def verify_document_type_set
62   valid_types = %w[
63     text/plain
64     text/html text/xml text/rss 
65     application/xml application/rss+xml
66   ]
67 
68   raise ArgumentError, "Document type must be in #{valid_types.join(', ')}" unless valid_types.include?(@options[:document_type]) 
69 end