Class: Spektrix::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/spektrix.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



33
34
35
36
37
38
# 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

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



21
22
23
# File 'lib/spektrix.rb', line 21

def api_key
  @api_key
end

#api_pathObject

Returns the value of attribute api_path.



21
22
23
# File 'lib/spektrix.rb', line 21

def api_path
  @api_path
end

#base_urlObject

Returns the value of attribute base_url.



21
22
23
# File 'lib/spektrix.rb', line 21

def base_url
  @base_url
end

#client_cert_pathObject

Returns the value of attribute client_cert_path.



21
22
23
# File 'lib/spektrix.rb', line 21

def client_cert_path
  @client_cert_path
end

#client_key_pathObject

Returns the value of attribute client_key_path.



21
22
23
# File 'lib/spektrix.rb', line 21

def client_key_path
  @client_key_path
end

#client_nameObject

Returns the value of attribute client_name.



21
22
23
# File 'lib/spektrix.rb', line 21

def client_name
  @client_name
end

#connectionObject (readonly)

Returns the value of attribute connection.



30
31
32
# File 'lib/spektrix.rb', line 30

def connection
  @connection
end

#loggerObject

Returns the value of attribute logger.



21
22
23
# File 'lib/spektrix.rb', line 21

def logger
  @logger
end

#proxyObject

Returns the value of attribute proxy.



21
22
23
# File 'lib/spektrix.rb', line 21

def proxy
  @proxy
end

#ssl_optionsObject (readonly)

Returns the value of attribute ssl_options.



30
31
32
# File 'lib/spektrix.rb', line 30

def ssl_options
  @ssl_options
end

Instance Method Details

#configure_connectionObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 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_hashHash

Return the Configuration object as a hash, with symbols as keys.

Returns:



46
47
48
# 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) ⇒ Object



40
41
42
# File 'lib/spektrix.rb', line 40

def user_agent=(agent)
  @user_agent = agent || @user_agent
end