class Alexa::Device
Attributes
attributes[RW]
Public Class Methods
new(attributes: {}, context:)
click to toggle source
# File lib/alexa/device.rb, line 7 def initialize(attributes: {}, context:) @attributes = attributes @context = context end
Public Instance Methods
audio_supported?()
click to toggle source
# File lib/alexa/device.rb, line 18 def audio_supported? attributes["supportedInterfaces"].keys.include?("AudioPlayer") end
id()
click to toggle source
Return device id
# File lib/alexa/device.rb, line 14 def id attributes["deviceId"] end
location()
click to toggle source
Return device location from amazon. Makes an API to amazon alexa's device location service and returns the location hash
# File lib/alexa/device.rb, line 30 def location @_location ||= begin if Alexa.configuration.location_permission_type == :full_address get_address elsif Alexa.configuration.location_permission_type == :country_and_postal_code get_address(only: :country_and_postal_code) end end end
video_supported?()
click to toggle source
# File lib/alexa/device.rb, line 22 def video_supported? attributes["supportedInterfaces"].keys.include?("VideoApp") end
Private Instance Methods
get_address(only: nil)
click to toggle source
# File lib/alexa/device.rb, line 42 def get_address(only: nil) url = "#{@context.api_endpoint}/v1/devices/#{id}/settings/address" url = url + "/countryAndPostalCode" if only == :country_and_postal_code conn = Faraday.new(url: url) do |conn| conn.options["open_timeout"] = 20 conn.options["timeout"] = 10 conn.adapter :net_http conn.headers["Authorization"] = "Bearer #{@context.api_access_token}" end resp = conn.get if resp.status == 200 return JSON.parse(resp.body) end end