5 unstable releases

Uses old Rust 2015

0.2.0 Jan 14, 2018
0.1.1 Jun 8, 2015
0.1.0 Jun 8, 2015
0.0.2 Apr 24, 2015
0.0.1 Apr 24, 2015

#42 in #segment

MPL-2.0 license

31KB
774 lines

strava-rs

Strava API client in Rust

Circle CI

About

The library currently exposes functions for accessing athletes, segments, and segment efforts. Support for activities is next on the list. For an exhaustive list of capabilities, please reference the docs.

extern crate strava;

use strava::athletes::Athlete;
use strava::api::AccessToken;

fn main() {
    // Create a token
    let token = AccessToken::new("<my token>".to_string());

    // Get the athlete associated with the given token
    let athlete = Athlete::get_current(&token).unwrap();

    // All of the strava types implement Debug and can be printed like so:
    println!("{:?}", athlete);
}

Disclaimer

I am not in any way affiliated with Strava, Inc. I merely wish to use the Strava API from Rust.


lib.rs:

A wrapper for the Strava API

Organization

The module layout in this crate mirrors the Strava API documentation. All functions interacting with the strava servers will return a strava::error::Result for which the E parameter is curried to strava::error::ApiError. The module listing below includes UNIMPLEMENTED tags to make it clear what hasn't been written yet. Modules without that tag are not guaranteed to exhaustively wrap all endpoints for that type, but they are guaranteed to have support for between 1..all endpoints for that type.

Examples

The simplest thing one can do with the strava API is to get an athlete and print it out. Every request made against the Strava API requires a valid access token. Since this example provides a fake token, the unwrap call will panic with an ApiError::InvalidAccessToken. You can get a token by registering an application on strava.com.

use strava::athletes::Athlete;
use strava::api::AccessToken;

// Create a token
let token = AccessToken::new("<my token>".to_string());

// Get the athlete associated with the given token
let athlete = Athlete::get_current(&token).unwrap();

// All of the strava types implement Debug and can be printed like so:
println!("{:?}", athlete);

Dependencies

~4–12MB
~153K SLoC