Class: NestConnect::API::Authorize

Inherits:
NestConnect::API show all
Defined in:
lib/nest_connect/api/authorize.rb

Instance Method Summary collapse

Methods inherited from NestConnect::API

#access_token

Constructor Details

#initialize(auth_code:, client_id:, client_secret:, stdout: STDOUT) ⇒ Authorize

Returns a new instance of Authorize.



4
5
6
7
8
9
# File 'lib/nest_connect/api/authorize.rb', line 4

def initialize(auth_code:, client_id:, client_secret:, stdout: STDOUT)
  @auth_code = auth_code
  @client_id = client_id
  @client_secret = client_secret
  @stdout = stdout
end

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/nest_connect/api/authorize.rb', line 11

def run
  response = connection.post do |request|
    request.url(url)
    request.headers.merge!(headers)
    request.body = body
  end

  if response.status == 200
    configuration.access_token = response.body['access_token']
  else
    stdout.write response.body
  end
end