Class: Georeference::GeoLocate::Request

Inherits:
Object
  • Object
show all
Defined in:
app/models/georeference/geo_locate.rb

Constant Summary collapse

REQUEST_PARAMS =
{
  country:      nil, # name of a country 'USA', or Germany
  state:        nil, # 'IL', or 'illinois' (required in the United States)
  county:       nil, # supply as a parameter, returned as 'Adm='
  locality:     nil, # name of a place 'CHAMPAIGN' (or building, i.e. 'Eiffel Tower')
  enableH2O:    'false',
  hwyX:         'false',
  doUncert:     'true',
  doPoly:       'false',
  displacePoly: 'false',
  languageKey:  '0',
  fmt:          'json' # or geojson ?
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_params) ⇒ Request

Returns a new instance of Request.

Parameters:

  • request_params (ActionController::Parameters)


280
281
282
283
# File 'app/models/georeference/geo_locate.rb', line 280

def initialize(request_params)
  @request_params = REQUEST_PARAMS.merge(request_params)
  @succeeded      = nil
end

Instance Attribute Details

#request_param_stringObject (readonly)

Returns the value of attribute request_param_string.



277
278
279
# File 'app/models/georeference/geo_locate.rb', line 277

def request_param_string
  @request_param_string
end

#request_paramsObject (readonly)

Returns the value of attribute request_params.



277
278
279
# File 'app/models/georeference/geo_locate.rb', line 277

def request_params
  @request_params
end

#responseGeoreference::GeoLocate::Response (readonly)



307
308
309
# File 'app/models/georeference/geo_locate.rb', line 307

def response
  @response
end

#succeededObject

Returns the value of attribute succeeded.



276
277
278
# File 'app/models/georeference/geo_locate.rb', line 276

def succeeded
  @succeeded
end

Instance Method Details

#build_param_stringObject

sets the @request_param_string attribute.



291
292
293
# File 'app/models/georeference/geo_locate.rb', line 291

def build_param_string
  @request_param_string ||= @request_params.collect { |key, value| "#{key}=#{value}" }.join('&')
end

#locateObject

sets the response attribute.



286
287
288
# File 'app/models/georeference/geo_locate.rb', line 286

def locate
  @response = Georeference::GeoLocate::Response.new(self)
end

#request_stringString

Returns api request string.

Returns:

  • (String)

    api request string.



296
297
298
299
# File 'app/models/georeference/geo_locate.rb', line 296

def request_string
  build_param_string
  API_PATH + @request_param_string
end

#succeeded?Boolean

Returns true if request was successful.

Returns:

  • (Boolean)

    true if request was successful



302
303
304
# File 'app/models/georeference/geo_locate.rb', line 302

def succeeded?
  @succeeded
end