class Spektrix::Configuration

Attributes

api_key[RW]
api_path[RW]
base_url[RW]
client_cert_path[RW]
client_key_path[RW]
client_name[RW]
connection[R]
logger[RW]
proxy[RW]
ssl_options[R]

Public Class Methods

new() click to toggle source
# File lib/spektrix.rb, line 33
def initialize
  @connection ||= Her::API.new
  @user_agent = "Spektrix Ruby client #{Spektrix::VERSION} (http://github.com/errorstudio/spektrix-ruby)",
  @base_url = "https://api.system.spektrix.com"
  @api_path = "api/v2"
end

Public Instance Methods

configure_connection() click to toggle source
# File lib/spektrix.rb, line 50
def configure_connection
  if @client_name.nil? || @client_key_path.nil? || @client_cert_path.nil? || @api_key.nil?
    raise ArgumentError, "You need to configure the Spektrix gem with a client name, private and public keys before making a call to Spektrix"
  end

  @connection_path = "#{@base_url}/#{@client_name}/#{@api_path}"
  # @connection_path = "http://localhost:8000"
  @ssl_options = {
    :client_cert => OpenSSL::X509::Certificate.new(File.read(@client_cert_path)),
    :client_key => OpenSSL::PKey::RSA.new(File.read(@client_key_path)),
    :verify => false
  }


  @connection.setup url: @connection_path, ssl: @ssl_options, proxy: @proxy do |c|

    if @logger
      #Connection Debugging
      c.use Spektrix::DebugMiddleware, @logger
    end


    #Api Auth
    c.params[:api_key] = @api_key

    # Request
    c.use Faraday::Request::UrlEncoded

    # Response
    # c.use Spektrix::DebugMiddleware
    c.use Spektrix::ResponseParser


    # Adapter
    c.use Faraday::Adapter::NetHttp
  end
end
to_hash() click to toggle source

Return the Configuration object as a hash, with symbols as keys. @return [Hash]

# File lib/spektrix.rb, line 46
def to_hash
  Hash[instance_variables.map { |name| [name.to_s.gsub("@","").to_sym, instance_variable_get(name)] } ]
end
user_agent=(agent) click to toggle source
# File lib/spektrix.rb, line 40
def user_agent=(agent)
  @user_agent = agent || @user_agent
end