module Strive.Actions.Segments
( getSegment
, getStarredSegments
, getSegmentEfforts
, getSegmentLeaderboard
, exploreSegments
) where
import Data.List (intercalate)
import Network.HTTP.Types (Query, toQuery)
import Strive.Aliases (Latitude, Longitude, Result, SegmentId)
import Strive.Client (Client)
import Strive.Internal.HTTP (get)
import Strive.Options (ExploreSegmentsOptions, GetSegmentEffortsOptions,
GetSegmentLeaderboardOptions, GetStarredSegmentsOptions)
import Strive.Types (EffortDetailed, SegmentDetailed, SegmentExplorerResponse,
SegmentLeaderboardResponse, SegmentSummary)
getSegment :: Client -> SegmentId -> IO (Result SegmentDetailed)
getSegment client segmentId = get client resource query
where
resource = "api/v3/segments/" ++ show segmentId
query = [] :: Query
getStarredSegments :: Client -> GetStarredSegmentsOptions -> IO (Result [SegmentSummary])
getStarredSegments client options = get client resource query
where
resource = "api/v3/segments/starred"
query = toQuery options
getSegmentEfforts :: Client -> SegmentId -> GetSegmentEffortsOptions -> IO (Result [EffortDetailed])
getSegmentEfforts client segmentId options = get client resource query
where
resource = "api/v3/segments/" ++ show segmentId ++ "/all_efforts"
query = toQuery options
getSegmentLeaderboard :: Client -> SegmentId -> GetSegmentLeaderboardOptions -> IO (Result SegmentLeaderboardResponse)
getSegmentLeaderboard client segmentId options = get client resource query
where
resource = "api/v3/segments/" ++ show segmentId ++ "/leaderboard"
query = toQuery options
exploreSegments :: Client -> (Latitude, Longitude, Latitude, Longitude) -> ExploreSegmentsOptions -> IO (Result SegmentExplorerResponse)
exploreSegments client (south, west, north, east) options = get client resource query
where
resource = "api/v3/segments/explore"
query = toQuery
[ ("bounds", intercalate "," (map show [south, west, north, east]))
] ++ toQuery options