class ResinIO::Device
Attributes
app_id[R]
commit[R]
device_name[R]
device_type[R]
id[R]
ip_address[R]
is_online[R]
last_connectivity_event[R]
latitude[R]
location[R]
longitude[R]
os_variant[R]
os_version[R]
status[R]
supervisor_version[R]
uuid[R]
Public Class Methods
all()
click to toggle source
# 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)
click to toggle source
# 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
new(attributes)
click to toggle source
# 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
Public Instance Methods
application()
click to toggle source
# File lib/resinio/device.rb, line 58 def application ResinIO::Application.find(self.app_id) end