class EarthTools::Lookup::Base

Base lookup object.

Public Instance Methods

Private Instance Methods

base_service_url() click to toggle source

The base URL for the web service endpoint (protocol and server). @return [String] the base URL

# File lib/earth_tools/lookup/base.rb, line 41
def base_service_url
  "http://www.earthtools.org"
end
cache() click to toggle source

Gets the cache. @return [EarthTools::Cache] the cache

# File lib/earth_tools/lookup/base.rb, line 48
def cache
  EarthTools::Configuration.cache
end
parse_xml(raw_xml) click to toggle source

Handle XML results by validating them. @param raw_xml the xml to parse @return [Height, SunriseSunset, TimeZone] the result

# File lib/earth_tools/lookup/base.rb, line 64
def parse_xml(raw_xml)
  xml = XmlSimple.xml_in( raw_xml, { 'ForceArray' => false } )
  if xml['location']
    result_class.new(xml)
  else
    warn "Invalid request."
  end
end
query(*options) click to toggle source

URL to use for querying the geocoding engine. @return [String] the url

# File lib/earth_tools/lookup/base.rb, line 55
def query(*options)
  base_service_url + query_base + options.join('/')
  # ([base_service_url, query_base] + options).join('/')
end
query_base() click to toggle source

The base of the query for the function. @return [String] the base of the query @throws NotImplementedError when child class does not implement method

# File lib/earth_tools/lookup/base.rb, line 93
def query_base
  raise NotImplementedError
end
raise_error(error, message = nil) click to toggle source

Raise exception if configuration specifies it should be raised. @return [boolean] false, if exception not raised

# File lib/earth_tools/lookup/base.rb, line 84
def raise_error(error, message = nil)
  raise error, message if EarthTools::Configuration.always_raise.include?( error.is_a?(Class) ? error : error.class )
  false
end
result_class() click to toggle source

The class for the result. @return [EarthTools::Result::Height, EarthTools::Result::SunriseSunset, EarthTools::Result::TimeZone] the result class

# File lib/earth_tools/lookup/base.rb, line 100
def result_class
  EarthTools::Result.const_get(self.class.to_s.split(":").last)
end
retrieve(query) click to toggle source

Handles running query. @return [xml] the results

# File lib/earth_tools/lookup/base.rb, line 76
def retrieve(query)
  RestClient.proxy = EarthTools::Configuration.proxy if EarthTools::Configuration.proxy
  RestClient.get query
end