Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I interact with the Github API using Perl6?

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

like image 651
jsaigle Avatar asked Apr 20 '18 18:04

jsaigle


1 Answers

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.

like image 146
jjmerelo Avatar answered Sep 23 '22 23:09

jjmerelo