Created
October 5, 2014 06:21
-
-
Save slemiere/1e3ba98ccad0d540ae88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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