Strive is a Haskell client for the Strava V3 API.
Installation
Add it to your Cabal file:
build-depends:
strive
Or install it manually:
$ cabal update
$ cabal install strive
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"
let authorizeUrl = buildAuthorizeUrl 1790 "http://localhost" $ with
[ set approvalPrompt False
, set privateScope True
, set writeScope True
, set state "..."
]
print (authorizeUrl :: String)
tokenExchangeResponse <- exchangeToken 1790 "secret" "code"
print (tokenExchangeResponse :: Result TokenExchangeResponse)
deauthorizationResponse <- deauthorize client
print (deauthorizationResponse :: Result DeauthorizationResponse)
currentAthlete <- getCurrentAthlete client
print (currentAthlete :: Result AthleteDetailed)
anotherAthlete <- getAthlete client 65516
print (anotherAthlete :: Result AthleteSummary)
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)
athleteStats <- getAthleteStats client 65516
print (athleteStats :: Result AthleteStats)
athleteCrs <- getAthleteCrs client 65516 $ with
[ set page 1
, set perPage 2
]
print (athleteCrs :: Result [EffortDetailed])
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])
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])
commonFriends <- getCommonFriends client 65516 $ with
[ set page 1
, set perPage 2
]
print (commonFriends :: Result [AthleteSummary])
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)
activity <- getActivity client 141273622 $ with
[ set allEfforts True
]
print (activity :: Result ActivitySummary)
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)
deletedActivity <- deleteActivity client 162674281
print (deletedActivity :: Result ())
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])
relatedActivities <- getRelatedActivities client 141273622 $ with
[ set page 1
, set perPage 2
]
print (relatedActivities :: Result [ActivitySummary])
feed <- getFeed client $ with
[ set page 1
, set perPage 2
]
print (feed :: Result [ActivitySummary])
activityZones <- getActivityZones client 141273622
print (activityZones :: Result [ActivityZoneDetailed])
activityLaps <- getActivityLaps client 141273622
print (activityLaps :: Result [ActivityLapSummary])
activityComments <- getActivityComments client 90112360 $ with
[ set markdown True
, set page 1
, set perPage 2
]
print (activityComments :: Result [CommentSummary])
activityKudoers <- getActivityKudoers client 141273622 $ with
[ set page 1
, set perPage 2
]
print (activityKudoers :: Result [AthleteSummary])
activityPhotos <- getActivityPhotos client 141273622
print (activityPhotos :: Result [PhotoSummary])
club <- getClub client 11193
print (club :: Result ClubDetailed)
currentClubs <- getCurrentClubs client
print (currentClubs :: Result [ClubSummary])
clubMembers <- getClubMembers client 11193 $ with
[ set page 1
, set perPage 2
]
print (clubMembers :: Result [AthleteSummary])
clubActivities <- getClubActivities client 11193 $ with
[ set page 1
, set perPage 2
]
print (clubActivities :: Result [ActivitySummary])
joinedClub <- joinClub client 165
print (joinedClub :: Result ())
leftClub <- leaveClub client 165
print (leftClub :: Result ())
theGear <- getGear client "b387855"
print (theGear :: Result GearDetailed)
theSegment <- getSegment client 4773104
print (theSegment :: Result SegmentDetailed)
starredSegments <- getStarredSegments client $ with
[ set page 1
, set perPage 2
]
print (starredSegments :: Result [SegmentSummary])
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])
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)
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)
segmentEffort <- getSegmentEffort client 1595370098
print (segmentEffort :: Result EffortDetailed)
activityStreams <- getActivityStreams client 141273622 [LatlngStream, WattsStream] $ with
[ set resolution (Just Low)
, set seriesType Time
]
print (activityStreams :: Result [StreamDetailed])
effortStreams <- getEffortStreams client 1595370098 [LatlngStream, WattsStream] $ with
[ set resolution (Just Low)
, set seriesType Time
]
print (effortStreams :: Result [StreamDetailed])
segmentStreams <- getSegmentStreams client 4773104 [LatlngStream, WattsStream] $ with
[ set resolution (Just Low)
, set seriesType Time
]
print (segmentStreams :: Result [StreamDetailed])
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)
upload <- getUpload client 16486788
print (upload :: Result UploadStatus)