Sha256: 10ed560a80d29303d84adfac08214c8ba41f15a675ee519d0fb08fc1e2e588ee

Contents?: true

Size: 711 Bytes

Versions: 6

Compression:

Stored size: 711 Bytes

Contents

module Gmaps4rails
  
  module BaseNetMethods

    def checked_google_response(&block)
      raise_net_status unless valid_response?
  
      raise_query_error unless valid_parsed_response?
  
      yield
    end

    def base_url
      URI.escape base_request
    end

    def response
      @response ||= get_response
    end

    def valid_response?
      response.is_a?(Net::HTTPSuccess)
    end

    def valid_parsed_response?
      parsed_response["status"] == "OK"
    end

    def parsed_response
      @parsed_response ||= JSON.parse(response.body)
    end
    
    def get_response
      url = URI.parse(base_url)
      http = Gmaps4rails.http_agent
      http.get_response(url)
    end
    
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gmaps4rails-1.5.7 lib/gmaps4rails/api_wrappers/base_net_methods.rb
gmaps4rails-2.0.0.pre lib/gmaps4rails/api_wrappers/base_net_methods.rb
gmaps4rails-1.5.6 lib/gmaps4rails/api_wrappers/base_net_methods.rb
gmaps4rails-1.5.5 lib/gmaps4rails/api_wrappers/base_net_methods.rb
gmaps4rails-1.5.4 lib/gmaps4rails/api_wrappers/base_net_methods.rb
gmaps4rails-1.5.3 lib/gmaps4rails/api_wrappers/base_net_methods.rb