class Goraku::Client
Public Class Methods
new(options = {})
click to toggle source
# File lib/goraku/client.rb, line 34 def initialize(options = {}) Configurable.keys.each do |key| instance_variable_set(:"@#{key}", options[key] || Goraku.instance_variable_get(:"@#{key}")) end end
Public Instance Methods
delete(path, options = {})
click to toggle source
# File lib/goraku/client.rb, line 48 def delete(path, options = {}) request :delete, path, options end
get(path, options = {})
click to toggle source
# File lib/goraku/client.rb, line 40 def get(path, options = {}) request :get, path, options end
inspect()
click to toggle source
Calls superclass method
# File lib/goraku/client.rb, line 56 def inspect inspected = super inspected.gsub! @password, "*****" if @password end
put(path, options = {})
click to toggle source
# File lib/goraku/client.rb, line 44 def put(path, options = {}) request :put, path, options end
root()
click to toggle source
# File lib/goraku/client.rb, line 52 def root get '/' end
Private Instance Methods
agent()
click to toggle source
HTTP client
@return [Sawyer::Agent]
# File lib/goraku/client.rb, line 66 def agent @agent ||= Sawyer::Agent.new(api_endpoint, sawyer_options) do |http| http.headers['content-type'] = 'application/json' if basic_authenticated? http.basic_auth(@login, @password) end end end
raise_error(code)
click to toggle source
# File lib/goraku/client.rb, line 81 def raise_error(code) case code when 400 raise Status400.new when 401 raise Status401.new when 402 raise Status402.new when 403 raise Status403.new when 404 raise Status404.new when 405 raise Status405.new when 409 raise Status409.new when 410 raise Status410.new when 415 raise Status415.new when 500 raise Status500.new when 501 raise Status501.new when 503 raise Status503.new end end
request(method, path, data, options = {})
click to toggle source
# File lib/goraku/client.rb, line 75 def request(method, path, data, options = {}) res = agent.call(method, URI::Parser.new.escape("/api#{path.to_s}"), data, options) raise_error(res.status) if @raise_error res.data end
sawyer_options()
click to toggle source
# File lib/goraku/client.rb, line 110 def sawyer_options opts = { :links_parser => Sawyer::LinkParsers::Simple.new } conn_ops = @connection_options conn_ops[:builder] = @middleware if @middleware conn_ops[:proxy] = @proxy if @proxy opts[:faraday] = Faraday.new(conn_ops) opts end