Permalink
Browse files

Apparently GitHub API or listing repositories paginates results, so w…

…e need to account for that.
  • Loading branch information...
1 parent b2d0633 commit 38f928ba44d096a7cf52be9e4dfaad1b0cb7b900 @yrashk yrashk committed Jan 31, 2011
Showing with 19 additions and 11 deletions.
  1. +19 −11 src/agner_github.erl
View
30 src/agner_github.erl
@@ -13,20 +13,28 @@
]).
repositories() ->
- case request("https://github.com/api/v2/json/repos/show/" ++ Account) of
+ repositories(1).
+
+repositories(Page) ->
+ case request("https://github.com/api/v2/json/repos/show/" ++ Account ++ "?page=" ++ integer_to_list(Page)) of
{error, _Reason} = Error ->
Error;
{struct, Object} ->
- Repositories = proplists:get_value(<<"repositories">>, Object),
- lists:filter(fun ({invalid,_}) ->
- false;
- (_) ->
- true
- end,
- lists:map(fun ({struct, RepObject}) ->
- {repo_name(proplists:get_value(<<"name">>, RepObject)),
- proplists:get_value(<<"pushed_at">>, RepObject)}
- end, Repositories))
+ case proplists:get_value(<<"repositories">>, Object) of
+ [] ->
+ [];
+ Repositories ->
+ Repos = lists:filter(fun ({invalid,_}) ->
+ false;
+ (_) ->
+ true
+ end,
+ lists:map(fun ({struct, RepObject}) ->
+ {repo_name(proplists:get_value(<<"name">>, RepObject)),
+ proplists:get_value(<<"pushed_at">>, RepObject)}
+ end, Repositories)),
+ Repos ++ repositories(Page + 1)
+ end
end.
repository(Name) ->

1 comment on commit 38f928b

@yrashk
A Giant Nebula of Erlang Repositories member

s/or/for/

Please sign in to comment.