Skip to content

Commit

Permalink
update to rebar3
Browse files Browse the repository at this point in the history
  • Loading branch information
tsloughter committed Jun 26, 2015
1 parent 6a7eec9 commit 19eec4c
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 134 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.rebar
_build
.eunit
deps
priv
Expand Down
93 changes: 0 additions & 93 deletions Makefile

This file was deleted.

7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ Build and Run
-------------

```shell
$ make

$ make shell
./rebar compile
$ ./rebar3 shell
==> mimetypes (compile)
==> hackney (compile)
==> jsx (compile)
Expand Down Expand Up @@ -71,5 +68,5 @@ $ bin/elasticsearch -f
Run Common Test:
```bash
$ make ct
$ ./rebar3 ct
```
Binary file removed rebar
Binary file not shown.
8 changes: 1 addition & 7 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@

{erl_opts, [debug_info]}.

{deps_dir, ["deps"]}.

{deps, [
{hackney, "0.13.1", {git, "https://github.com/benoitc/hackney.git", {tag, "0.13.1"}}}
,{jsx, "1.4.5", {git, "https://github.com/talentdeficit/jsx.git", {tag, "v1.4.5"}}}
]}.
{deps, [hackney, jsx]}.
4 changes: 4 additions & 0 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[{<<"idna">>,{pkg,<<"idna">>,<<"1.0.2">>},1},
{<<"ssl_verify_hostname">>,{pkg,<<"ssl_verify_hostname">>,<<"1.0.5">>},1},
{<<"jsx">>,{pkg,<<"jsx">>,<<"2.6.2">>},0},
{<<"hackney">>,{pkg,<<"hackney">>,<<"1.1.0">>},0}].
Binary file added rebar3
Binary file not shown.
12 changes: 8 additions & 4 deletions src/erlastic_search.app.src
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
%% This is the application resource file (.app file) for the erlastic_search,
%% application.
{application, erlastic_search,
{application, erlastic_search,
[{description, "An Erlang app for communicating with Elastic Search's rest interface."},
{vsn, "0.3.1"},
{vsn, "1.0.0"},
{modules, []},
{registered,[]},
{applications, [kernel
,stdlib
,stdlib
,ssl
,hackney
,jsx]},
{start_phases, []}]}.
{start_phases, []},

{contributors, ["Tristan Sloughter"]},
{licenses, ["LGPL"]},
{links, [{"Github", "https://github.com/tsloughter/erlastic_search"}]}
]}.
27 changes: 13 additions & 14 deletions src/erlastic_search.erl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ create_index(Index) ->
%% details to create and sends the request to Elastic Search.
%% @end
%%--------------------------------------------------------------------
-spec create_index(record(erls_params), binary()) -> {ok, list()} | {error, any()}.
-spec create_index(#erls_params{}, binary()) -> {ok, list()} | {error, any()}.
create_index(Params, Index) ->
erls_resource:put(Params, Index, [], [], [], Params#erls_params.http_client_options).

Expand Down Expand Up @@ -105,8 +105,8 @@ stats_index(Params, Index) ->
put_mapping(Index, Type, Doc) ->
put_mapping(#erls_params{}, Index, Type, Doc).

-spec put_mapping(record(erls_params), binary(), binary(), list() | binary()) -> {ok, list()} | {error, any()}.
put_mapping(Params, Index, Type, Doc) ->
-spec put_mapping(#erls_params{}, binary(), binary(), list() | binary()) -> {ok, list()} | {error, any()}.
put_mapping(Params, Index, Type, Doc) ->
erls_resource:put(Params, filename:join([Index, Type, "_mapping"]), [], [], jsx:encode(Doc), Params#erls_params.http_client_options).

%%--------------------------------------------------------------------
Expand All @@ -120,7 +120,7 @@ put_mapping(Params, Index, Type, Doc) ->
index_doc(Index, Type, Doc) ->
index_doc(#erls_params{}, Index, Type, Doc).

-spec index_doc(record(erls_params), binary(), binary(), list() | binary()) -> {ok, list()} | {error, any()}.
-spec index_doc(#erls_params{}, binary(), binary(), list() | binary()) -> {ok, list()} | {error, any()}.
index_doc(Params, Index, Type, Doc) when is_list(Doc) ->
index_doc(Params, Index, Type, jsx:encode(Doc));
index_doc(Params, Index, Type, Doc) when is_binary(Doc) ->
Expand All @@ -137,11 +137,11 @@ index_doc(Params, Index, Type, Doc) when is_binary(Doc) ->
index_doc_with_id(Index, Type, Id, Doc) ->
index_doc_with_id_opts(#erls_params{}, Index, Type, Id, Doc, []).

-spec index_doc_with_id(record(erls_params), binary(), binary(), binary(), list() | binary()) -> {ok, list()} | {error, any()}.
-spec index_doc_with_id(#erls_params{}, binary(), binary(), binary(), list() | binary()) -> {ok, list()} | {error, any()}.
index_doc_with_id(Params, Index, Type, Id, Doc) ->
index_doc_with_id_opts(Params, Index, Type, Id, Doc, []).

-spec index_doc_with_id_opts(record(erls_params), binary(), binary(), binary(), list() | binary(), list()) -> {ok, list()} | {error, any()}.
-spec index_doc_with_id_opts(#erls_params{}, binary(), binary(), binary(), list() | binary(), list()) -> {ok, list()} | {error, any()}.
index_doc_with_id_opts(Params, Index, Type, Id, Doc, Opts) when is_list(Doc), is_list(Opts) ->
index_doc_with_id_opts(Params, Index, Type, Id, jsx:encode(Doc), []);
index_doc_with_id_opts(Params, Index, Type, Id, Doc, Opts) when is_binary(Doc), is_list(Opts) ->
Expand All @@ -157,18 +157,18 @@ index_doc_with_id_opts(Params, Index, Type, Id, Doc, Opts) when is_binary(Doc),
upsert_doc(Index, Type, Id, Doc) ->
upsert_doc_opts(#erls_params{}, Index, Type, Id, Doc, []).

-spec upsert_doc(record(erls_params), binary(), binary(), binary(), list() | binary()) -> {ok, list()} | {error, any()}.
-spec upsert_doc(#erls_params{}, binary(), binary(), binary(), list() | binary()) -> {ok, list()} | {error, any()}.
upsert_doc(Params, Index, Type, Id, Doc) ->
upsert_doc_opts(Params, Index, Type, Id, Doc, []).

-spec upsert_doc_opts(record(erls_params), binary(), binary(), binary(), list(), list()) -> {ok, list()} | {error, any()}.
-spec upsert_doc_opts(#erls_params{}, binary(), binary(), binary(), list(), list()) -> {ok, list()} | {error, any()}.
upsert_doc_opts(Params, Index, Type, Id, Doc, Opts) when is_list(Doc), is_list(Opts) ->
erls_resource:post(Params, filename:join([Index, Type, Id, "_update"]), [], Opts,
jsx:encode([{<<"doc">>, Doc}, {<<"doc_as_upsert">>, true}]),
Params#erls_params.http_client_options).

%% Documents is [ {Index, Type, Id, Json}, ... ]
-spec bulk_index_docs(record(erls_params), list()) -> {ok, list()} | {error, any()}.
-spec bulk_index_docs(#erls_params{}, list()) -> {ok, list()} | {error, any()}.
bulk_index_docs(Params, IndexTypeIdJsonTuples) ->
Body = lists:map(fun({Index, Type, Id, Doc}) when is_binary(Doc) ->
Header = jsx:encode([
Expand Down Expand Up @@ -200,17 +200,17 @@ bulk_index_docs(Params, IndexTypeIdJsonTuples) ->
search(Index, Query) ->
search(#erls_params{}, Index, <<>>, Query, []).

-spec search(binary() | list() | record(erls_params), binary() | list(), list() | binary()) -> {ok, list()} | {error, any()}.
-spec search(binary() | list() | #erls_params{}, binary() | list(), list() | binary()) -> {ok, list()} | {error, any()}.
search(Params, Index, Query) when is_record(Params, erls_params) ->
search(Params, Index, <<>>, Query, []);
search(Index, Type, Query) ->
search(#erls_params{}, Index, Type, Query, []).
search(#erls_params{}, Index, Type, Query, []).

-spec search_limit(binary() | list(), binary(), list() | binary(), integer()) -> {ok, list()} | {error, any()}.
search_limit(Index, Type, Query, Limit) when is_integer(Limit) ->
search(#erls_params{}, Index, Type, Query, [{<<"size">>, integer_to_list(Limit)}]).

-spec search(record(erls_params), list() | binary(), list() | binary(), list() | binary(), list()) -> {ok, list()} | {error, any()}.
-spec search(#erls_params{}, list() | binary(), list() | binary(), list() | binary(), list()) -> {ok, list()} | {error, any()}.
search(Params, Index, Type, Query, Opts) when is_binary(Query) ->
erls_resource:get(Params, filename:join([commas(Index), Type, <<"_search">>]), [], [{<<"q">>, Query}]++Opts, Params#erls_params.http_client_options);
search(Params, Index, Type, Query, Opts) ->
Expand All @@ -232,7 +232,7 @@ get_doc(Index, Type, Id) ->
%% it to the Elastic Search server specified in Params.
%% @end
%%--------------------------------------------------------------------
-spec get_doc(record(erls_params), binary(), binary(), binary()) -> {ok, list()} | {error, any()}.
-spec get_doc(#erls_params{}, binary(), binary(), binary()) -> {ok, list()} | {error, any()}.
get_doc(Params, Index, Type, Id) ->
erls_resource:get(Params, filename:join([Index, Type, Id]), [], [], Params#erls_params.http_client_options).

Expand Down Expand Up @@ -326,4 +326,3 @@ commas([]) ->
<<>>;
commas([H | T]) ->
<< H/binary, << <<",", B/binary>> || B <- T >> >>.

2 changes: 0 additions & 2 deletions src/erls_resource.erl
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,3 @@ default_content_length(B, H) ->

make_body(Body, Headers, Options) ->
{default_content_length(Body, Headers), Options, Body}.


10 changes: 1 addition & 9 deletions test/basic_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ search(Config) ->
%%% Helper Functions
%%%===================================================================

compare_json(J1, J2) ->
sort(jsx:decode(J1)) == sort(jsx:decode(J2)).

sort(L = [X | _]) when is_list(X) ->
[sort(Y) || Y <- L];
sort(L = [X | _]) when is_tuple(X)->
lists:keysort(1, L).

create_random_name(Name) ->
random:seed(erlang:now()),
random:seed(os:timestamp()),
<<Name/binary, (list_to_binary(erlang:integer_to_list(random:uniform(1000000))))/binary>>.

0 comments on commit 19eec4c

Please sign in to comment.