Module: Yahoo::Placemaker

Defined in:
lib/yahoo/placemaker.rb,
lib/yahoo/placemaker/scope.rb,
lib/yahoo/placemaker/place.rb,
lib/yahoo/placemaker/lat_lng.rb,
lib/yahoo/placemaker/extents.rb,
lib/yahoo/placemaker/version.rb,
lib/yahoo/placemaker/ancestor.rb,
lib/yahoo/placemaker/document.rb,
lib/yahoo/placemaker/response.rb,
lib/yahoo/placemaker/reference.rb,
lib/yahoo/placemaker/exception.rb,
lib/yahoo/placemaker/local_scope.rb,
lib/yahoo/placemaker/geographic_scope.rb,
lib/yahoo/placemaker/administrative_scope.rb

Defined Under Namespace

Classes: AdministrativeScope, Ancestor, Document, Exception, Extents, GeographicScope, LatLng, LocalScope, Place, Reference, Response, Scope

Constant Summary

VERSION =
"0.0.7"

Class Method Summary (collapse)

Class Method Details

+ (Object) extract(text = '', options = {})

Main method for interacting w/ the Yahoo! Placemaker API



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/yahoo/placemaker.rb', line 13

def self.extract (text = '', options = {})

  # TODO: make sure only valid options are passed in..

  unless defined?(Yahoo::Placemaker::APP_ID)
    raise Yahoo::Placemaker::Exception.new("Invalid APP_ID")
  end

  result = nil
  host = 'wherein.yahooapis.com'

  # These options need to be explicitly set!
  options['documentContent'] = text
  options['appid'] = Yahoo::Placemaker::APP_ID
  options['outputType'] = 'json'
  options['documentType'] = 'text/plain'

  req = ::Net::HTTP::Post.new('/v1/document')
  req.body = to_url_params(options)
  begin
    response = ::Net::HTTP.new(host).start do |http|
      http.request(req)
    end
    json = ::JSON.parse(response.body)

    result = Yahoo::Placemaker::Response.new(json)
  rescue Exception => e
   # puts e
    # Something has gone horribly wrong...
  end

  result

end