Class: Senec::Cloud::Connection
- Inherits:
-
Object
- Object
- Senec::Cloud::Connection
- Defined in:
- lib/senec/cloud/connection.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #authenticated? ⇒ Boolean
- #default_system_id ⇒ Object
- #get(path, params: nil) ⇒ Object
-
#initialize(username:, password:, token: nil) ⇒ Connection
constructor
A new instance of Connection.
- #post(path, data) ⇒ Object
- #systems ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(username:, password:, token: nil) ⇒ Connection
Returns a new instance of Connection.
4 5 6 7 8 |
# File 'lib/senec/cloud/connection.rb', line 4 def initialize(username:, password:, token: nil) @username = username @password = password @token = token end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
10 11 12 |
# File 'lib/senec/cloud/connection.rb', line 10 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
10 11 12 |
# File 'lib/senec/cloud/connection.rb', line 10 def username @username end |
Instance Method Details
#authenticated? ⇒ Boolean
12 13 14 |
# File 'lib/senec/cloud/connection.rb', line 12 def authenticated? !token.nil? end |
#default_system_id ⇒ Object
20 21 22 23 24 |
# File 'lib/senec/cloud/connection.rb', line 20 def default_system_id raise Error.new('No systems found!', :not_found) if systems.nil? systems[0]['id'] end |
#get(path, params: nil) ⇒ Object
26 27 28 29 30 |
# File 'lib/senec/cloud/connection.rb', line 26 def get(path, params: nil) return_body do connection.get(path, params, { authorization: token }) end end |
#post(path, data) ⇒ Object
32 33 34 35 36 |
# File 'lib/senec/cloud/connection.rb', line 32 def post(path, data) return_body do connection.post(path, data) end end |
#systems ⇒ Object
16 17 18 |
# File 'lib/senec/cloud/connection.rb', line 16 def systems get('/v1/senec/systems') end |
#token ⇒ Object
38 39 40 |
# File 'lib/senec/cloud/connection.rb', line 38 def token @token ||= login['token'] end |