Current section
5 Versions
Jump to
Current section
5 Versions
Compare versions
12
files changed
+129
additions
-98
deletions
| @@ -1,5 +1,5 @@ | |
| 1 1 | name = "howdy" |
| 2 | - version = "0.1.2" |
| 2 | + version = "0.1.3" |
| 3 3 | |
| 4 4 | # Fill out these fields if you intend to generate HTML documentation or publish |
| 5 5 | # your project to the Hex package manager. |
| @@ -19,6 +19,7 @@ mimerl = "~> 1.2" | |
| 19 19 | howdy_uuid = "~> 0.1" |
| 20 20 | mist = "~> 0.4" |
| 21 21 | gleam_hackney = "~> 0.2" |
| 22 | + hackney = "~> 1.18" |
| 22 23 | |
| 23 24 | [dev-dependencies] |
| 24 25 | gleeunit = "~> 0.6" |
| @@ -1,6 +1,6 @@ | |
| 1 1 | {<<"name">>, <<"howdy">>}. |
| 2 2 | {<<"app">>, <<"howdy">>}. |
| 3 | - {<<"version">>, <<"0.1.2">>}. |
| 3 | + {<<"version">>, <<"0.1.3">>}. |
| 4 4 | {<<"description">>, <<"A simple and easy to use API created on top of the (Mist)[https://hex.pm/packages/mist] web server">>}. |
| 5 5 | {<<"licenses">>, [<<"Apache-2.0">>]}. |
| 6 6 | {<<"build_tools">>, [<<"gleam">>]}. |
| @@ -16,40 +16,45 @@ | |
| 16 16 | {<<"optional">>, false}, |
| 17 17 | {<<"requirement">>, <<"~> 0.2">>} |
| 18 18 | ]}, |
| 19 | - {<<"gleam_otp">>, [ |
| 20 | - {<<"app">>, <<"gleam_otp">>}, |
| 19 | + {<<"hackney">>, [ |
| 20 | + {<<"app">>, <<"hackney">>}, |
| 21 21 | {<<"optional">>, false}, |
| 22 | - {<<"requirement">>, <<"~> 0.4">>} |
| 23 | - ]}, |
| 24 | - {<<"howdy_uuid">>, [ |
| 25 | - {<<"app">>, <<"howdy_uuid">>}, |
| 26 | - {<<"optional">>, false}, |
| 27 | - {<<"requirement">>, <<"~> 0.1">>} |
| 28 | - ]}, |
| 29 | - {<<"gleam_json">>, [ |
| 30 | - {<<"app">>, <<"gleam_json">>}, |
| 31 | - {<<"optional">>, false}, |
| 32 | - {<<"requirement">>, <<"~> 0.4">>} |
| 22 | + {<<"requirement">>, <<"~> 1.18">>} |
| 33 23 | ]}, |
| 34 24 | {<<"gleam_http">>, [ |
| 35 25 | {<<"app">>, <<"gleam_http">>}, |
| 36 26 | {<<"optional">>, false}, |
| 37 27 | {<<"requirement">>, <<"~> 3.0">>} |
| 38 28 | ]}, |
| 39 | - {<<"gleam_erlang">>, [ |
| 40 | - {<<"app">>, <<"gleam_erlang">>}, |
| 29 | + {<<"gleam_otp">>, [ |
| 30 | + {<<"app">>, <<"gleam_otp">>}, |
| 41 31 | {<<"optional">>, false}, |
| 42 | - {<<"requirement">>, <<"~> 0.9">>} |
| 32 | + {<<"requirement">>, <<"~> 0.4">>} |
| 33 | + ]}, |
| 34 | + {<<"gleam_stdlib">>, [ |
| 35 | + {<<"app">>, <<"gleam_stdlib">>}, |
| 36 | + {<<"optional">>, false}, |
| 37 | + {<<"requirement">>, <<"~> 0.21">>} |
| 38 | + ]}, |
| 39 | + {<<"gleam_json">>, [ |
| 40 | + {<<"app">>, <<"gleam_json">>}, |
| 41 | + {<<"optional">>, false}, |
| 42 | + {<<"requirement">>, <<"~> 0.4">>} |
| 43 43 | ]}, |
| 44 44 | {<<"mimerl">>, [ |
| 45 45 | {<<"app">>, <<"mimerl">>}, |
| 46 46 | {<<"optional">>, false}, |
| 47 47 | {<<"requirement">>, <<"~> 1.2">>} |
| 48 48 | ]}, |
| 49 | - {<<"gleam_stdlib">>, [ |
| 50 | - {<<"app">>, <<"gleam_stdlib">>}, |
| 49 | + {<<"gleam_erlang">>, [ |
| 50 | + {<<"app">>, <<"gleam_erlang">>}, |
| 51 51 | {<<"optional">>, false}, |
| 52 | - {<<"requirement">>, <<"~> 0.21">>} |
| 52 | + {<<"requirement">>, <<"~> 0.9">>} |
| 53 | + ]}, |
| 54 | + {<<"howdy_uuid">>, [ |
| 55 | + {<<"app">>, <<"howdy_uuid">>}, |
| 56 | + {<<"optional">>, false}, |
| 57 | + {<<"requirement">>, <<"~> 0.1">>} |
| 53 58 | ]}, |
| 54 59 | {<<"mist">>, [ |
| 55 60 | {<<"app">>, <<"mist">>}, |
| @@ -1 +1 @@ | |
| 1 | - -record(user, {name :: binary(), claims :: gleam@map:map_(binary(), binary())}). |
| 1 | + -record(user, {name :: binary(), claims :: list({binary(), binary()})}). |
| @@ -1,5 +1,5 @@ | |
| 1 1 | {application, howdy, [ |
| 2 | - {vsn, "0.1.2"}, |
| 2 | + {vsn, "0.1.3"}, |
| 3 3 | {applications, [gleam_erlang, |
| 4 4 | gleam_hackney, |
| 5 5 | gleam_http, |
| @@ -7,6 +7,7 @@ | |
| 7 7 | gleam_otp, |
| 8 8 | gleam_stdlib, |
| 9 9 | gleeunit, |
| 10 | + hackney, |
| 10 11 | howdy_uuid, |
| 11 12 | mimerl, |
| 12 13 | mist]}, |
| @@ -1,17 +1,29 @@ | |
| 1 1 | //// helper functions to handle authenticated users. |
| 2 2 | |
| 3 | - import gleam/map.{Map} |
| 3 | + import gleam/option.{None, Option, Some} |
| 4 | + import gleam/list |
| 4 5 | |
| 5 6 | /// The user type to store the user information |
| 6 7 | pub type User { |
| 7 | - User(name: String, claims: Map(String, String)) |
| 8 | + User(name: String, claims: List(#(String, String))) |
| 8 9 | } |
| 9 10 | |
| 10 | - pub fn change_name(user: User, name: String) { |
| 11 | - User(..user, name: name) |
| 12 | - } |
| 13 | - |
| 14 | - pub fn add_claim(user: User, key: String, value: String) { |
| 15 | - let new_claims = map.insert(user.claims, key, value) |
| 16 | - User(..user, claims: new_claims) |
| 11 | + /// Returns the value of a claim. |
| 12 | + /// Either a Ok with the value or Error(Nil) if the |
| 13 | + /// key is not found within the claims. |
| 14 | + pub fn get_claim( |
| 15 | + user_option: Option(User), |
| 16 | + claim_key: String, |
| 17 | + ) -> Result(String, Nil) { |
| 18 | + case user_option { |
| 19 | + Some(user) -> |
| 20 | + user.claims |
| 21 | + |> list.find_map(fn(claim) { |
| 22 | + case claim.0 == claim_key { |
| 23 | + True -> Ok(claim.1) |
| 24 | + False -> Error(Nil) |
| 25 | + } |
| 26 | + }) |
| 27 | + None -> Error(Nil) |
| 28 | + } |
| 17 29 | } |
Loading more files…