Class: Code42::Connection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/code42/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Connection

Returns a new instance of Connection.



12
13
14
15
16
17
18
19
20
21
# File 'lib/code42/connection.rb', line 12

def initialize(options = {})
  self.host         = options[:host]
  self.port         = options[:port]
  self.scheme       = options[:scheme]
  self.path_prefix  = options[:path_prefix]
  self.username     = options[:username]
  self.password     = options[:password]
  self.token        = options[:token] if options[:token]
  self.verify_https = !options[:verify_https].nil? ? options[:verify_https] : true
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)



133
134
135
136
# File 'lib/code42/connection.rb', line 133

def method_missing(method_name, *args, &block)
  return super unless adapter.respond_to?(method_name)
  adapter.send(method_name, *args, &block)
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



10
11
12
# File 'lib/code42/connection.rb', line 10

def adapter
  @adapter
end

#hostObject

Returns the value of attribute host.



10
11
12
# File 'lib/code42/connection.rb', line 10

def host
  @host
end

#last_responseObject

Returns the value of attribute last_response.



10
11
12
# File 'lib/code42/connection.rb', line 10

def last_response
  @last_response
end

#loggerObject

Returns the value of attribute logger.



10
11
12
# File 'lib/code42/connection.rb', line 10

def logger
  @logger
end

#mlkObject

Returns the value of attribute mlk.



10
11
12
# File 'lib/code42/connection.rb', line 10

def mlk
  @mlk
end

#passwordObject

Returns the value of attribute password.



10
11
12
# File 'lib/code42/connection.rb', line 10

def password
  @password
end

#path_prefixObject

Returns the value of attribute path_prefix.



10
11
12
# File 'lib/code42/connection.rb', line 10

def path_prefix
  @path_prefix
end

#portObject

Returns the value of attribute port.



10
11
12
# File 'lib/code42/connection.rb', line 10

def port
  @port
end

#schemeObject

Returns the value of attribute scheme.



10
11
12
# File 'lib/code42/connection.rb', line 10

def scheme
  @scheme
end

#tokenObject

Returns the value of attribute token.



10
11
12
# File 'lib/code42/connection.rb', line 10

def token
  @token
end

#usernameObject

Returns the value of attribute username.



10
11
12
# File 'lib/code42/connection.rb', line 10

def username
  @username
end

#verify_httpsObject

Returns the value of attribute verify_https.



10
11
12
# File 'lib/code42/connection.rb', line 10

def verify_https
  @verify_https
end

Instance Method Details

#has_valid_credentials?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/code42/connection.rb', line 56

def has_valid_credentials?
  username && password
end

#make_request(method, *args, &block) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/code42/connection.rb', line 83

def make_request(method, *args, &block)
  begin
    @last_response = response = self.send(method, *args, &block)
    ActiveSupport::Notifications.instrument('code42.request', {
      method:   method,
      args:     args,
      response: response
    })
  rescue Faraday::Error::ConnectionFailed
    raise Code42::Error::ConnectionFailed
  end
  check_for_errors(response)
  response.body
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/code42/connection.rb', line 98

def respond_to_missing?(method_name, include_private = false)
  adapter.respond_to?(method_name, include_private) || super
end