The strive package

[Tags: library, mit]

A Haskell client for the Strava V3 API.

Check out the readme for complete documentation.


[Skip to ReadMe]

Properties

Versions0.5.1, 0.6.0, 0.6.1, 0.6.2, 0.7.0, 0.7.1, 0.8.0, 1.0.0, 1.0.1, 2.0.0, 2.0.1, 2.1.0
Change logCHANGELOG.md
Dependenciesaeson (>=0.7 && <0.10), base (==4.*), bytestring (==0.10.*), data-default (==0.5.*), gpolyline (==0.1.*), http-conduit (==2.*), http-types (==0.8.*), template-haskell (==2.*), text (>=0.11 && <2), time (==1.*), transformers (>=0.3 && <0.5) [details]
LicenseMIT
Copyright2015 Taylor Fausak <taylor@fausak.me>
AuthorTaylor Fausak
Maintainertaylor@fausak.me
CategoryAPI
Home pagehttp://taylor.fausak.me/strive/
Bug trackerhttps://github.com/tfausak/strive/issues
Source repositoryhead: git clone git://github.com/tfausak/strive.git
UploadedSat Jun 6 03:43:03 UTC 2015 by fozworth
DistributionsNixOS:2.1.0
Downloads784 total (102 in last 30 days)
Votes
0 []
StatusDocs available [build log]
Last success reported on 2015-06-09 [all 1 reports]

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees

Readme for strive-2.1.0

Strive

Strive is a Haskell client for the Strava V3 API.

Version Build Dependencies


Installation

Add it to your Cabal file:

build-depends:
  strive ==2.1.*

Or install it manually:

$ cabal update
$ cabal install 'strive ==2.1.*'

Strive uses Semantic Versioning. See the change log for a detailed list of changes.

Usage

To use the API, you'll need an access token. Once you have that, create a new client using the default HTTP manager.

{-# LANGUAGE OverloadedStrings #-}
import Strive
let token = "..."
client <- buildClient (Just token)

Most types implement lenses for their fields. Lenses are preferred over directly accessing the fields. For instance, instead of doing this:

client_accessToken (client { client_accessToken = "record token" })
-- "record token"

Do this:

get accessToken (set accessToken "lens token" client)
-- "lens token"
<!--

This setup is required for these examples to work, but it isn't required for a reader of this file to understand what's going on.

{-# LANGUAGE OverloadedStrings #-}

import Data.ByteString.Char8 (pack)
import Data.Time.Calendar (fromGregorian)
import Data.Time.Clock (UTCTime (UTCTime))
import Strive
import System.Exit (exitSuccess)

main :: IO ()
main = do
  _ <- exitSuccess
  client <- buildClient (Just "token")
-->

Authentication

Request access

  let authorizeUrl = buildAuthorizeUrl 1790 "http://localhost" $ with
        [ set approvalPrompt False
        , set privateScope True
        , set writeScope True
        , set state "..."
        ]
  print (authorizeUrl :: String)

Token exchange

  tokenExchangeResponse <- exchangeToken 1790 "secret" "code"
  print (tokenExchangeResponse :: Result TokenExchangeResponse)

Deauthorization

  deauthorizationResponse <- deauthorize client
  print (deauthorizationResponse :: Result DeauthorizationResponse)

Athletes

Retrieve current athlete

  currentAthlete <- getCurrentAthlete client
  print (currentAthlete :: Result AthleteDetailed)

Retrieve another athlete

  anotherAthlete <- getAthlete client 65516
  print (anotherAthlete :: Result AthleteSummary)

Update current athlete

  updatedAthlete <- updateCurrentAthlete client $ with
    [ set city (Just "Dallas")
    , set state (Just "Texas")
    , set country (Just "United States")
    , set sex (Just Male)
    , set weight (Just 72.57)
    ]
  print (updatedAthlete :: Result AthleteDetailed)

Totals and stats

  athleteStats <- getAthleteStats client 65516
  print (athleteStats :: Result AthleteStats)

List athlete K/QOMs/CRs

  athleteCrs <- getAthleteCrs client 65516 $ with
    [ set page 1
    , set perPage 2
    ]
  print (athleteCrs :: Result [EffortDetailed])

Friends and followers

List athlete friends

  currentFriends <- getCurrentFriends client $ with
    [ set page 1
    , set perPage 2
    ]
  print (currentFriends :: Result [AthleteSummary])
  friends <- getFriends client 65516 $ with
    [ set page 1
    , set perPage 2
    ]
  print (friends :: Result [AthleteSummary])

List athlete followers

  currentFollowers <- getCurrentFollowers client $ with
    [ set page 1
    , set perPage 2
    ]
  print (currentFollowers :: Result [AthleteSummary])
  followers <- getFollowers client 65516 $ with
    [ set page 1
    , set perPage 2
    ]
  print (followers :: Result [AthleteSummary])

List both following

  commonFriends <- getCommonFriends client 65516 $ with
    [ set page 1
    , set perPage 2
    ]
  print (commonFriends :: Result [AthleteSummary])

Activities

Create an activity

  createdActivity <- createActivity client "An Example" Run (UTCTime (fromGregorian 1970 0 0) 0) 10 $ with
    [ set description (Just "...")
    , set distance (Just 100.0)
    ]
  print (createdActivity :: Result ActivityDetailed)

Retrieve an activity

  activity <- getActivity client 141273622 $ with
    [ set allEfforts True
    ]
  print (activity :: Result ActivitySummary)

Update an activity

  updatedActivity <- updateActivity client 141273622 $ with
    [ set name (Just "WedEx Pit Stop")
    , set type_ (Just Ride)
    , set private (Just False)
    , set commute (Just True)
    , set trainer (Just False)
    , set gearId (Just "b387882")
    , set description Nothing
    ]
  print (updatedActivity :: Result ActivityDetailed)

Delete an activity

  deletedActivity <- deleteActivity client 162674281
  print (deletedActivity :: Result ())

List athlete activities

  currentActivities <- getCurrentActivities client $ with
    [ set before (Just (UTCTime (fromGregorian 1970 0 0) 0))
    , set after (Just (UTCTime (fromGregorian 1970 0 0) 0))
    , set page 1
    , set perPage 2
    ]
  print (currentActivities :: Result [ActivitySummary])

List related activities

  relatedActivities <- getRelatedActivities client 141273622 $ with
    [ set page 1
    , set perPage 2
    ]
  print (relatedActivities :: Result [ActivitySummary])

List friends' activities

  feed <- getFeed client $ with
    [ set page 1
    , set perPage 2
    ]
  print (feed :: Result [ActivitySummary])

List activity zones

  activityZones <- getActivityZones client 141273622
  print (activityZones :: Result [ActivityZoneDetailed])

List activity laps

  activityLaps <- getActivityLaps client 141273622
  print (activityLaps :: Result [ActivityLapSummary])

Comments

List activity comments

  activityComments <- getActivityComments client 90112360 $ with
    [ set markdown True
    , set page 1
    , set perPage 2
    ]
  print (activityComments :: Result [CommentSummary])

Kudos

List activity kudoers

  activityKudoers <- getActivityKudoers client 141273622 $ with
    [ set page 1
    , set perPage 2
    ]
  print (activityKudoers :: Result [AthleteSummary])

Photos

List activity photos

  activityPhotos <- getActivityPhotos client 141273622
  print (activityPhotos :: Result [PhotoSummary])

Clubs

Retrieve a club

  club <- getClub client 11193
  print (club :: Result ClubDetailed)

List athlete clubs

  currentClubs <- getCurrentClubs client
  print (currentClubs :: Result [ClubSummary])

List club members

  clubMembers <- getClubMembers client 11193 $ with
    [ set page 1
    , set perPage 2
    ]
  print (clubMembers :: Result [AthleteSummary])

List club activities

  clubActivities <- getClubActivities client 11193 $ with
    [ set page 1
    , set perPage 2
    ]
  print (clubActivities :: Result [ActivitySummary])

Join a club

  joinedClub <- joinClub client 165
  print (joinedClub :: Result ())

Leave a club

  leftClub <- leaveClub client 165
  print (leftClub :: Result ())

Gear

Retrieve gear

  theGear <- getGear client "b387855"
  print (theGear :: Result GearDetailed)

Segments

Retrieve a segment

  theSegment <- getSegment client 4773104
  print (theSegment :: Result SegmentDetailed)

List starred segments

  starredSegments <- getStarredSegments client $ with
    [ set page 1
    , set perPage 2
    ]
  print (starredSegments :: Result [SegmentSummary])

List efforts

  theSegmentEfforts <- getSegmentEfforts client 4773104 $ with
    [ set athleteId (Just 65516)
    , set range (Just ((UTCTime (fromGregorian 1970 0 0) 0), (UTCTime (fromGregorian 1970 0 0) 0)))
    , set page 1
    , set perPage 2
    ]
  print (theSegmentEfforts :: Result [EffortDetailed])

Segment leaderboard

  segmentLeaderboardResponse <- getSegmentLeaderboard client 4773104 $ with
    [ set gender (Just Male)
    , set ageGroup (Just Ages0To24)
    , set weightClass (Just Kilograms65To74)
    , set following (Just True)
    , set clubId (Just 11193)
    , set dateRange (Just "this_year")
    , set contextEntries (Just 15)
    , set page 1
    , set perPage 2
    ]
  print (segmentLeaderboardResponse :: Result SegmentLeaderboardResponse)

Segment explorer

  segmentExplorerResponse <- exploreSegments client (32.0, -96.0, 33.0, -95.0) $ with
    [ set activityType Riding
    , set minCat 0
    , set maxCat 5
    ]
  print (segmentExplorerResponse :: Result SegmentExplorerResponse)

Segment efforts

Retrieve a segment effort

  segmentEffort <- getSegmentEffort client 1595370098
  print (segmentEffort :: Result EffortDetailed)

Streams

Retrieve activity streams

  activityStreams <- getActivityStreams client 141273622 [LatlngStream, WattsStream] $ with
    [ set resolution (Just Low)
    , set seriesType Time
    ]
  print (activityStreams :: Result [StreamDetailed])

Retrieve effort streams

  effortStreams <- getEffortStreams client 1595370098 [LatlngStream, WattsStream] $ with
    [ set resolution (Just Low)
    , set seriesType Time
    ]
  print (effortStreams :: Result [StreamDetailed])

Retrieve segment streams

  segmentStreams <- getSegmentStreams client 4773104 [LatlngStream, WattsStream] $ with
    [ set resolution (Just Low)
    , set seriesType Time
    ]
  print (segmentStreams :: Result [StreamDetailed])

Uploads

Upload an activity

  uploadedActivity <- uploadActivity client (pack "...") "gpx.gz" $ with
    [ set activityType (Just Ride)
    , set name (Just "An Example")
    , set description (Just "...")
    , set private True
    , set trainer False
    , set externalId (Just "...")
    ]
  print (uploadedActivity :: Result UploadStatus)

Check upload status

  upload <- getUpload client 16486788
  print (upload :: Result UploadStatus)