Created
March 29, 2015 09:43
-
-
Save shao1555/9dac11f53af0fa7e333f to your computer and use it in GitHub Desktop.
Hello, Tesla World.
This file contains hidden or 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 'rest-client' | |
require 'json' | |
ENDPOINT = 'https://portal.vn.teslamotors.com/' | |
# login | |
session_id = ENV['TESLA_SESSION_ID'] | |
user_credentials = ENV['TESLA_USER_CREDENTIALS'] | |
unless session_id && user_credentials | |
login = RestClient.post( | |
"#{ENDPOINT}login", { | |
"user_session[email]" => ENV['TESLA_EMAIL'], | |
"user_session[password]" => ENV['TESLA_PASSWORD'] | |
} | |
) | |
session_id = login.cookies['_s_portal_session'] | |
user_credentials = login.cookies['user_credentials'] | |
end | |
# get vehicle id | |
data = JSON.parse(RestClient.get("#{ENDPOINT}vehicles")) | |
vehicle_id = data[0]['id'] | |
# awake | |
RestClient.get("#{ENDPOINT}vehicles/#{vehicle_id}/command/wake_up") | |
# let's open door | |
RestClient.get("#{ENDPOINT}vehicles/#{vehicle_id}/command/door_unlock") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment