Skip to content

Instantly share code, notes, and snippets.

@slemiere
Created October 5, 2014 06:21
Show Gist options
  • Save slemiere/1e3ba98ccad0d540ae88 to your computer and use it in GitHub Desktop.
Save slemiere/1e3ba98ccad0d540ae88 to your computer and use it in GitHub Desktop.
require 'httparty'
class Wink
include HTTParty
CLIENT_ID = 'CHANGE_ME'
CLIENT_SECRET = 'CHANGE_ME'
base_uri 'https://winkapi.quirky.com'
def initialize(u, p)
@auth = {:username => u, :password => p}
end
def login!
response = self.class.post('/oauth2/token', body:{ client_id: CLIENT_ID, client_secret: CLIENT_SECRET, grant_type: 'password', username: @auth[:username], password: @auth[:password] })
if response.success?
@token = response['data']['access_token']
end
end
def profile
self.class.get('/users/me', headers: {'Authorization'=> "Bearer #{@token}"})
end
def devices
self.class.get('/users/me/wink_devices', headers: {'Authorization'=> "Bearer #{@token}"})
end
end
w = Wink.new('sylvain+hackmit@winkapp.com', 'azerty')
w.login!
w.devices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment