Class: Google::Directions::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/google/directions/request.rb

Constant Summary collapse

BASE_URL =
'maps.googleapis.com'
GET_PATH =
'/maps/api/directions/json'
DRIVING_MODE =
'driving'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRequest

Returns a new instance of Request.



13
14
15
16
17
# File 'lib/google/directions/request.rb', line 13

def initialize
  session.base_url        = ((sign? || private_key) ? 'https://' : 'http://') + BASE_URL
  session.timeout         = Google::Directions.config.timeout
  session.connect_timeout = Google::Directions.config.connect_timeout
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'lib/google/directions/request.rb', line 11

def params
  @params
end

#responseObject (readonly)

Returns the value of attribute response.



11
12
13
# File 'lib/google/directions/request.rb', line 11

def response
  @response
end

Instance Method Details

#get(params) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/google/directions/request.rb', line 19

def get(params)
  @params   = params.with_indifferent_access

  url = sign_url_if_needed(GET_PATH + '?' + parse_params.to_query)
  @response = session.get url

  response ? ::JSON.parse(response.body) : nil
end