-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1aabca9
Showing
13 changed files
with
1,504 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ebin/*.beam | ||
ebin/*.app | ||
agner | ||
scripts | ||
deps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
all: compile | ||
|
||
deps: | ||
@./rebar get-deps | ||
|
||
compile: deps | ||
@./rebar compile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-type agner_spec_name() :: string() | atom(). | ||
-type agner_spec_version() :: string(). | ||
|
||
-type agner_key() :: term(). | ||
-type agner_value() :: term(). | ||
-type agner_spec() :: list({agner_key(), agner_value()}). |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{compile_post_script, "./scripts/escriptize"}. | ||
{deps, [ | ||
{typespecs, "0.1", {git, "git://github.com/spawngrid/typespecs.git", | ||
"HEAD"}} | ||
]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{application, agner, | ||
[ | ||
{description, ""}, | ||
{vsn, "0.1"}, | ||
{registered, []}, | ||
{applications, [ | ||
kernel, | ||
stdlib, | ||
inets | ||
]}, | ||
{env, [{github_accounts, ["agner"]}]}, | ||
{mod, { agner_app, []}}, | ||
{env, []} | ||
]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-module(agner). | ||
-include_lib("agner.hrl"). | ||
-export([start/0,stop/0]). | ||
-export([main/1]). | ||
%% API | ||
-export([spec/1, spec/2]). | ||
|
||
start() -> | ||
inets:start(), | ||
ssl:start(), | ||
{ok, _Pid} = inets:start(httpc,[{profile, agner}]), | ||
application:start(agner). | ||
|
||
stop() -> | ||
application:stop(agner), | ||
inets:stop(), | ||
ssl:stop(). | ||
|
||
main(_) -> | ||
start(), | ||
stop(). | ||
|
||
%%%=================================================================== | ||
%%% API | ||
%%%=================================================================== | ||
-spec spec(agner_spec_name()) -> agner_spec(). | ||
-spec spec(agner_spec_name(), agner_spec_version()) -> agner_spec(). | ||
|
||
spec(Name) -> | ||
spec(Name, master). | ||
|
||
spec(Name, Version) when is_atom(Name) -> | ||
spec(atom_to_list(Name),Version); | ||
|
||
spec(Name, Version) -> | ||
gen_server:call(agner_server, {spec, Name, Version}). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-module(agner_app). | ||
|
||
-behaviour(application). | ||
|
||
%% Application callbacks | ||
-export([start/2, stop/1]). | ||
|
||
%% =================================================================== | ||
%% Application callbacks | ||
%% =================================================================== | ||
|
||
start(_StartType, _StartArgs) -> | ||
agner_sup:start_link(). | ||
|
||
stop(_State) -> | ||
ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
-module(agner_github). | ||
-export([list_all_repos/0, | ||
list_tags/1, | ||
list_branches/1, | ||
blob/3 | ||
]). | ||
|
||
list_all_repos() -> | ||
request("https://github.com/api/v2/json/repos/show/agner"). | ||
|
||
list_tags(Name) -> | ||
request("http://github.com/api/v2/json/repos/show/agner/" ++ Name ++ "/tags"). | ||
|
||
list_branches(Name) -> | ||
request("http://github.com/api/v2/json/repos/show/agner/" ++ Name ++ "/branches"). | ||
|
||
blob(Name, SHA1, Path) -> | ||
request("http://github.com/api/v2/json/blob/show/agner/" ++ Name ++ "/" ++ SHA1 ++ "/" ++ Path). | ||
|
||
%%% | ||
|
||
request(URL) -> | ||
parse_response(httpc_request(URL)). | ||
|
||
httpc_request(URL) -> | ||
httpc_request_1(URL,[]). | ||
|
||
httpc_request_1(URL, Opts) -> | ||
httpc:request(get,{URL, | ||
[]}, | ||
[{timeout, 60000}], | ||
Opts, | ||
agner). | ||
parse_response({ok, {{"HTTP/1.1",200,_},_Header,Body}}) -> | ||
mochijson2:decode(Body). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
-module(agner_server). | ||
-include_lib("agner.hrl"). | ||
-include_lib("typespecs/include/typespecs.hrl"). | ||
-behaviour(gen_server). | ||
|
||
%% API | ||
-export([start_link/0]). | ||
|
||
%% gen_server callbacks | ||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, | ||
terminate/2, code_change/3]). | ||
|
||
-define(SERVER, ?MODULE). | ||
|
||
|
||
-record(state, {}). | ||
|
||
-type gen_server_state() :: #state{}. | ||
|
||
%%%=================================================================== | ||
%%% API | ||
%%%=================================================================== | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @doc | ||
%% Starts the server | ||
%% | ||
%% @spec start_link() -> {ok, Pid} | ignore | {error, Error} | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
start_link() -> | ||
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). | ||
|
||
%%%=================================================================== | ||
%%% gen_server callbacks | ||
%%%=================================================================== | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @private | ||
%% @doc | ||
%% Initializes the server | ||
%% | ||
%% @spec init(Args) -> {ok, State} | | ||
%% {ok, State, Timeout} | | ||
%% ignore | | ||
%% {stop, Reason} | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
-spec init([]) -> gen_server_init_result(). | ||
|
||
init([]) -> | ||
{ok, #state{}}. | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @private | ||
%% @doc | ||
%% Handling call messages | ||
%% | ||
%% @spec handle_call(Request, From, State) -> | ||
%% {reply, Reply, State} | | ||
%% {reply, Reply, State, Timeout} | | ||
%% {noreply, State} | | ||
%% {noreply, State, Timeout} | | ||
%% {stop, Reason, Reply, State} | | ||
%% {stop, Reason, State} | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
-type agner_call_spec() :: {spec, agner_spec_name(), agner_spec_version()}. | ||
|
||
-spec handle_call(agner_call_spec(), gen_server_from(), gen_server_state()) -> | ||
gen_server_async_reply(agner_spec()). | ||
|
||
handle_call({spec, Name0, Version}, From, #state{}=State) -> | ||
Name = Name0 ++ ".agner", | ||
spawn_link(fun () -> | ||
SHA1 = | ||
case Version of | ||
master -> | ||
{struct, [{<<"branches">>, {struct, PL}}]} = agner_github:list_branches(Name), | ||
binary_to_list(proplists:get_value(<<"master">>, PL)); | ||
_ -> | ||
{struct, [{<<"tags">>, {struct, PL}}]} = agner_github:list_tags(Name), | ||
binary_to_list(proplists:get_value(list_to_binary(Name), PL)) | ||
end, | ||
{struct, [{<<"blob">>, {struct, PL1}}]} = agner_github:blob(Name, SHA1, "agner.config"), | ||
Data = proplists:get_value(<<"data">>, PL1), | ||
gen_server:reply(From, Data) | ||
end), | ||
{noreply, State}. | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @private | ||
%% @doc | ||
%% Handling cast messages | ||
%% | ||
%% @spec handle_cast(Msg, State) -> {noreply, State} | | ||
%% {noreply, State, Timeout} | | ||
%% {stop, Reason, State} | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
handle_cast(_Msg, State) -> | ||
{noreply, State}. | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @private | ||
%% @doc | ||
%% Handling all non call/cast messages | ||
%% | ||
%% @spec handle_info(Info, State) -> {noreply, State} | | ||
%% {noreply, State, Timeout} | | ||
%% {stop, Reason, State} | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
|
||
-spec handle_info(any(), gen_server_state()) -> | ||
gen_server_handle_info_result(). | ||
|
||
handle_info(_, State) -> | ||
{noreply, State}. | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @private | ||
%% @doc | ||
%% This function is called by a gen_server when it is about to | ||
%% terminate. It should be the opposite of Module:init/1 and do any | ||
%% necessary cleaning up. When it returns, the gen_server terminates | ||
%% with Reason. The return value is ignored. | ||
%% | ||
%% @spec terminate(Reason, State) -> void() | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
terminate(_Reason, _State) -> | ||
ok. | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @private | ||
%% @doc | ||
%% Convert process state when code is changed | ||
%% | ||
%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState} | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
code_change(_OldVsn, State, _Extra) -> | ||
{ok, State}. | ||
|
||
%%%=================================================================== | ||
%%% Internal functions | ||
%%%=================================================================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
-module(agner_sup). | ||
|
||
-behaviour(supervisor). | ||
|
||
%% API | ||
-export([start_link/0]). | ||
|
||
%% Supervisor callbacks | ||
-export([init/1]). | ||
|
||
%% Helper macro for declaring children of supervisor | ||
-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}). | ||
|
||
%% =================================================================== | ||
%% API functions | ||
%% =================================================================== | ||
|
||
start_link() -> | ||
supervisor:start_link({local, ?MODULE}, ?MODULE, []). | ||
|
||
%% =================================================================== | ||
%% Supervisor callbacks | ||
%% =================================================================== | ||
|
||
init([]) -> | ||
{ok, { {one_for_one, 5, 10}, [ | ||
?CHILD(agner_server, worker) | ||
]} }. | ||
|
Oops, something went wrong.