class Strife::Client

Public Class Methods

new(options = {}) click to toggle source
# File lib/strife/client.rb, line 20
def initialize(options = {})
  Strife::Configurable.keys.each do |key|
    instance_variable_set(:"@#{key}", options[key] || Strife.instance_variable_get(:"@#{key}"))
  end
end

Public Instance Methods

agent() click to toggle source
# File lib/strife/client.rb, line 47
def agent
  @agent ||= Sawyer::Agent.new("#{@api_endpoint}#{@region}/", sawyer_options) do |http|
    http.headers[:accept] = @default_media_type
    http.headers[:user_agent] = @user_agent
  end
end
get(url, options = {}) click to toggle source
# File lib/strife/client.rb, line 39
def get(url, options = {})
  request :get, url, options
end
inspect() click to toggle source

Scrub out our api key from inspect

Calls superclass method
# File lib/strife/client.rb, line 31
def inspect
  inspected = super

  inspected = inspected.gsub! @api_key, '*' * @api_key.length

  inspected
end
last_response() click to toggle source
# File lib/strife/client.rb, line 43
def last_response
  @last_response
end
same_options?(opts) click to toggle source
# File lib/strife/client.rb, line 26
def same_options?(opts)
  opts.hash == options.hash
end

Private Instance Methods

request(method, path, options) click to toggle source
# File lib/strife/client.rb, line 68
def request(method, path, options)
  options[:query] ||= {}
  options[:query].merge!(api_key: @api_key)

  @last_response = response = agent.call(method, URI.encode(path.to_s), options)
  response.data
end
sawyer_options() click to toggle source
# File lib/strife/client.rb, line 56
def sawyer_options
  opts = {
    links_parser: Sawyer::LinkParsers::Simple.new
  }

  conn_opts = @connection_options
  conn_opts[:builder] = @middleware if @middleware
  opts[:faraday] = Faraday.new(conn_opts)

  opts
end