Drop use of Server args in ApiUrl.
This commit is contained in:
parent
1ad5dac7a1
commit
44843e0ccd
|
@ -32,19 +32,19 @@ type alias Server =
|
||||||
String
|
String
|
||||||
|
|
||||||
|
|
||||||
apps : Server -> String
|
apps : String
|
||||||
apps server =
|
apps =
|
||||||
server ++ "/api/v1/apps"
|
"/api/v1/apps"
|
||||||
|
|
||||||
|
|
||||||
oauthAuthorize : Server -> String
|
oauthAuthorize : String
|
||||||
oauthAuthorize server =
|
oauthAuthorize =
|
||||||
server ++ "/oauth/authorize"
|
"/oauth/authorize"
|
||||||
|
|
||||||
|
|
||||||
oauthToken : Server -> String
|
oauthToken : String
|
||||||
oauthToken server =
|
oauthToken =
|
||||||
server ++ "/oauth/token"
|
"/oauth/token"
|
||||||
|
|
||||||
|
|
||||||
accounts : String
|
accounts : String
|
||||||
|
@ -57,33 +57,24 @@ account id =
|
||||||
accounts ++ (toString id)
|
accounts ++ (toString id)
|
||||||
|
|
||||||
|
|
||||||
follow : Server -> Int -> String
|
follow : Int -> String
|
||||||
follow server id =
|
follow id =
|
||||||
server ++ accounts ++ (toString id) ++ "/follow"
|
accounts ++ (toString id) ++ "/follow"
|
||||||
|
|
||||||
|
|
||||||
unfollow : Server -> Int -> String
|
unfollow : Int -> String
|
||||||
unfollow server id =
|
unfollow id =
|
||||||
server ++ accounts ++ (toString id) ++ "/unfollow"
|
accounts ++ (toString id) ++ "/unfollow"
|
||||||
|
|
||||||
|
|
||||||
userAccount : Server -> String
|
userAccount : String
|
||||||
userAccount server =
|
userAccount =
|
||||||
server ++ accounts ++ "verify_credentials"
|
accounts ++ "verify_credentials"
|
||||||
|
|
||||||
|
|
||||||
searchAccount : Server -> String -> Int -> Bool -> String
|
searchAccount : String
|
||||||
searchAccount server query limit resolve =
|
searchAccount =
|
||||||
encodeUrl (server ++ accounts ++ "search")
|
accounts ++ "search"
|
||||||
[ ( "q", query )
|
|
||||||
, ( "limit", toString limit )
|
|
||||||
, ( "resolve"
|
|
||||||
, if resolve then
|
|
||||||
"true"
|
|
||||||
else
|
|
||||||
"false"
|
|
||||||
)
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
relationships : List Int -> String
|
relationships : List Int -> String
|
||||||
|
@ -131,41 +122,41 @@ notifications =
|
||||||
"/api/v1/notifications"
|
"/api/v1/notifications"
|
||||||
|
|
||||||
|
|
||||||
statuses : Server -> String
|
statuses : String
|
||||||
statuses server =
|
statuses =
|
||||||
server ++ "/api/v1/statuses"
|
"/api/v1/statuses"
|
||||||
|
|
||||||
|
|
||||||
context : Server -> Int -> String
|
context : Int -> String
|
||||||
context server id =
|
context id =
|
||||||
statuses server ++ "/" ++ (toString id) ++ "/context"
|
statuses ++ "/" ++ (toString id) ++ "/context"
|
||||||
|
|
||||||
|
|
||||||
reblog : Server -> Int -> String
|
reblog : Int -> String
|
||||||
reblog server id =
|
reblog id =
|
||||||
statuses server ++ "/" ++ (toString id) ++ "/reblog"
|
statuses ++ "/" ++ (toString id) ++ "/reblog"
|
||||||
|
|
||||||
|
|
||||||
status : Server -> Int -> String
|
status : Int -> String
|
||||||
status server id =
|
status id =
|
||||||
statuses server ++ "/" ++ (toString id)
|
statuses ++ "/" ++ (toString id)
|
||||||
|
|
||||||
|
|
||||||
unreblog : Server -> Int -> String
|
unreblog : Int -> String
|
||||||
unreblog server id =
|
unreblog id =
|
||||||
statuses server ++ "/" ++ (toString id) ++ "/unreblog"
|
statuses ++ "/" ++ (toString id) ++ "/unreblog"
|
||||||
|
|
||||||
|
|
||||||
favourite : Server -> Int -> String
|
favourite : Int -> String
|
||||||
favourite server id =
|
favourite id =
|
||||||
statuses server ++ "/" ++ (toString id) ++ "/favourite"
|
statuses ++ "/" ++ (toString id) ++ "/favourite"
|
||||||
|
|
||||||
|
|
||||||
unfavourite : Server -> Int -> String
|
unfavourite : Int -> String
|
||||||
unfavourite server id =
|
unfavourite id =
|
||||||
statuses server ++ "/" ++ (toString id) ++ "/unfavourite"
|
statuses ++ "/" ++ (toString id) ++ "/unfavourite"
|
||||||
|
|
||||||
|
|
||||||
streaming : Server -> String
|
streaming : String
|
||||||
streaming server =
|
streaming =
|
||||||
server ++ "/api/v1/streaming/"
|
"/api/v1/streaming/"
|
||||||
|
|
|
@ -74,23 +74,41 @@ toResponse result =
|
||||||
Result.mapError extractError result
|
Result.mapError extractError result
|
||||||
|
|
||||||
|
|
||||||
fetch : Client -> String -> Decode.Decoder a -> Request a
|
type Method
|
||||||
fetch client endpoint decoder =
|
= GET
|
||||||
HttpBuilder.get (client.server ++ endpoint)
|
| POST
|
||||||
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
| DELETE
|
||||||
|> HttpBuilder.withExpect (Http.expectJson decoder)
|
|
||||||
|
|
||||||
|
fetch : Method -> Client -> String -> Decode.Decoder a -> Request a
|
||||||
|
fetch method client endpoint decoder =
|
||||||
|
let
|
||||||
|
request =
|
||||||
|
case method of
|
||||||
|
GET ->
|
||||||
|
HttpBuilder.get
|
||||||
|
|
||||||
|
POST ->
|
||||||
|
HttpBuilder.post
|
||||||
|
|
||||||
|
DELETE ->
|
||||||
|
HttpBuilder.delete
|
||||||
|
in
|
||||||
|
request (client.server ++ endpoint)
|
||||||
|
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
||||||
|
|> HttpBuilder.withExpect (Http.expectJson decoder)
|
||||||
|
|
||||||
|
|
||||||
register : String -> String -> String -> String -> String -> Request AppRegistration
|
register : String -> String -> String -> String -> String -> Request AppRegistration
|
||||||
register server client_name redirect_uri scope website =
|
register server client_name redirect_uri scope website =
|
||||||
HttpBuilder.post (ApiUrl.apps server)
|
HttpBuilder.post (server ++ ApiUrl.apps)
|
||||||
|> HttpBuilder.withExpect (Http.expectJson (appRegistrationDecoder server scope))
|
|> HttpBuilder.withExpect (Http.expectJson (appRegistrationDecoder server scope))
|
||||||
|> HttpBuilder.withJsonBody (appRegistrationEncoder client_name redirect_uri scope website)
|
|> HttpBuilder.withJsonBody (appRegistrationEncoder client_name redirect_uri scope website)
|
||||||
|
|
||||||
|
|
||||||
getAuthorizationUrl : AppRegistration -> String
|
getAuthorizationUrl : AppRegistration -> String
|
||||||
getAuthorizationUrl registration =
|
getAuthorizationUrl registration =
|
||||||
encodeUrl (ApiUrl.oauthAuthorize registration.server)
|
encodeUrl (registration.server ++ ApiUrl.oauthAuthorize)
|
||||||
[ ( "response_type", "code" )
|
[ ( "response_type", "code" )
|
||||||
, ( "client_id", registration.client_id )
|
, ( "client_id", registration.client_id )
|
||||||
, ( "scope", registration.scope )
|
, ( "scope", registration.scope )
|
||||||
|
@ -100,7 +118,7 @@ getAuthorizationUrl registration =
|
||||||
|
|
||||||
getAccessToken : AppRegistration -> String -> Request AccessTokenResult
|
getAccessToken : AppRegistration -> String -> Request AccessTokenResult
|
||||||
getAccessToken registration authCode =
|
getAccessToken registration authCode =
|
||||||
HttpBuilder.post (ApiUrl.oauthToken registration.server)
|
HttpBuilder.post (registration.server ++ ApiUrl.oauthToken)
|
||||||
|> HttpBuilder.withExpect (Http.expectJson (accessTokenDecoder registration))
|
|> HttpBuilder.withExpect (Http.expectJson (accessTokenDecoder registration))
|
||||||
|> HttpBuilder.withJsonBody (authorizationCodeEncoder registration authCode)
|
|> HttpBuilder.withJsonBody (authorizationCodeEncoder registration authCode)
|
||||||
|
|
||||||
|
@ -112,66 +130,79 @@ send tagger builder =
|
||||||
|
|
||||||
fetchAccount : Client -> Int -> Request Account
|
fetchAccount : Client -> Int -> Request Account
|
||||||
fetchAccount client accountId =
|
fetchAccount client accountId =
|
||||||
fetch client (ApiUrl.account accountId) accountDecoder
|
fetch GET client (ApiUrl.account accountId) accountDecoder
|
||||||
|
|
||||||
|
|
||||||
fetchUserTimeline : Client -> Request (List Status)
|
fetchUserTimeline : Client -> Request (List Status)
|
||||||
fetchUserTimeline client =
|
fetchUserTimeline client =
|
||||||
fetch client ApiUrl.homeTimeline <| Decode.list statusDecoder
|
fetch GET client ApiUrl.homeTimeline <| Decode.list statusDecoder
|
||||||
|
|
||||||
|
|
||||||
fetchRelationships : Client -> List Int -> Request (List Relationship)
|
fetchRelationships : Client -> List Int -> Request (List Relationship)
|
||||||
fetchRelationships client ids =
|
fetchRelationships client ids =
|
||||||
fetch client (ApiUrl.relationships ids) <| Decode.list relationshipDecoder
|
-- TODO: use withQueryParams
|
||||||
|
fetch GET client (ApiUrl.relationships ids) <| Decode.list relationshipDecoder
|
||||||
|
|
||||||
|
|
||||||
fetchLocalTimeline : Client -> Request (List Status)
|
fetchLocalTimeline : Client -> Request (List Status)
|
||||||
fetchLocalTimeline client =
|
fetchLocalTimeline client =
|
||||||
fetch client (ApiUrl.publicTimeline (Just "public")) <| Decode.list statusDecoder
|
-- TODO: use withQueryParams
|
||||||
|
fetch GET client (ApiUrl.publicTimeline (Just "public")) <| Decode.list statusDecoder
|
||||||
|
|
||||||
|
|
||||||
fetchGlobalTimeline : Client -> Request (List Status)
|
fetchGlobalTimeline : Client -> Request (List Status)
|
||||||
fetchGlobalTimeline client =
|
fetchGlobalTimeline client =
|
||||||
fetch client (ApiUrl.publicTimeline (Nothing)) <| Decode.list statusDecoder
|
-- TODO: use withQueryParams
|
||||||
|
fetch GET client (ApiUrl.publicTimeline (Nothing)) <| Decode.list statusDecoder
|
||||||
|
|
||||||
|
|
||||||
fetchAccountTimeline : Client -> Int -> Request (List Status)
|
fetchAccountTimeline : Client -> Int -> Request (List Status)
|
||||||
fetchAccountTimeline client id =
|
fetchAccountTimeline client id =
|
||||||
fetch client (ApiUrl.accountTimeline id) <| Decode.list statusDecoder
|
fetch GET client (ApiUrl.accountTimeline id) <| Decode.list statusDecoder
|
||||||
|
|
||||||
|
|
||||||
fetchNotifications : Client -> Request (List Notification)
|
fetchNotifications : Client -> Request (List Notification)
|
||||||
fetchNotifications client =
|
fetchNotifications client =
|
||||||
fetch client (ApiUrl.notifications) <| Decode.list notificationDecoder
|
fetch GET client (ApiUrl.notifications) <| Decode.list notificationDecoder
|
||||||
|
|
||||||
|
|
||||||
fetchAccountFollowers : Client -> Int -> Request (List Account)
|
fetchAccountFollowers : Client -> Int -> Request (List Account)
|
||||||
fetchAccountFollowers client accountId =
|
fetchAccountFollowers client accountId =
|
||||||
fetch client (ApiUrl.followers accountId) <| Decode.list accountDecoder
|
fetch GET client (ApiUrl.followers accountId) <| Decode.list accountDecoder
|
||||||
|
|
||||||
|
|
||||||
fetchAccountFollowing : Client -> Int -> Request (List Account)
|
fetchAccountFollowing : Client -> Int -> Request (List Account)
|
||||||
fetchAccountFollowing client accountId =
|
fetchAccountFollowing client accountId =
|
||||||
fetch client (ApiUrl.following accountId) <| Decode.list accountDecoder
|
fetch GET client (ApiUrl.following accountId) <| Decode.list accountDecoder
|
||||||
|
|
||||||
|
|
||||||
searchAccounts : Client -> String -> Int -> Bool -> Request (List Account)
|
searchAccounts : Client -> String -> Int -> Bool -> Request (List Account)
|
||||||
searchAccounts client query limit resolve =
|
searchAccounts client query limit resolve =
|
||||||
HttpBuilder.get (ApiUrl.searchAccount client.server query limit resolve)
|
HttpBuilder.get (client.server ++ ApiUrl.searchAccount)
|
||||||
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
||||||
|> HttpBuilder.withExpect (Http.expectJson (Decode.list accountDecoder))
|
|> HttpBuilder.withExpect (Http.expectJson (Decode.list accountDecoder))
|
||||||
|
|> HttpBuilder.withQueryParams
|
||||||
|
[ ( "q", query )
|
||||||
|
, ( "limit", toString limit )
|
||||||
|
, ( "resolve"
|
||||||
|
, if resolve then
|
||||||
|
"true"
|
||||||
|
else
|
||||||
|
"false"
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
userAccount : Client -> Request Account
|
userAccount : Client -> Request Account
|
||||||
userAccount client =
|
userAccount client =
|
||||||
HttpBuilder.get (ApiUrl.userAccount client.server)
|
HttpBuilder.get (client.server ++ ApiUrl.userAccount)
|
||||||
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
||||||
|> HttpBuilder.withExpect (Http.expectJson accountDecoder)
|
|> HttpBuilder.withExpect (Http.expectJson accountDecoder)
|
||||||
|
|
||||||
|
|
||||||
postStatus : Client -> StatusRequestBody -> Request Status
|
postStatus : Client -> StatusRequestBody -> Request Status
|
||||||
postStatus client statusRequestBody =
|
postStatus client statusRequestBody =
|
||||||
HttpBuilder.post (ApiUrl.statuses client.server)
|
HttpBuilder.post (client.server ++ ApiUrl.statuses)
|
||||||
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
||||||
|> HttpBuilder.withExpect (Http.expectJson statusDecoder)
|
|> HttpBuilder.withExpect (Http.expectJson statusDecoder)
|
||||||
|> HttpBuilder.withJsonBody (statusRequestBodyEncoder statusRequestBody)
|
|> HttpBuilder.withJsonBody (statusRequestBodyEncoder statusRequestBody)
|
||||||
|
@ -179,55 +210,55 @@ postStatus client statusRequestBody =
|
||||||
|
|
||||||
deleteStatus : Client -> Int -> Request Int
|
deleteStatus : Client -> Int -> Request Int
|
||||||
deleteStatus client id =
|
deleteStatus client id =
|
||||||
HttpBuilder.delete (ApiUrl.status client.server id)
|
HttpBuilder.delete (client.server ++ (ApiUrl.status id))
|
||||||
|> HttpBuilder.withExpect (Http.expectJson <| Decode.succeed id)
|
|> HttpBuilder.withExpect (Http.expectJson <| Decode.succeed id)
|
||||||
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
||||||
|
|
||||||
|
|
||||||
context : Client -> Int -> Request Context
|
context : Client -> Int -> Request Context
|
||||||
context client id =
|
context client id =
|
||||||
HttpBuilder.get (ApiUrl.context client.server id)
|
HttpBuilder.get (client.server ++ (ApiUrl.context id))
|
||||||
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
||||||
|> HttpBuilder.withExpect (Http.expectJson contextDecoder)
|
|> HttpBuilder.withExpect (Http.expectJson contextDecoder)
|
||||||
|
|
||||||
|
|
||||||
reblog : Client -> Int -> Request Status
|
reblog : Client -> Int -> Request Status
|
||||||
reblog client id =
|
reblog client id =
|
||||||
HttpBuilder.post (ApiUrl.reblog client.server id)
|
HttpBuilder.post (client.server ++ (ApiUrl.reblog id))
|
||||||
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
||||||
|> HttpBuilder.withExpect (Http.expectJson statusDecoder)
|
|> HttpBuilder.withExpect (Http.expectJson statusDecoder)
|
||||||
|
|
||||||
|
|
||||||
unreblog : Client -> Int -> Request Status
|
unreblog : Client -> Int -> Request Status
|
||||||
unreblog client id =
|
unreblog client id =
|
||||||
HttpBuilder.post (ApiUrl.unreblog client.server id)
|
HttpBuilder.post (client.server ++ (ApiUrl.unreblog id))
|
||||||
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
||||||
|> HttpBuilder.withExpect (Http.expectJson statusDecoder)
|
|> HttpBuilder.withExpect (Http.expectJson statusDecoder)
|
||||||
|
|
||||||
|
|
||||||
favourite : Client -> Int -> Request Status
|
favourite : Client -> Int -> Request Status
|
||||||
favourite client id =
|
favourite client id =
|
||||||
HttpBuilder.post (ApiUrl.favourite client.server id)
|
HttpBuilder.post (client.server ++ (ApiUrl.favourite id))
|
||||||
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
||||||
|> HttpBuilder.withExpect (Http.expectJson statusDecoder)
|
|> HttpBuilder.withExpect (Http.expectJson statusDecoder)
|
||||||
|
|
||||||
|
|
||||||
unfavourite : Client -> Int -> Request Status
|
unfavourite : Client -> Int -> Request Status
|
||||||
unfavourite client id =
|
unfavourite client id =
|
||||||
HttpBuilder.post (ApiUrl.unfavourite client.server id)
|
HttpBuilder.post (client.server ++ (ApiUrl.unfavourite id))
|
||||||
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
||||||
|> HttpBuilder.withExpect (Http.expectJson statusDecoder)
|
|> HttpBuilder.withExpect (Http.expectJson statusDecoder)
|
||||||
|
|
||||||
|
|
||||||
follow : Client -> Int -> Request Relationship
|
follow : Client -> Int -> Request Relationship
|
||||||
follow client id =
|
follow client id =
|
||||||
HttpBuilder.post (ApiUrl.follow client.server id)
|
HttpBuilder.post (client.server ++ (ApiUrl.follow id))
|
||||||
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
||||||
|> HttpBuilder.withExpect (Http.expectJson relationshipDecoder)
|
|> HttpBuilder.withExpect (Http.expectJson relationshipDecoder)
|
||||||
|
|
||||||
|
|
||||||
unfollow : Client -> Int -> Request Relationship
|
unfollow : Client -> Int -> Request Relationship
|
||||||
unfollow client id =
|
unfollow client id =
|
||||||
HttpBuilder.post (ApiUrl.unfollow client.server id)
|
HttpBuilder.post (client.server ++ (ApiUrl.unfollow id))
|
||||||
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
|> HttpBuilder.withHeader "Authorization" ("Bearer " ++ client.token)
|
||||||
|> HttpBuilder.withExpect (Http.expectJson relationshipDecoder)
|
|> HttpBuilder.withExpect (Http.expectJson relationshipDecoder)
|
||||||
|
|
|
@ -54,7 +54,7 @@ subscribeToWebSockets client streamType message =
|
||||||
|
|
||||||
url =
|
url =
|
||||||
encodeUrl
|
encodeUrl
|
||||||
(ApiUrl.streaming (replaceSlice "wss" 0 5 client.server))
|
(replaceSlice "wss" 0 5 <| client.server ++ ApiUrl.streaming)
|
||||||
[ ( "access_token", client.token )
|
[ ( "access_token", client.token )
|
||||||
, ( "stream", type_ )
|
, ( "stream", type_ )
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue