class Rome2rio::Connection
Public Class Methods
new(opts = {})
click to toggle source
# File lib/rome2rio/connection.rb, line 3 def initialize(opts = {}) @apikey = opts[:apikey] @endpoint = opts[:endpoint] || "http://free.rome2rio.com" end
Public Instance Methods
encode_params(params)
click to toggle source
# File lib/rome2rio/connection.rb, line 16 def encode_params(params) URI.encode_www_form(params) end
handle_response(response)
click to toggle source
# File lib/rome2rio/connection.rb, line 8 def handle_response(response) if response.status == 200 SearchResponse.new(MultiJson.decode(response.body)) else {:status => response.status, :body => response.body} end end
search(opts)
click to toggle source
# File lib/rome2rio/connection.rb, line 20 def search(opts) opts[:key] ||= @apikey if @apikey # format SearchFlags flags = opts[:flags] opts[:flags] = SearchRequestFlags.new(flags) if flags.is_a?(Symbol) or flags.is_a?(Array) request = "/api/1.2/json/Search?#{encode_params(opts)}" handle_response(Faraday.new(:url => @endpoint).get(request)) # handle_response(conn.get do |req| # req.headers['Content-Type'] = 'application/json' # req.url request_url # end) end