fix directory structure

This commit is contained in:
lewdum 2024-10-22 18:59:01 -03:00
parent faba419c39
commit ec177f2b60
No known key found for this signature in database
4 changed files with 17 additions and 12 deletions

View file

@ -1,6 +1,7 @@
import apkallone
import gleam/io
import mastodon/instance
import apkallone
import apkallone/mastodon/instance
pub fn main() {
io.println_error("Fetching...")

View file

@ -3,7 +3,6 @@ import gleam/http/request.{type Request}
import gleam/http/response.{type Response}
import gleam/httpc
import gleam/json
import gleam/pair
import gleam/result
import gleam/string
@ -48,21 +47,26 @@ pub fn decode_response(
fn require_content_type(
res: Response(String),
expected_type: String,
content_type: String,
fun: fn() -> Result(a, Error),
) -> Result(a, Error) {
use actual_type <- result.try(
use actual_content_type <- result.try(
response.get_header(res, "content-type")
|> result.replace_error(apkallone.MissingContentType),
)
let actual_type =
string.split_once(actual_type, on: ";")
|> result.map(pair.first)
|> result.unwrap(or: actual_type)
let actual_content_type =
strip_parameters_from_content_type(actual_content_type)
case actual_type == expected_type {
case actual_content_type == content_type {
True -> fun()
False -> Error(apkallone.UnexpectedContentType(actual_type))
False -> Error(apkallone.UnexpectedContentType(actual_content_type))
}
}
fn strip_parameters_from_content_type(content_type: String) -> String {
case string.split_once(content_type, on: ";") {
Ok(#(before_parameters, _parameters)) -> before_parameters
Error(Nil) -> content_type
}
}

View file

@ -2,7 +2,7 @@ import gleam/result
import apkallone
import apkallone/internal
import mastodon/model/instance.{type Instance}
import apkallone/mastodon/model/instance.{type Instance}
pub fn get_instance(
client: apkallone.Client,