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)


256
257
258
259
# File 'app/models/georeference/geo_locate.rb', line 256

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



253
254
255
# File 'app/models/georeference/geo_locate.rb', line 253

def request_param_string
  @request_param_string
end

#request_paramsObject (readonly)

Returns the value of attribute request_params



253
254
255
# File 'app/models/georeference/geo_locate.rb', line 253

def request_params
  @request_params
end

#responseGeoreference::GeoLocate::Response (readonly)



283
284
285
# File 'app/models/georeference/geo_locate.rb', line 283

def response
  @response
end

#succeededObject

Returns the value of attribute succeeded



252
253
254
# File 'app/models/georeference/geo_locate.rb', line 252

def succeeded
  @succeeded
end

Instance Method Details

#build_param_stringObject

sets the @request_param_string attribute.



267
268
269
# File 'app/models/georeference/geo_locate.rb', line 267

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

#locateObject

sets the response attribute.



262
263
264
# File 'app/models/georeference/geo_locate.rb', line 262

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

#request_stringString

Returns api request string.

Returns:

  • (String)

    api request string.



272
273
274
275
# File 'app/models/georeference/geo_locate.rb', line 272

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



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

def succeeded?
  @succeeded
end