Class: ResinIO::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/resinio/device.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Device

Returns a new instance of Device.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/resinio/device.rb', line 11

def initialize(attributes)
  @id = attributes['id']
  @uuid = attributes['uuid']
  @device_name = attributes['device_name']
  @device_type = attributes['device_type']
  @is_online = attributes['is_online']
  @status = attributes['status']
  @os_variant = attributes['os_variant']
  @location = attributes['location']
  @commit = attributes['is_on__commit']
  @os_version = attributes['os_version']
  @supervisor_version = attributes['supervisor_version']
  @longitude = attributes['longitude']
  @latitude = attributes['latitude']
  @app_id = attributes['belongs_to__application']['__id']
  @last_connectivity_event = Time.parse(attributes['last_connectivity_event'])
  @ip_address = attributes['ip_address'].split(" ")
end

Instance Attribute Details

#app_idObject (readonly)

Returns the value of attribute app_id.



7
8
9
# File 'lib/resinio/device.rb', line 7

def app_id
  @app_id
end

#commitObject (readonly)

Returns the value of attribute commit.



7
8
9
# File 'lib/resinio/device.rb', line 7

def commit
  @commit
end

#device_nameObject (readonly)

Returns the value of attribute device_name.



7
8
9
# File 'lib/resinio/device.rb', line 7

def device_name
  @device_name
end

#device_typeObject (readonly)

Returns the value of attribute device_type.



7
8
9
# File 'lib/resinio/device.rb', line 7

def device_type
  @device_type
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/resinio/device.rb', line 7

def id
  @id
end

#ip_addressObject (readonly)

Returns the value of attribute ip_address.



7
8
9
# File 'lib/resinio/device.rb', line 7

def ip_address
  @ip_address
end

#is_onlineObject (readonly)

Returns the value of attribute is_online.



7
8
9
# File 'lib/resinio/device.rb', line 7

def is_online
  @is_online
end

#last_connectivity_eventObject (readonly)

Returns the value of attribute last_connectivity_event.



7
8
9
# File 'lib/resinio/device.rb', line 7

def last_connectivity_event
  @last_connectivity_event
end

#latitudeObject (readonly)

Returns the value of attribute latitude.



7
8
9
# File 'lib/resinio/device.rb', line 7

def latitude
  @latitude
end

#locationObject (readonly)

Returns the value of attribute location.



7
8
9
# File 'lib/resinio/device.rb', line 7

def location
  @location
end

#longitudeObject (readonly)

Returns the value of attribute longitude.



7
8
9
# File 'lib/resinio/device.rb', line 7

def longitude
  @longitude
end

#os_variantObject (readonly)

Returns the value of attribute os_variant.



7
8
9
# File 'lib/resinio/device.rb', line 7

def os_variant
  @os_variant
end

#os_versionObject (readonly)

Returns the value of attribute os_version.



7
8
9
# File 'lib/resinio/device.rb', line 7

def os_version
  @os_version
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/resinio/device.rb', line 7

def status
  @status
end

#supervisor_versionObject (readonly)

Returns the value of attribute supervisor_version.



7
8
9
# File 'lib/resinio/device.rb', line 7

def supervisor_version
  @supervisor_version
end

#uuidObject (readonly)

Returns the value of attribute uuid.



7
8
9
# File 'lib/resinio/device.rb', line 7

def uuid
  @uuid
end

Class Method Details

.allObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/resinio/device.rb', line 45

def self.all
  conn = Faraday.new(url: "#{API_URL}/device") do |faraday|
    faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
    faraday.headers['Content-Type'] = 'application/json' # form-encode POST params
    faraday.headers['Authorization'] = "Bearer #{ENV['RESIN_API_KEY']}" # form-encode POST params
  end
  response = conn.get
  parsed_response = JSON.parse(response.body)
  devices = parsed_response['d']
  result = devices.map { |device| new(device) }
  # byebug
end

.find(id) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/resinio/device.rb', line 30

def self.find(id)
  conn = Faraday.new(url: "#{API_URL}/device(#{id})") do |faraday|
    faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
    faraday.headers['Content-Type'] = 'application/json' # form-encode POST params
    faraday.headers['Authorization'] = "Bearer #{ENV['RESIN_API_KEY']}" # form-encode POST params
    # faraday.request :url_encoded # form-encode POST params
    # faraday.response :logger                  # log requests to $stdout
  end
  response = conn.get
  parsed_response = JSON.parse(response.body)
  attributes = parsed_response['d'][0]
  # byebug
  new(attributes)
end

Instance Method Details

#applicationObject



58
59
60
# File 'lib/resinio/device.rb', line 58

def application
  ResinIO::Application.find(self.app_id)
end