Skip to content

Instantly share code, notes, and snippets.

@ninjarobot
Created February 3, 2017 03:43
Show Gist options
  • Save ninjarobot/6858256f5f9ad4333395d6de729befc1 to your computer and use it in GitHub Desktop.
Save ninjarobot/6858256f5f9ad4333395d6de729befc1 to your computer and use it in GitHub Desktop.
Retrieves some public repository information via SWI-Prolog.
:- module(githubapi, [list_repos/3]).
:- use_module(library(http/http_client)).
:- use_module(library(http/http_json)).
process_repo(J) :-
J = json(D),
format(
'~w \n\t~w \n\tlanguage: ~w \n\tclone url: ~w \n',
[D.name, D.description, D.language, D.clone_url]
).
list_repos(Username, Page, PerPage) :-
format(
atom(Url),
'https://api.github.com/users/~w/repos?sort=pushed&page=~w&per_page=~w',
[Username, Page, PerPage]
),
http_get(Url, Data, []),
length(Data, Len),
format('Got ~w items\n', [Len]),
maplist(process_repo, Data).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment