6

I want to use the Github API in a script and I want to use it as an experience to get better using Perl6. However, I cannot even get a simple proof of concept to work.

Through some testing I realized that Github requires that you supply a valid user agent so I turned to HTTP::UserAgent. No matter what I try, I get the following error:

Internal Error: 'server returned no data'
  in block  at /Applications/Rakudo/share/perl6/site/sources/FD28A8E22DFE16B70B757D9981C7B6C25543060C (HTTP::UserAgent) line 259
  in any  at /Applications/Rakudo/share/perl6/site/precomp/F91BAB44DF15C5C298C627DD5E0F9D819ED79939.1517344679.60204/FD/FD28A8E22DFE16B70B757D9981C7B6C25543060C line 1
  in method new at /Applications/Rakudo/share/perl6/site/sources/DDDD4497B34FC81BC1F5FF467999BC4DA2FA1CEB (HTTP::Response) line 25
  in method get-response at /Applications/Rakudo/share/perl6/site/sources/FD28A8E22DFE16B70B757D9981C7B6C25543060C (HTTP::UserAgent) line 291
  in method request at /Applications/Rakudo/share/perl6/site/sources/FD28A8E22DFE16B70B757D9981C7B6C25543060C (HTTP::UserAgent) line 159
  in method get at /Applications/Rakudo/share/perl6/site/sources/FD28A8E22DFE16B70B757D9981C7B6C25543060C (HTTP::UserAgent) line 102
  in method get at /Applications/Rakudo/share/perl6/site/sources/FD28A8E22DFE16B70B757D9981C7B6C25543060C (HTTP::UserAgent) line 105
  in block <unit> at reporter.pl6 line 12

There is even an example in the the repo that doesn't seem to work for me.

#!/usr/bin/env perl6
use v6;
use HTTP::UserAgent;

my $ua = HTTP::UserAgent.new;
$ua.timeout = 1;

my $response = $ua.get('https://github.com');

if $response.is-success {
    say $response.content;
} else {
    die $response.status-line;
}

Any tips on how to connect to Github via Perl 6? I really love many aspects of the language but this type of thing is discouraging.

EDIT: I went on #perl6 irc and no one was able to reproduce this on other OSes. I got it to work on Debian. The issue seems to be with OS X

jsaigle
  • 444
  • 2
  • 7
  • 1
    That example seems to be using homepage instead of an API endpoint. What's the program that produces the error you pasted? Our IRC bot that [uses HTTP::UserAgent](https://github.com/perl6/geth/blob/c150dd327d3414862898b24d091811c2d9cdb5a2/lib/Geth/GitHub/Hooks/Preprocessor.pm6#L7) works fine. There's also [WebService::GitHub](https://modules.perl6.org/repo/WebService::GitHub) in ecosystem. –  Apr 20 '18 at 19:08
  • 1
    I tried to use an API endpoint at first: `https://api.github.com/users/:username/events` and got the same error. I'll look into the ecosystem module you posted -- but it's still odd that UserAgent doesn't seem to work. – jsaigle Apr 20 '18 at 19:14
  • 1
    FWIW, [another user verified](https://irclog.perlgeek.de/perl6/2018-04-20#i_16072080) that it works on OSX for them. The one thing you could try is [build the latest compiler from source](https://gist.github.com/zoffixznet/7f2b3ad3d3a6665baf84107c36283cb0) to see if it's some recent bug that got fixed. Though I don't particularly remember anything obvious getting in since 2018.01 as far as fixes go. –  Apr 20 '18 at 21:48
  • Thanks I appreciate that you had someone test this on OS X. It's possible that it's my openssl version that's out of date. I'll update this post when I find out. – jsaigle May 03 '18 at 19:41

1 Answers1

2

Although in alpha stage, WebServices::GitHub is perfectly serviceable. You can use it to download user information, or you can use my fork if you want to interact with issues. This program, for instance, is used to download some issues from a particular repo.

jjmerelo
  • 22,578
  • 8
  • 40
  • 86