class NestApi::Api

Public Class Methods

new(product_id: ENV.fetch("NEST_PRODUCT_ID"), product_secret: ENV.fetch("NEST_PRODUCT_SECRET"), file: NestApi::CONFIG_FILE) click to toggle source
# File lib/nest_api/api.rb, line 3
def initialize(product_id: ENV.fetch("NEST_PRODUCT_ID"), product_secret: ENV.fetch("NEST_PRODUCT_SECRET"), file: NestApi::CONFIG_FILE)
  @token = NestApi::AccessToken.new(product_id, product_secret, file)
end

Public Instance Methods

get_thermostat_by_name(name) click to toggle source

Retrieve a single thermostat by name

# File lib/nest_api/api.rb, line 13
def get_thermostat_by_name(name)
  get_thermostat_list[name]
end
get_thermostat_list() click to toggle source

Retrieve a list of all thermostats registered to this account

# File lib/nest_api/api.rb, line 8
def get_thermostat_list
  create_thermostats(HTTParty.get("#{NestApi::API_URL}/devices/thermostats", query: { auth: @token.access_token }))
end

Private Instance Methods

create_thermostats(thermostat_list) click to toggle source

Transform the nest api thermostats reponse into NestApi::Thermostat objects

# File lib/nest_api/api.rb, line 20
def create_thermostats(thermostat_list)
  thermostat_list.map { |device, info| [ info['name'], NestApi::Thermostat.new(device, @token) ] }.to_h
end