Latest 4.7.1
Homepage https://github.com/jonasman/TeslaSwift
License MIT
Platforms ios 10.0, osx 10.12, watchos 3.0, tvos 10.0, requires ARC
Dependencies PromiseKit/CorePromise
Frameworks Foundation
Authors

Swift library to access Tesla API based on Tesla JSON API (Unofficial)

Swift
Build Status
TeslaSwift

Installation

Manual

Copy Sources folder into your project

CocoaPods

pod 'TeslaSwift', '~> 4'

Swift Package Manager

You can use Swift Package Manager and specify a dependency in Package.swift by adding this:

.Package(url: "https://github.com/jonasman/TeslaSwift.git", majorVersion: 4)

Usage

Tesla’s server is not fully compatible with ATS so you need to add the following to your app Info.plist

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

Import the module

import TeslaSwift

Perform an authentication with your My Tesla credentials:

let api = TeslaSwift()
api.authenticate(email: email, password: password)

Use the promise to check the success:

.done { (result) in
    // Logged In!
}.catch { (error) in
    print("Error: (error as NSError)")
}

Example


class ViewController {
    func showCars() {
        api.getVehicles()
        .done { (response) in
            self.data = response
            self.tableView.reloadData()
        }.catch { (error) in
            //Process error
   }
}

Streaming

class ViewController {

  func showStream() {
    api.openStream(vehicle: myVehicle, dataReceived: {
                    (event: StreamEvent?, error: Error?) in

                    if event != nil {
                        self.data.append(event)
                        self.tableView.reloadData()
                    } else {
                        //Process error
                    }
                })

    // After some events...
    api.closeStream()
   }
}

Encoder and Decoder

If you need a JSON Encoder and Decoder, the library provides both already configured to be used with Tesla’s JSON formats

public let teslaJSONEncoder: JSONEncoder
public let teslaJSONDecoder: JSONDecoder

Options

You can use the mock server by setting: api.useMockServer = true

You can enable debugging by setting: api.debuggingEnabled = true

Other Features

After the authentication is done. The library manages itself the access token.
When the token expires the library will perform another authentication with your past credentials.

Roadmap

4.x

Add new API features and summon

Referral

If you want to buy a Tesla or signup for the mailing list using my referral as a "thank you" for this library here it is:
http://ts.la/joao290

Apps using this library

Missing your app? open a PR or issue

License

The MIT License (MIT)

Copyright (c) 2016 João Nunes

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.

Latest podspec

{
    "name": "TeslaSwift",
    "version": "4.7.1",
    "summary": "Swift library to access the Tesla Model S API.",
    "homepage": "https://github.com/jonasman/TeslaSwift",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Joao Nunes": "[email protected]"
    },
    "social_media_url": "https://twitter.com/jonas2man",
    "platforms": {
        "ios": "10.0",
        "osx": "10.12",
        "watchos": "3.0",
        "tvos": "10.0"
    },
    "swift_versions": "5",
    "source": {
        "git": "https://github.com/jonasman/TeslaSwift.git",
        "tag": "4.7.1"
    },
    "source_files": "Sources/**/*.swift",
    "frameworks": "Foundation",
    "requires_arc": true,
    "dependencies": {
        "PromiseKit/CorePromise": [
            "~> 6"
        ]
    }
}

Pin It on Pinterest

Share This