/
hex_api_organization.erl
66 lines (62 loc) · 1.84 KB
/
hex_api_organization.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-module(hex_api_organization).
-export([
get/1,
list/1,
update/2
]).
%% @doc
%% Lists all organizations you are member of.
%%
%% Examples:
%%
%% ```
%% > hex_api_organization:list(hex_core:default_config()#{api_organization => <<"acme">>}).
%% {ok, {200, ..., [#{
%% <<"billing_active">> => true,
%% <<"inserted_at">> => <<"2017-08-22T22:19:53Z">>,
%% <<"name">> => <<"acme">>,
%% <<"updated_at">> => <<"2019-01-18T08:47:29Z">>}
%% }]}}
%% '''
-spec list(hex_core:config()) -> hex_api:response().
list(Config) when is_map(Config) ->
hex_api:get(Config, ["orgs"]).
%% @doc
%% Gets an organzation.
%%
%% Examples:
%%
%% ```
%% > hex_api_organization:get(hex_core:default_config()#{api_organization => <<"acme">>}).
%% {ok, {200, ..., #{
%% <<"billing_active">> => true,
%% <<"inserted_at">> => <<"2017-08-22T22:19:53Z">>,
%% <<"name">> => <<"acme">>,
%% <<"seats">> => 42,
%% <<"updated_at">> => <<"2019-01-18T08:47:29Z">>}
%% }}}
%% '''
-spec get(hex_core:config()) -> hex_api:response().
get(Config) when is_map(Config) ->
Path = hex_api:build_organization_path(Config, []),
hex_api:get(Config, Path).
%% @doc
%% Updates the number of seats in an organzation.
%%
%% Examples:
%%
%% ```
%% > hex_api_organization:get(hex_core:default_config()#{api_organization => <<"acme">>}, 42).
%% {ok, {200, ..., #{
%% <<"billing_active">> => true,
%% <<"inserted_at">> => <<"2017-08-22T22:19:53Z">>,
%% <<"name">> => <<"acme">>,
%% <<"seats">> => 42,
%% <<"updated_at">> => <<"2019-01-18T08:47:29Z">>}
%% }}}
%% '''
-spec update(hex_core:config(), pos_integer()) -> hex_api:response().
update(Config, Seats) when is_map(Config) and is_integer(Seats)->
Path = hex_api:build_organization_path(Config, []),
Params = #{<<"seats">> => Seats},
hex_api:post(Config, Path, Params).