fix directory structure
This commit is contained in:
parent
faba419c39
commit
ec177f2b60
4 changed files with 17 additions and 12 deletions
|
@ -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...")
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
Loading…
Reference in a new issue