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 = 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/" forall a. Semigroup a => a -> a -> a
<> 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 = 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 = 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 = 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/" forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show SegmentId
segmentId forall a. Semigroup a => a -> a -> a
<> String
"/all_efforts"
query :: Query
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 = 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/" forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show SegmentId
segmentId forall a. Semigroup a => a -> a -> a
<> String
"/leaderboard"
query :: Query
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 =
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 =
forall a. QueryLike a => a -> Query
toQuery
[(String
"bounds", forall a. [a] -> [[a]] -> [a]
intercalate String
"," (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Show a => a -> String
show [Latitude
south, Latitude
west, Latitude
north, Latitude
east]))]
forall a. Semigroup a => a -> a -> a
<> forall a. QueryLike a => a -> Query
toQuery ExploreSegmentsOptions
options