Class: Spektrix::Configuration
- Inherits:
-
Object
- Object
- Spektrix::Configuration
- Defined in:
- lib/spektrix.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_path ⇒ Object
Returns the value of attribute api_path.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#client_cert_path ⇒ Object
Returns the value of attribute client_cert_path.
-
#client_key_path ⇒ Object
Returns the value of attribute client_key_path.
-
#client_name ⇒ Object
Returns the value of attribute client_name.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#ssl_options ⇒ Object
readonly
Returns the value of attribute ssl_options.
Instance Method Summary collapse
- #configure_connection ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#to_hash ⇒ Hash
Return the Configuration object as a hash, with symbols as keys.
- #user_agent=(agent) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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_key ⇒ Object
Returns the value of attribute api_key.
21 22 23 |
# File 'lib/spektrix.rb', line 21 def api_key @api_key end |
#api_path ⇒ Object
Returns the value of attribute api_path.
21 22 23 |
# File 'lib/spektrix.rb', line 21 def api_path @api_path end |
#base_url ⇒ Object
Returns the value of attribute base_url.
21 22 23 |
# File 'lib/spektrix.rb', line 21 def base_url @base_url end |
#client_cert_path ⇒ Object
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_path ⇒ Object
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_name ⇒ Object
Returns the value of attribute client_name.
21 22 23 |
# File 'lib/spektrix.rb', line 21 def client_name @client_name end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
30 31 32 |
# File 'lib/spektrix.rb', line 30 def connection @connection end |
#logger ⇒ Object
Returns the value of attribute logger.
21 22 23 |
# File 'lib/spektrix.rb', line 21 def logger @logger end |
#proxy ⇒ Object
Returns the value of attribute proxy.
21 22 23 |
# File 'lib/spektrix.rb', line 21 def proxy @proxy end |
#ssl_options ⇒ Object (readonly)
Returns the value of attribute ssl_options.
30 31 32 |
# File 'lib/spektrix.rb', line 30 def end |
Instance Method Details
#configure_connection ⇒ Object
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" = { :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: , 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 ⇒ Hash
Return the Configuration object as a hash, with symbols as keys.
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 |