Class: GoogleApiCustomization::Request
- Inherits:
-
Object
- Object
- GoogleApiCustomization::Request
- Includes:
- HTTParty
- Defined in:
- lib/google_api_customization/request.rb
Constant Summary collapse
- PLACES_URL =
"https://maps.googleapis.com/maps/api/place/details/json"- RADAR_SEARCH_URL =
"https://maps.googleapis.com/maps/api/place/radarsearch/json"- TEXT_SEARCH_URL =
"https://maps.googleapis.com/maps/api/place/textsearch/json"- NEARBY_SEARCH_URL =
"https://maps.googleapis.com/maps/api/place/nearbysearch/json"- PHOTO_URL =
"https://maps.googleapis.com/maps/api/place/photo"- PAGETOKEN_URL =
"https://maps.googleapis.com/maps/api/place/search/json"- AUTOCOMPLETE_URL =
"https://maps.googleapis.com/maps/api/place/autocomplete/json"
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
- .autocomplete(options = {}) ⇒ Object
- .nearby_search(options = {}) ⇒ Object
- .place(options = {}) ⇒ Object
- .text_search(options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(url, options, follow_redirects = true) ⇒ Request
constructor
A new instance of Request.
- #parsed_response ⇒ Object
Constructor Details
#initialize(url, options, follow_redirects = true) ⇒ Request
Returns a new instance of Request.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/google_api_customization/request.rb', line 44 def initialize(url, , follow_redirects = true) = .delete(:retry_options) || {} [:status] ||= [] [:max] ||= 0 [:delay] ||= 5 [:status] = [[:status]] unless [:status].is_a?(Array) @response = self.class.get(url, :query => , :follow_redirects => follow_redirects) # puts @response.request.last_uri.to_s 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 => , :follow_redirects => follow_redirects) 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
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/google_api_customization/request.rb', line 4 def @options end |
#response ⇒ Object
Returns the value of attribute response.
3 4 5 |
# File 'lib/google_api_customization/request.rb', line 3 def response @response end |
Class Method Details
.autocomplete(options = {}) ⇒ Object
39 40 41 42 |
# File 'lib/google_api_customization/request.rb', line 39 def self.autocomplete( = {}) request = new(AUTOCOMPLETE_URL, ) request.parsed_response end |
.nearby_search(options = {}) ⇒ Object
29 30 31 32 |
# File 'lib/google_api_customization/request.rb', line 29 def self.nearby_search( = {}) request = new(NEARBY_SEARCH_URL, ) request.parsed_response end |
.place(options = {}) ⇒ Object
24 25 26 27 |
# File 'lib/google_api_customization/request.rb', line 24 def self.place( = {}) request = new(PLACES_URL, ) request.parsed_response end |
.text_search(options = {}) ⇒ Object
34 35 36 37 |
# File 'lib/google_api_customization/request.rb', line 34 def self.text_search( = {}) request = new(TEXT_SEARCH_URL, ) request.parsed_response end |
Instance Method Details
#parsed_response ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/google_api_customization/request.rb', line 84 def parsed_response return @response.headers["location"] if @response.code >= 300 and @response.code < 400 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) when 'NOT_FOUND' raise NotFoundError.new(@response) end end |