Class: Umbreo::Models::System

Inherits:
Object
  • Object
show all
Defined in:
lib/umbreo/models/system.rb

Instance Method Summary collapse

Constructor Details

#initialize(credentials = {}) ⇒ System

Returns a new instance of System.



5
6
7
8
9
10
11
# File 'lib/umbreo/models/system.rb', line 5

def initialize(credentials = {})
	if credentials.present?
		@email    = credentials[:email]
		@api_key  = credentials[:api_key]
		@endpoint = credentials[:end_point] || SERVER_END_POINT
	end
end

Instance Method Details

#allObject

callback for retrieve data



31
32
33
34
35
36
37
38
39
# File 'lib/umbreo/models/system.rb', line 31

def all
	retrieve_data

  	if @data['systems'].present?
       Helpers::Table.show_table(@data['systems'], "List System", ['ID', 'Name'])
  	else
  		Helpers::AlertMessage.show_error_message(@data["message"])
  	end
end

#retrieve_dataObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/umbreo/models/system.rb', line 13

def retrieve_data
	Helpers::ErrorException.rescue do
		data = Typhoeus.get(
			          "#{@endpoint}/api/v1/systems",
			          body: {
			            authenticate_token: @api_key,
			            email:              @email
			          }
			        )

   	@data = JSON.parse data.response_body
   	@data['systems']
	end
end