Class: ResinIO::Device
- Inherits:
-
Object
- Object
- ResinIO::Device
- Defined in:
- lib/resinio/device.rb
Instance Attribute Summary collapse
-
#app_id ⇒ Object
readonly
Returns the value of attribute app_id.
-
#commit ⇒ Object
readonly
Returns the value of attribute commit.
-
#device_name ⇒ Object
readonly
Returns the value of attribute device_name.
-
#device_type ⇒ Object
readonly
Returns the value of attribute device_type.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#ip_address ⇒ Object
readonly
Returns the value of attribute ip_address.
-
#is_online ⇒ Object
readonly
Returns the value of attribute is_online.
-
#last_connectivity_event ⇒ Object
readonly
Returns the value of attribute last_connectivity_event.
-
#latitude ⇒ Object
readonly
Returns the value of attribute latitude.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#longitude ⇒ Object
readonly
Returns the value of attribute longitude.
-
#os_variant ⇒ Object
readonly
Returns the value of attribute os_variant.
-
#os_version ⇒ Object
readonly
Returns the value of attribute os_version.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#supervisor_version ⇒ Object
readonly
Returns the value of attribute supervisor_version.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
- #application ⇒ Object
-
#initialize(attributes) ⇒ Device
constructor
A new instance of Device.
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_id ⇒ Object (readonly)
Returns the value of attribute app_id.
7 8 9 |
# File 'lib/resinio/device.rb', line 7 def app_id @app_id end |
#commit ⇒ Object (readonly)
Returns the value of attribute commit.
7 8 9 |
# File 'lib/resinio/device.rb', line 7 def commit @commit end |
#device_name ⇒ Object (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_type ⇒ Object (readonly)
Returns the value of attribute device_type.
7 8 9 |
# File 'lib/resinio/device.rb', line 7 def device_type @device_type end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/resinio/device.rb', line 7 def id @id end |
#ip_address ⇒ Object (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_online ⇒ Object (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_event ⇒ Object (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 |
#latitude ⇒ Object (readonly)
Returns the value of attribute latitude.
7 8 9 |
# File 'lib/resinio/device.rb', line 7 def latitude @latitude end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
7 8 9 |
# File 'lib/resinio/device.rb', line 7 def location @location end |
#longitude ⇒ Object (readonly)
Returns the value of attribute longitude.
7 8 9 |
# File 'lib/resinio/device.rb', line 7 def longitude @longitude end |
#os_variant ⇒ Object (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_version ⇒ Object (readonly)
Returns the value of attribute os_version.
7 8 9 |
# File 'lib/resinio/device.rb', line 7 def os_version @os_version end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/resinio/device.rb', line 7 def status @status end |
#supervisor_version ⇒ Object (readonly)
Returns the value of attribute supervisor_version.
7 8 9 |
# File 'lib/resinio/device.rb', line 7 def supervisor_version @supervisor_version end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
7 8 9 |
# File 'lib/resinio/device.rb', line 7 def uuid @uuid end |
Class Method Details
.all ⇒ Object
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
#application ⇒ Object
58 59 60 |
# File 'lib/resinio/device.rb', line 58 def application ResinIO::Application.find(self.app_id) end |