Class: LocationQuery

Inherits:
Base
  • Object
show all
Defined in:
lib/globe_connect/location_query.rb

Constant Summary collapse

LOCATION_URL =
'https://devapi.globelabs.com.ph/location/v1/queries/location?access_token=%s&address=%s&requestedAccuracy=%s'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#send_get_request, #send_post_request

Constructor Details

#initialize(access_token) ⇒ Object

Starts up whenever the class is being called.

Parameters:

  • string

    access_token



11
12
13
# File 'lib/globe_connect/location_query.rb', line 11

def initialize(access_token)
  @access_token = access_token
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



5
6
7
# File 'lib/globe_connect/location_query.rb', line 5

def access_token
  @access_token
end

Instance Method Details

#get_location(address, accuracy = 10) ⇒ Object

Fetches the geolocation of a given address.

Parameters:

  • string

    address

  • int

    accuracy

Returns:

  • json



20
21
22
23
24
25
26
27
28
# File 'lib/globe_connect/location_query.rb', line 20

def get_location(address, accuracy = 10)
  # prepare the request url
  url = sprintf(LOCATION_URL, @access_token, address, accuracy)

  # set get request
  response = send_get_request(url)

  return JSON.parse(response)
end