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 -> IO (Result SegmentDetailed)
getSegment Client
client SegmentId
segmentId = Client -> String -> Query -> IO (Result SegmentDetailed)
forall q j.
(QueryLike q, FromJSON j) =>
Client -> String -> q -> IO (Result j)
get Client
client String
resource Query
query
where
resource :: String
resource = String
"api/v3/segments/" String -> String -> String
forall a. [a] -> [a] -> [a]
++ SegmentId -> String
forall a. Show a => a -> String
show SegmentId
segmentId
query :: Query
query = [] :: Query
getStarredSegments :: Client -> GetStarredSegmentsOptions -> IO (Result [SegmentSummary])
getStarredSegments :: Client -> GetStarredSegmentsOptions -> IO (Result [SegmentSummary])
getStarredSegments Client
client GetStarredSegmentsOptions
options = Client -> String -> Query -> IO (Result [SegmentSummary])
forall q j.
(QueryLike q, FromJSON j) =>
Client -> String -> q -> IO (Result j)
get Client
client String
resource Query
query
where
resource :: String
resource = String
"api/v3/segments/starred"
query :: Query
query = GetStarredSegmentsOptions -> Query
forall a. QueryLike a => a -> Query
toQuery GetStarredSegmentsOptions
options
getSegmentEfforts :: Client -> SegmentId -> GetSegmentEffortsOptions -> IO (Result [EffortDetailed])
getSegmentEfforts :: Client
-> SegmentId
-> GetSegmentEffortsOptions
-> IO (Result [EffortDetailed])
getSegmentEfforts Client
client SegmentId
segmentId GetSegmentEffortsOptions
options = Client -> String -> Query -> IO (Result [EffortDetailed])
forall q j.
(QueryLike q, FromJSON j) =>
Client -> String -> q -> IO (Result j)
get Client
client String
resource Query
query
where
resource :: String
resource = String
"api/v3/segments/" String -> String -> String
forall a. [a] -> [a] -> [a]
++ SegmentId -> String
forall a. Show a => a -> String
show SegmentId
segmentId String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"/all_efforts"
query :: Query
query = GetSegmentEffortsOptions -> Query
forall a. QueryLike a => a -> Query
toQuery GetSegmentEffortsOptions
options
getSegmentLeaderboard :: Client -> SegmentId -> GetSegmentLeaderboardOptions -> IO (Result SegmentLeaderboardResponse)
getSegmentLeaderboard :: Client
-> SegmentId
-> GetSegmentLeaderboardOptions
-> IO (Result SegmentLeaderboardResponse)
getSegmentLeaderboard Client
client SegmentId
segmentId GetSegmentLeaderboardOptions
options = Client -> String -> Query -> IO (Result SegmentLeaderboardResponse)
forall q j.
(QueryLike q, FromJSON j) =>
Client -> String -> q -> IO (Result j)
get Client
client String
resource Query
query
where
resource :: String
resource = String
"api/v3/segments/" String -> String -> String
forall a. [a] -> [a] -> [a]
++ SegmentId -> String
forall a. Show a => a -> String
show SegmentId
segmentId String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"/leaderboard"
query :: Query
query = GetSegmentLeaderboardOptions -> Query
forall a. QueryLike a => a -> Query
toQuery GetSegmentLeaderboardOptions
options
exploreSegments :: Client -> (Latitude, Longitude, Latitude, Longitude) -> ExploreSegmentsOptions -> IO (Result SegmentExplorerResponse)
exploreSegments :: Client
-> (Latitude, Latitude, Latitude, Latitude)
-> ExploreSegmentsOptions
-> IO (Result SegmentExplorerResponse)
exploreSegments Client
client (Latitude
south, Latitude
west, Latitude
north, Latitude
east) ExploreSegmentsOptions
options = Client -> String -> Query -> IO (Result SegmentExplorerResponse)
forall q j.
(QueryLike q, FromJSON j) =>
Client -> String -> q -> IO (Result j)
get Client
client String
resource Query
query
where
resource :: String
resource = String
"api/v3/segments/explore"
query :: Query
query = [(String, String)] -> Query
forall a. QueryLike a => a -> Query
toQuery
[ (String
"bounds", String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"," ((Latitude -> String) -> [Latitude] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Latitude -> String
forall a. Show a => a -> String
show [Latitude
south, Latitude
west, Latitude
north, Latitude
east]))
] Query -> Query -> Query
forall a. [a] -> [a] -> [a]
++ ExploreSegmentsOptions -> Query
forall a. QueryLike a => a -> Query
toQuery ExploreSegmentsOptions
options