mpclarkson / StravaSwift

A Swift wrapper for the Strava API v3
MIT License
102 stars 45 forks source link
strava swift

StravaSwift

CI Status codebeat badge Version License Platform

This is a Swift wrapper for the Strava v3 API.

As this is a passion project, I only work on it when I have time. So, if you are interested in contributing, feel free to submit PRs.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

StravaSwift is available through the Swift Package Manager and CocoaPods.

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/mpclarkson/StravaSwift.git", from: "1.0.1")
]

Cocoapods

To install it, simply add the following line to your Podfile:

pod "StravaSwift", '~> 1.0.1'

Quick Start

The full library documentation is available here.

let config = StravaConfig(
    clientId: YourStravaClientId,
    clientSecret: YourStravaClientSecret,
    redirectUri: YourRedirectUrl
)

StravaClient.sharedInstance.initWithConfig(config)
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>strava</string>
</array>
let strava = StravaClient.sharedInstance

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    return strava.handleAuthorizationRedirect(url)
}
strava.authorize() { result in
    switch result {
        case .success(let token):
            //do something for success
        case .failure(let error):
            //do something for error
    }
}

The Router implementation is based on this Alamofire example:

strava.request(Router.athletes(id: 9999999999)) { (athlete: Athlete?) in
    //do something with the athlete
}

let params = [
    'page' = 2,
    'per_page' = 25
]

strava.request(Router.athleteActivities(params: params) { (activities: [Activity]?) in
   //do something with the activities
}

Todos

Author

Matthew Clarkson, mpclarkson@gmail.com

License

StravaSwift is available under the MIT license. See the LICENSE file for more info.