Skip to content

adamwulf/automatic-php-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Automatic PHP API

This is a PHP client library for the Automatic API (http://www.automatic.com/). The Automatic Link plugs into your car's data port and connects to your phone to help you track and improve your driving habits. This API gives you access to the data stored in your Automatic account, including some of your car information and driving history. The Automatic API is in early alpha, and more functionality is expected to be released soon.

Authentication

The Automatic API uses OAuth2 to authenticate against their website.

Cloning this Repo

This repo uses a PHP OAuth2 library for authentication as a submodule. When cloning, be sure to:

$ git clone git@github.com:adamwulf/automatic-php-api.git
$ cd automatic-php-api
$ git submodule init
$ git submodule update

Usage

Below is a simple code snippet that shows how to authenticate with the API and send requests to fetch the user's trip information.

$automatic = new Automatic($your_client_id, $your_client_secret);

// logging in with OAuth2 code
if (/* have a stored token somewhere in $_SESSION or the database */){
    $automatic->setOAuthToken($the_stored_token_to_reuse);
}else if (!isset($_GET['code'])){
	// we don't have a token stored, so fetch one
	$scopes = array("scope:location", "scope:vehicle", "scope:trip:summary");
	$auth_url = $automatic->authenticationURLForScopes($scopes);
    header('Location: ' . $auth_url);
    die('Redirect');
}
else
{
    $response_token = $automatic->getTokenForCode($_GET["code"]);
    // store and re-use this $response_token to save the user's login
    // across multiple requests
    $automatic->setOAuthToken($response_token);
}

$trip_data = $automatic->getTrips();

Documentation

The Automatic API documentation is available at: https://www.automatic.com/developer/documentation/

More information is available at: https://www.automatic.com/developer/

About

A barebones PHP API for the Automatic API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages