Class: GooglePlaces::Request
- Inherits:
-
Object
- Object
- GooglePlaces::Request
- Includes:
- HTTParty
- Defined in:
- lib/google_places/request.rb
Constant Summary
- SPOTS_LIST_URL =
'https://maps.googleapis.com/maps/api/place/search/json'- SPOT_URL =
'https://maps.googleapis.com/maps/api/place/details/json'
Instance Attribute Summary (collapse)
-
- (Object) response
Returns the value of attribute response.
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (Request) initialize(url, options)
constructor
A new instance of Request.
- - (Object) parsed_response
Constructor Details
- (Request) initialize(url, options)
A new instance of Request
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/google_places/request.rb', line 23 def initialize(url, ) = .delete(:retry_options) || {} [:status] ||= [] [:max] ||= 0 [:delay] ||= 5 [:status] = [[:status]] unless [:status].is_a?(Array) @response = self.class.get(url, :query => ) return unless [:max] > 0 && [:status].include?(@response.parsed_response['status']) retry_request = proc do for i in (1..[:max]) sleep([:delay]) @response = self.class.get(url, :query => ) break unless [:status].include?(@response.parsed_response['status']) end end if [:timeout] begin Timeout::timeout([:timeout]) do retry_request.call end rescue Timeout::Error raise RetryTimeoutError.new(@response) end else retry_request.call raise RetryError.new(@response) if [:status].include?(@response.parsed_response['status']) end end |
Instance Attribute Details
- (Object) response
Returns the value of attribute response
3 4 5 |
# File 'lib/google_places/request.rb', line 3 def response @response end |
Class Method Details
+ (Object) spot(options = {})
17 18 19 20 21 |
# File 'lib/google_places/request.rb', line 17 def self.spot( = {}) # pp options request = new(SPOT_URL, ) request.parsed_response end |
+ (Object) spots(options = {})
11 12 13 14 15 |
# File 'lib/google_places/request.rb', line 11 def self.spots( = {}) # pp options request = new(SPOTS_LIST_URL, ) request.parsed_response end |
Instance Method Details
- (Object) parsed_response
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/google_places/request.rb', line 61 def parsed_response case @response.parsed_response['status'] when 'OK', 'ZERO_RESULTS' @response.parsed_response when 'OVER_QUERY_LIMIT' raise OverQueryLimitError.new(@response) when 'REQUEST_DENIED' raise RequestDeniedError.new(@response) when 'INVALID_REQUEST' raise InvalidRequestError.new(@response) when 'UNKNOWN_ERROR' raise UnknownError.new(@response) end end |