module Gemini::RestConnection
Network Layer for API Rest client
Private Instance Methods
base_api_endpoint()
click to toggle source
# File lib/gemini/connection.rb, line 46 def base_api_endpoint url = URI.parse config.api_endpoint "#{url.scheme}://#{url.host}:#{url.port}" end
build_url(url)
click to toggle source
# File lib/gemini/connection.rb, line 33 def build_url(url) URI.join(config.api_endpoint, url).path end
check_params(params, allowed_params)
click to toggle source
Make sure parameters are allowed for the HTTP call
# File lib/gemini/connection.rb, line 21 def check_params(params, allowed_params) if (params.keys - allowed_params).empty? return params else raise Gemini::ParamsError end end
get(url, params={})
click to toggle source
Make an HTTP GET request
# File lib/gemini/connection.rb, line 7 def get(url, params={}) rest_connection.get do |req| req.url build_url(url) req.headers['Content-Type'] = 'application/json' req.headers['Accept'] = 'application/json' params.each do |k,v| req.params[k] = v end req.options.timeout = config.rest_timeout req.options.open_timeout = config.rest_open_timeout end end
new_rest_connection()
click to toggle source
# File lib/gemini/connection.rb, line 37 def new_rest_connection Faraday.new(url: base_api_endpoint) do |conn| conn.use Gemini::CustomErrors conn.response :logger, Logger.new(STDOUT) , bodies: true if config.debug_connection conn.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/ conn.adapter :net_http end end
rest_connection()
click to toggle source
# File lib/gemini/connection.rb, line 29 def rest_connection @conn ||= new_rest_connection end