Created
February 3, 2017 03:43
-
-
Save ninjarobot/6858256f5f9ad4333395d6de729befc1 to your computer and use it in GitHub Desktop.
Retrieves some public repository information via SWI-Prolog.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- 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