Module: Sense::Session

Included in:
Client
Defined in:
lib/hello_sense/session.rb

Instance Method Summary collapse

Instance Method Details

#authorize_with_password!Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/hello_sense/session.rb', line 5

def authorize_with_password!
  data = {
    grant_type: 'password',
    client_id: @client_id,
    client_secret: @client_secret,
    username: @username,
    password: @password,
  }
  request = Net::HTTP::Post.new('/v1/oauth2/token',
                                headers.reject { |key, _| key == :Authorization })
  request.set_form_data(data)
  response = connection.request(request)
  response_data = data_or_error(response)

  response_data['access_token']
end

#destroy_tokenObject



22
23
24
# File 'lib/hello_sense/session.rb', line 22

def destroy_token
  delete('/v1/oauth2/token')
end