Skip to content

Commit

Permalink
readme fix and minor other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas hadin committed Sep 25, 2014
1 parent d0e859e commit 8ad43d3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,50 @@ diversity-api
=============

An erlang diversity api server

Configuration
-------------

Before compiling you need to configure where the git repos should be cloned to, the credentials to diversity.io and
what port to use for the api server. This is currently done in the `rel/sys.config` file:

``` rel/sys.config
[{
divapi, [{repo_dir, "path/to/your/directory"},
{token, "s3cr3tt0k3n"},
{port, 8181}]
}].
```

The token can be obtained in your Account settings page on diversity.io (`Profile settings -> Account`)

Building
--------

`make` - Compiles and builds a release in _rel/divapi_release/

Running
-------

`./_rel/divapi_release/bin/divapi_release start` - start the server
`./_rel/divapi_release/bin/divapi_release stop` - stop the server


Usage/Routes
------------

`/components/<component>/` - Lists all tagged versions of the component
`/components/` - Lists information of all public components on diversity.io
`/components/?grouping=sidebar` - Lists all components that have sidebar configured in their grouping attribute.

`/components/<component>/1.2.3/` - diversity.json from component with version 1.2.3
`/components/<component>/1.2/` - diversity.json from latest patch-version of component 1.2.*
`/components/<component>/*/` - diversity.json from latest version of the component

`/components/<component>/1.2.3/settings` - settings attribute from the diversity.json from component with version 1.2.3
`/components/<component>/1.2.3/settingsForm` - settingsForm attribute from the diversity.json from component with version 1.2.3
`/components/<component>/1.2.3/files/path/to/file.js` - Gets the file file.js

Note: All the version selection methods can be used to get settings, settingsForm and files from the selected version.


5 changes: 3 additions & 2 deletions rel/sys.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[{
divapi, [{repo_dir, ""},
{token, ""}]
divapi, [{repo_dir, ""}, %% Path to your directory
{token, ""}, %% Token from your diversity.io account
{port, 8181}] %% Port to run the server on
}].
2 changes: 1 addition & 1 deletion src/component_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ handle_get(Req, _State=#state{}) ->
end,
{ok, Req4}.

expand_tag(<<"*">>, Tags) -> find_latest_tag(Tags);
expand_tag(<<"*/">>, Tags) -> find_latest_tag(Tags);
expand_tag(Tag, Tags) ->
case lists:member(Tag, Tags) of
true ->
Expand Down
4 changes: 2 additions & 2 deletions src/divapi_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
-export([start/2]).
-export([stop/1]).

-define(PORT, 8181).

start(_Type, _Args) ->
inets:start(),
Expand All @@ -14,7 +13,8 @@ start(_Type, _Args) ->
Dispatch = cowboy_router:compile([
{'_', Routes}
]),
cowboy:start_http(diversity_api_listener, 100, [{port, ?PORT}],
{ok, Port} = application:get_env(divapi, port),
cowboy:start_http(diversity_api_listener, 100, [{port, Port}],
[{env, [{dispatch, Dispatch}]}]
),
divapi_cache:start_link(),
Expand Down
2 changes: 1 addition & 1 deletion src/git_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ get_git_result(RepoName, RepoUrl, Cmd) ->

clone_bare(RepoUrl) ->
{ok, RepoDir} = application:get_env(divapi, repo_dir),
filelib:ensure_dir(RepoDir),
filelib:ensure_dir(RepoDir ++ "/"),
file:set_cwd(RepoDir),
Cmd = "clone --bare " ++ RepoUrl,
git_cmd(Cmd).
Expand Down

0 comments on commit 8ad43d3

Please sign in to comment.