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 gleam/io
|
||||||
import mastodon/instance
|
|
||||||
|
import apkallone
|
||||||
|
import apkallone/mastodon/instance
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
io.println_error("Fetching...")
|
io.println_error("Fetching...")
|
||||||
|
|
|
@ -3,7 +3,6 @@ import gleam/http/request.{type Request}
|
||||||
import gleam/http/response.{type Response}
|
import gleam/http/response.{type Response}
|
||||||
import gleam/httpc
|
import gleam/httpc
|
||||||
import gleam/json
|
import gleam/json
|
||||||
import gleam/pair
|
|
||||||
import gleam/result
|
import gleam/result
|
||||||
import gleam/string
|
import gleam/string
|
||||||
|
|
||||||
|
@ -48,21 +47,26 @@ pub fn decode_response(
|
||||||
|
|
||||||
fn require_content_type(
|
fn require_content_type(
|
||||||
res: Response(String),
|
res: Response(String),
|
||||||
expected_type: String,
|
content_type: String,
|
||||||
fun: fn() -> Result(a, Error),
|
fun: fn() -> Result(a, Error),
|
||||||
) -> Result(a, Error) {
|
) -> Result(a, Error) {
|
||||||
use actual_type <- result.try(
|
use actual_content_type <- result.try(
|
||||||
response.get_header(res, "content-type")
|
response.get_header(res, "content-type")
|
||||||
|> result.replace_error(apkallone.MissingContentType),
|
|> result.replace_error(apkallone.MissingContentType),
|
||||||
)
|
)
|
||||||
|
|
||||||
let actual_type =
|
let actual_content_type =
|
||||||
string.split_once(actual_type, on: ";")
|
strip_parameters_from_content_type(actual_content_type)
|
||||||
|> result.map(pair.first)
|
|
||||||
|> result.unwrap(or: actual_type)
|
|
||||||
|
|
||||||
case actual_type == expected_type {
|
case actual_content_type == content_type {
|
||||||
True -> fun()
|
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
|
||||||
import apkallone/internal
|
import apkallone/internal
|
||||||
import mastodon/model/instance.{type Instance}
|
import apkallone/mastodon/model/instance.{type Instance}
|
||||||
|
|
||||||
pub fn get_instance(
|
pub fn get_instance(
|
||||||
client: apkallone.Client,
|
client: apkallone.Client,
|
Loading…
Reference in a new issue