Class: Code42::Connection
- Inherits:
-
Object
- Object
- Code42::Connection
- Extended by:
- Forwardable
- Defined in:
- lib/code42/connection.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#host ⇒ Object
Returns the value of attribute host.
-
#last_response ⇒ Object
Returns the value of attribute last_response.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#password ⇒ Object
Returns the value of attribute password.
-
#path_prefix ⇒ Object
Returns the value of attribute path_prefix.
-
#port ⇒ Object
Returns the value of attribute port.
-
#scheme ⇒ Object
Returns the value of attribute scheme.
-
#token ⇒ Object
Returns the value of attribute token.
-
#username ⇒ Object
Returns the value of attribute username.
-
#verify_https ⇒ Object
Returns the value of attribute verify_https.
Instance Method Summary collapse
- #delete(path, data) ⇒ Object
- #get(path, data) ⇒ Object
- #has_valid_credentials? ⇒ Boolean
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #make_request(method, *args) ⇒ Object
- #post(path, data) ⇒ Object
- #put(path, data) ⇒ Object
- #respond_to?(method_name, include_private = false) ⇒ Boolean
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/code42/connection.rb', line 11 def initialize( = {}) self.host = [:host] self.port = [:port] self.scheme = [:scheme] self.path_prefix = [:path_prefix] self.username = [:username] self.password = [:password] self.token = [:token] if [:token] self.verify_https = ![:verify_https].nil? ? [: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)
141 142 143 144 |
# File 'lib/code42/connection.rb', line 141 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
#adapter ⇒ Object
Returns the value of attribute adapter.
9 10 11 |
# File 'lib/code42/connection.rb', line 9 def adapter @adapter end |
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/code42/connection.rb', line 9 def host @host end |
#last_response ⇒ Object
Returns the value of attribute last_response.
9 10 11 |
# File 'lib/code42/connection.rb', line 9 def last_response @last_response end |
#logger ⇒ Object
Returns the value of attribute logger.
9 10 11 |
# File 'lib/code42/connection.rb', line 9 def logger @logger end |
#password ⇒ Object
Returns the value of attribute password.
9 10 11 |
# File 'lib/code42/connection.rb', line 9 def password @password end |
#path_prefix ⇒ Object
Returns the value of attribute path_prefix.
9 10 11 |
# File 'lib/code42/connection.rb', line 9 def path_prefix @path_prefix end |
#port ⇒ Object
Returns the value of attribute port.
9 10 11 |
# File 'lib/code42/connection.rb', line 9 def port @port end |
#scheme ⇒ Object
Returns the value of attribute scheme.
9 10 11 |
# File 'lib/code42/connection.rb', line 9 def scheme @scheme end |
#token ⇒ Object
Returns the value of attribute token.
9 10 11 |
# File 'lib/code42/connection.rb', line 9 def token @token end |
#username ⇒ Object
Returns the value of attribute username.
9 10 11 |
# File 'lib/code42/connection.rb', line 9 def username @username end |
#verify_https ⇒ Object
Returns the value of attribute verify_https.
9 10 11 |
# File 'lib/code42/connection.rb', line 9 def verify_https @verify_https end |
Instance Method Details
#delete(path, data) ⇒ Object
98 99 100 |
# File 'lib/code42/connection.rb', line 98 def delete(path, data) adapter.delete(path, data) end |
#get(path, data) ⇒ Object
86 87 88 |
# File 'lib/code42/connection.rb', line 86 def get(path, data) adapter.get(path, data) end |
#has_valid_credentials? ⇒ Boolean
50 51 52 |
# File 'lib/code42/connection.rb', line 50 def has_valid_credentials? username && password end |
#make_request(method, *args) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/code42/connection.rb', line 71 def make_request(method, *args) begin @last_response = response = self.send(method, *args) 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 |
#post(path, data) ⇒ Object
94 95 96 |
# File 'lib/code42/connection.rb', line 94 def post(path, data) adapter.post path, data end |
#put(path, data) ⇒ Object
90 91 92 |
# File 'lib/code42/connection.rb', line 90 def put(path, data) adapter.put path, data end |
#respond_to?(method_name, include_private = false) ⇒ Boolean
102 103 104 |
# File 'lib/code42/connection.rb', line 102 def respond_to?(method_name, include_private = false) adapter.respond_to?(method_name, include_private) || super end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
106 107 108 |
# File 'lib/code42/connection.rb', line 106 def respond_to_missing?(method_name, include_private = false) adapter.respond_to?(method_name, include_private) || super end |