Giter Site home page Giter Site logo

perl6-webservice-github's Introduction

perl6-WebService-GitHub

Build Status

ALPHA STAGE, SUBJECT TO CHANGE

SYNOPSIS

use WebService::GitHub;

my $gh = WebService::GitHub.new(
    access-token => 'my-access-token'
);

my $res = $gh.request('/user');
say $res.data.name;

TODO

Patches welcome

  • Break down modules (Users, Repos, Issues etc.)
  • Errors Handle
  • Auto Pagination
  • API Throttle

Methods

Args

  • endpoint

useful for GitHub Enterprise. default to https://api.github.com

  • access-token

Required for Authorized API Request

  • auth_login & auth_password

Basic Authenticaation. useful to get access-token.

  • per_page

from Doc, default to 30, max to 100.

  • jsonp_callback

JSONP Callback

  • time-zone

UTC by default, Doc

  • with

does the roles

my $gh = WebService::GitHub.new(
    with => ('Debug')
);

Response

  • raw

HTTP::Response instance

  • data

JSON decoded data

  • header(Str $field)

Get header of HTTP Response

  • first-page-url, prev-page-url, next-page-url, last-page-url

Parsed from Link header, Doc

  • x-ratelimit-limit, x-ratelimit-remaining, x-ratelimit-reset

Rate Limit

Examples

Public Access without access-token

get user info

my $gh = WebService::GitHub.new;
my $user = $gh.request('/users/fayland').data;
say $user<name>;

search repositories

use WebService::GitHub::Search;

my $search = WebService::GitHub::Search.new;
my $data = $search.repositories({
    :q<perl6>,
    :sort<stars>,
    :order<desc>
}).data;

OAuth

get token from user/login

examples/create_access_token.pl

use WebService::GitHub::OAuth;

my $gh = WebService::GitHub::OAuth.new(
    auth_login => 'username',
    auth_password => 'password'
);

my $auth = $gh.create_authorization({
    :scopes(['user', 'public_repo', 'repo', 'gist']), # just ['public_repo']
    :note<'test purpose'>
}).data;
say $auth<token>;

Gist

create a gist

use WebService::GitHub::Gist;

my $gist = WebService::GitHub::Gist.new(
    access-token => %*ENV<GITHUB_ACCESS_TOKEN>
);

my $data = $gist.create_gist({
    description => 'Test from perl6 WebService::GitHub::Gist',
    public => True,
    files => {
        'test.txt' => {
            content => "Created on " ~ now
        }
    }
}).data;
say $data<url>;

update gist

$data = $gist.update_gist($id, {
    files => {
        "test_another.txt" => {
            content => "Updated on " ~ now
        }
    }
}).data;

delete gist

$res = $gist.delete_gist($id);
say 'Deleted' if $res.is-success;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.