From 70f2a5b28c516a262a74dea82bfbe80d041c4d19 Mon Sep 17 00:00:00 2001 From: Alexander Batischev Date: Fri, 16 Dec 2016 21:14:54 +0300 Subject: [PATCH] Prefix internal options with `octo` (#36) --- README.md | 6 +++--- src/helpers/octo_http_helper.erl | 2 +- src/helpers/octo_url_helper.erl | 2 +- test/octo_http_helper_test.erl | 4 ++-- test/octo_url_helper_test.erl | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8561c1d..6a03df3 100644 --- a/README.md +++ b/README.md @@ -345,7 +345,7 @@ GitHub API [paginates](https://en.wikipedia.org/wiki/Pagination) its responses wherever possible. octo.erl can either fetch all the pages for you in one call (effectively hiding pagination from you), or it can let you handle it yourself. -To make octo.erl fetch all the pages, read about `all_pages` option below. +To make octo.erl fetch all the pages, read about `octo_all_pages` option below. If you decided to consume pages one by one, here's how you do it: @@ -391,7 +391,7 @@ By default, GitHub returns 30 results per page. To change that to, say, 100 results per page, do the following: ```erlang -Options = [{per_page, 100}], +Options = [{octo_per_page, 100}], {ok, PullRequests} = octo:read_pull_request(Owner, Repo, Number, Options). ``` @@ -401,7 +401,7 @@ If you don't want to do the pagination manually, you can provide an option that resolves all pages automatically: ```erlang -Options = [all_pages], +Options = [octo_all_pages], {ok, PullRequests} = octo:read_pull_request(Owner, Repo, Number, Options). ``` diff --git a/src/helpers/octo_http_helper.erl b/src/helpers/octo_http_helper.erl index 82a27b9..6a4f43a 100644 --- a/src/helpers/octo_http_helper.erl +++ b/src/helpers/octo_http_helper.erl @@ -94,7 +94,7 @@ internal_read_collection(Url, Options, ProcessingFun, Acc) -> case Result of {ok, PrevResult} -> - case proplists:get_value(all_pages, Options) of + case proplists:get_value(octo_all_pages, Options) of true -> case octo_pagination_helper:get_url({next, Result}) of {ok, NextUrl} -> diff --git a/src/helpers/octo_url_helper.erl b/src/helpers/octo_url_helper.erl index ab9e55d..4df3151 100644 --- a/src/helpers/octo_url_helper.erl +++ b/src/helpers/octo_url_helper.erl @@ -78,7 +78,7 @@ options_to_query_params(Options) -> options_to_query_params([], Query) -> Query; -options_to_query_params([{ per_page, PerPage }|Rest], Query) -> +options_to_query_params([{ octo_per_page, PerPage }|Rest], Query) -> options_to_query_params(Rest, Query ++ ["per_page=" ++ integer_to_list(PerPage)]); options_to_query_params([_|Rest], Query) -> options_to_query_params(Rest, Query). diff --git a/test/octo_http_helper_test.erl b/test/octo_http_helper_test.erl index c47fce1..3ad8505 100644 --- a/test/octo_http_helper_test.erl +++ b/test/octo_http_helper_test.erl @@ -153,7 +153,7 @@ pagination_test_() -> ?assertEqual( {ok, [1,2,3]}, - octo_http_helper:read_collection(url, [all_pages], Id)), + octo_http_helper:read_collection(url, [octo_all_pages], Id)), ?assert(meck:validate(hackney)) end, fun() -> @@ -171,6 +171,6 @@ pagination_test_() -> ?assertEqual( {ok, [1,2,3,4,5,6]}, - octo_http_helper:read_collection(url, [all_pages], Id)), + octo_http_helper:read_collection(url, [octo_all_pages], Id)), ?assert(meck:validate(hackney)) end]). diff --git a/test/octo_url_helper_test.erl b/test/octo_url_helper_test.erl index 6992d1c..d325f0a 100644 --- a/test/octo_url_helper_test.erl +++ b/test/octo_url_helper_test.erl @@ -34,10 +34,10 @@ options_to_query_params_test_() -> octo_url_helper:options_to_query_params([])), ?_assertEqual( "per_page=100", - octo_url_helper:options_to_query_params([{per_page, 100}])), + octo_url_helper:options_to_query_params([{octo_per_page, 100}])), ?_assertEqual( "per_page=100", - octo_url_helper:options_to_query_params([{per_page, 100}, hi, {haha, 2}])) + octo_url_helper:options_to_query_params([{octo_per_page, 100}, hi, {haha, 2}])) ]}. pull_request_url_test_() ->