Class: SoraGeocoding::Query

Inherits:
Base
  • Object
show all
Defined in:
lib/sora_geocoding/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#configuration, #handle, #raise_error

Constructor Details

#initialize(query, options = {}) ⇒ Query

Returns a new instance of Query.



5
6
7
8
9
10
# File 'lib/sora_geocoding/query.rb', line 5

def initialize(query, options = {})
  self.query = query
  self.opts = configure(options)
  self.url = SoraGeocoding::Url.new(query)
  self.req = SoraGeocoding::Request.new
end

Instance Attribute Details

#opts ⇒ Object

Returns the value of attribute opts.



3
4
5
# File 'lib/sora_geocoding/query.rb', line 3

def opts
  @opts
end

#query ⇒ Object

Returns the value of attribute query.



3
4
5
# File 'lib/sora_geocoding/query.rb', line 3

def query
  @query
end

#req ⇒ Object

Returns the value of attribute req.



3
4
5
# File 'lib/sora_geocoding/query.rb', line 3

def req
  @req
end

#url ⇒ Object

Returns the value of attribute url.



3
4
5
# File 'lib/sora_geocoding/query.rb', line 3

def url
  @url
end

Instance Method Details

#configure(func_opts) ⇒ Object



16
17
18
# File 'lib/sora_geocoding/query.rb', line 16

def configure(func_opts)
  SoraGeocoding.configure(func_opts)
end

#execute ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sora_geocoding/query.rb', line 20

def execute
  data = req.fetch_data(url.get)
  SoraGeocoding.log(:error, "The data could not be retrieved from #{url.site}") if data.nil?

  {
    site: url.site,
    data: data.to_s
  }
rescue StandardError
  if url.site == 'yahoo'
    initialize_geocoding
    retry
  end
  SoraGeocoding.log(:warn, 'The information could not be retrieved. Please change your address.')
end

#to_s ⇒ Object



12
13
14
# File 'lib/sora_geocoding/query.rb', line 12

def to_s
  query
end