Class: Senec::Cloud::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/senec/cloud/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#passwordObject (readonly)

Returns the value of attribute password.



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

def password
  @password
end

#usernameObject (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

Returns:

  • (Boolean)


12
13
14
# File 'lib/senec/cloud/connection.rb', line 12

def authenticated?
  !token.nil?
end

#default_system_idObject

Raises:



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

#systemsObject



16
17
18
# File 'lib/senec/cloud/connection.rb', line 16

def systems
  get('/v1/senec/systems')
end

#tokenObject



38
39
40
# File 'lib/senec/cloud/connection.rb', line 38

def token
  @token ||= ['token']
end