-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
79 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import gleam/http.{Https} | ||
import gleam/http/request.{type Request} | ||
import gleam/json.{type Json} | ||
|
||
pub type TwitchApiRequest = | ||
Request(String) | ||
|
||
const host = "api.twitch.tv/helix" | ||
|
||
pub fn from_request(request: Request(Json)) -> TwitchApiRequest { | ||
let body = | ||
request.body | ||
|> json.to_string | ||
|
||
request | ||
|> request.set_scheme(Https) | ||
|> request.set_host(host) | ||
|> request.set_body(body) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import gleam/dynamic.{type Decoder} | ||
import gleam/json | ||
import gleam/http/response.{type Response} | ||
import glitch/extended/function_ext | ||
|
||
pub type TwitchApiResponse(data) { | ||
TwitchApiResponse(data: List(data)) | ||
} | ||
|
||
fn decoder(of data_decoder: Decoder(data)) -> Decoder(TwitchApiResponse(data)) { | ||
dynamic.decode1( | ||
TwitchApiResponse, | ||
dynamic.field("data", dynamic.list(of: data_decoder)), | ||
) | ||
} | ||
|
||
pub fn from_json(json_string: String, of data_decoder: Decoder(data)) { | ||
json.decode(json_string, decoder(data_decoder)) | ||
} | ||
|
||
pub fn get_data(api_response: TwitchApiResponse(data)) -> List(data) { | ||
api_response.data | ||
} | ||
|
||
pub fn get_data_from_response( | ||
response: Response(TwitchApiResponse(data)), | ||
) -> Result(Response(List(data)), error) { | ||
response | ||
|> response.try_map(function_ext.compose(get_data, Ok)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters