Skip to content

Commit

Permalink
Changes to use of access tokens and a general tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart Wilson committed Dec 27, 2014
1 parent d098e5b commit be880c1
Show file tree
Hide file tree
Showing 4 changed files with 318 additions and 261 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
.DS_Store
/.idea/

/vendor/

/examples/
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ StravaApi

Simple PHP class to interact with Strava's V3 API.

VERSION BUMP
-------

Latest version **1.0**

Updates include:

- Better composer support
- PSR 2 standards
- New `setAccessToken()` method

Overview
------------

Expand All @@ -22,7 +33,7 @@ Add `iamstuartwilson/strava` to your `composer.json`:
``` json
{
"require" : {
"iamstuartwilson/strava" : "dev-master"
"iamstuartwilson/strava" : "1.0.*"
}
}
```
Expand All @@ -38,34 +49,37 @@ Include the class and instantiate with your **client_id** and **client_secret**

require_once 'StravaApi.php';

$api = new StravaApi( $clientId, $clientSecret );
$api = new Iamstuartwilson\StravaApi(
$clientId,
$clientSecret
);

You will then need to [authenticate](http://strava.github.io/api/v3/oauth/) your strava account by requesting an access code *[1]*. You can generate a URL for authentication using the following method:

$api->authenticationUrl( $redirect, $approvalPrompt = 'auto', $scope = null, $state = null );
$api->authenticationUrl($redirect, $approvalPrompt = 'auto', $scope = null, $state = null);

When a code is returned you must then exchange it for an [access token](http://strava.github.io/api/v3/oauth/#post-token) for the authenticated user:

$api->tokenExchange( $code );
$api->tokenExchange($code);

Example Requests
------------

Get the most recent 100 KOMs from any athlete

$api->get( 'athletes/:id/koms', $accessToken, array( 'per_page' => 100 ) );
$api->get('athletes/:id/koms', array('per_page' => 100));

Post a new activity *[2]*

$api->post( 'activities', $accessToken, array( 'name' => 'API Test', 'type' => 'Ride', 'start_date_local' => date( 'Y-m-d\TH:i:s\Z' ), 'elapsed_time' => 3600 ) ) );
$api->post('activities', array('name' => 'API Test', 'type' => 'Ride', 'start_date_local' => date( 'Y-m-d\TH:i:s\Z'), 'elapsed_time' => 3600));

Update a athlete's weight *[2]*

$api->put( 'athlete', $accessToken, array( 'weight' => 70 ) );
$api->put('athlete', array('weight' => 70));

Delete an activity *[2]*

$api->delete( 'activities/:id', $accessToken );
$api->delete('activities/:id');

###Notes

Expand Down
Loading

0 comments on commit be880c1

Please sign in to comment.