Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
gutenye committed May 26, 2016
0 parents commit 418a035
Show file tree
Hide file tree
Showing 36 changed files with 2,128 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
presets: ["es2015", "stage-0"]
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
/utils
config.js
17 changes: 17 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
138 changes: 138 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
tesla-api, Unofficial API Wrapper for Tesla Model S and X
===================================================

[Homepage](https://github.com/gutenye/tesla-api) |
[Issue Tracker](https://github.com/gutenye/tesla-api/issues) |
[MIT License](http://choosealicense.com/licenses/mit) |
[by Guten](http://guten.me) |
[Gratipay](https://gratipay.com/gutenye) |
[Bountysource](https://www.bountysource.com/teams/gutenye)

| | |
|----------------|------------------------------------------------------------|
| **Install** | |
| Node | $ npm install tesla-api |

This is a part of [GutTesla](https://github.com/gutenye/guttesla) project.

Philosophy
-----------

API wrappers [should reflect the idioms of the language in which they were written](http://wynnnetherland.com/journal/what-makes-a-good-api-wrapper). tesla-api wraps the Tesla API in a flat API client that follows Javascript conventions and requires little knowledge of REST.

Getting started
---------------

With ES2015 and Async Functions

```javascript
import Tesla from "tesla-api"

async function main() {
try {
var vehicles = await Tesla.login({email: x, password: y})
var vehicle = vehicles[0]
var chargeState = await vehicle.chargeState()
} catch (err) {
if (err.status) { // 4xx, 5xx response error
console.log(`<${err.status} ${err.message}>`, err.response.body)
} else { // Network failures, timeouts, and other errors
console.error(err.stack)
}
}
}
main()
```

Streaming driving state

```
vehicle.stream().subscribe(
data => console.log(data.speed),
err => console.error(err),
() => console.log("complete")
)
```

stream returns a [Observable](https://github.com/ReactiveX/RxJS).

**Follows Javascript Conventions**

Convert response key from underscore to camelCase

```
{
response: {
display_name: "Hello",
remote_start_enabled: true
}
}
->
{
response: {
displayName: "Hello",
remoteStartEnabled: true
}
}
```

**Better Error Handling**

...

**Automatical re-Authentication**

When credientals are expires, automatically authenticate it again.

**Units Support**

```
Tesla.login({distanceUnit: "km"})
```

odometer, batteryRange, etc returns in kilometer unit instead of mile

**API Reference**

Read the source for now :)

Development
===========

Contributing
-------------

* Submit any bugs/features/ideas to GitHub issue tracker.
* Thanks to [all contributors](https://github.com/gutenye/tesla-api/contributors).

Resource
--------

* [Unofficial documentation of the Tesla API](https://github.com/timdorr/model-s-api)

Copyright
---------

The MIT License

Copyright (c) 2015 Guten Ye

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 21 additions & 0 deletions ake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

build() {
rm -r dist/* 2>/dev/null
babel --presets es2015,stage-0 lib --out-dir dist --ignore lib/secrets.js
cp lib/secrets.js dist
}

test() {
./test.js
}

publish() {
npm publish
}

case "$1" in
b | build) build ;;
t | test) test ;;
p | publish ) publish ;;
esac
23 changes: 23 additions & 0 deletions dist/console.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.cerror = exports.clog = undefined;
exports.cdebug = cdebug;

var _debug = require("debug");

var _debug2 = _interopRequireDefault(_debug);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function cdebug(format) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}

(0, _debug2.default)("tesla-api").apply(undefined, ["%s " + format, new Date().toLocaleTimeString()].concat(args));
}
var clog = exports.clog = console.log.bind(console);
var cerror = exports.cerror = console.log.bind(console);
10 changes: 10 additions & 0 deletions dist/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
var API_HOST = exports.API_HOST = "https://owner-api.teslamotors.com";
var API_URL = exports.API_URL = API_HOST + "/api/1";
var STREAM_HOST = exports.STREAM_HOST = "streaming.vn.teslamotors.com";
var ANDROID_USER_AGENT = exports.ANDROID_USER_AGENT = "Model S 2.1.79 (SM-G900V; Android REL 4.4.4; en_US)";
var DISTANCE_KEYS = exports.DISTANCE_KEYS = ["speed", "odometer", "battery_range", "ideal_battery_range", "est_battery_range"];
Loading

0 comments on commit 418a035

Please sign in to comment.