-module(slack_webhook_client@operations). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/slack_webhook_client/operations.gleam"). -export([post_webhook_request/2, post_webhook_response/1]). -export_type([bad_u_r_l/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -type bad_u_r_l() :: {bad_u_r_l, binary()}. -file("src/slack_webhook_client/operations.gleam", 16). ?DOC( " Generate a POST request\n" " \n" " The request can be passed to\n" " \n" " httpc.send_bits()\n" ). -spec post_webhook_request(binary(), gleam@json:json()) -> {ok, gleam@http@request:request(bitstring())} | {error, bad_u_r_l()}. post_webhook_request(Webhook_url, Payload) -> case gleam@http@request:to(Webhook_url) of {ok, Req} -> Body = begin _pipe = Payload, _pipe@1 = gleam@json:to_string(_pipe), gleam_stdlib:identity(_pipe@1) end, _pipe@2 = Req, _pipe@3 = gleam@http@request:set_method(_pipe@2, post), _pipe@4 = gleam@http@request:set_header( _pipe@3, <<"content-type"/utf8>>, <<"application/json"/utf8>> ), _pipe@5 = gleam@http@request:set_body(_pipe@4, Body), {ok, _pipe@5}; {error, nil} -> {error, {bad_u_r_l, Webhook_url}} end. -file("src/slack_webhook_client/operations.gleam", 41). ?DOC( " Verify the response\n" " \n" " Workflow:\n" " \n" " webhook_url\n" " |> post_webhook_request()\n" " |> result.then(httpc.send_bits)\n" " |> result.then(post_webhook_response)\n" ). -spec post_webhook_response(gleam@http@response:response(bitstring())) -> {ok, integer()} | {error, gleam@http@response:response(bitstring())}. post_webhook_response(Response) -> case Response of {response, Status, _, _} when (Status >= 200) andalso (Status =< 204) -> {ok, Status}; _ -> {error, Response} end.