Nit wrapper for Github API

This module provides a Nit object oriented interface to access the Github api.

Accessing the API

GithubAPI - Client to Github API

To access the API you need an instance of a GithubAPI client.

var token = get_github_oauth
assert not token.is_empty

# Init the client.
var api = new GithubAPI(token)

The API client allows you to get Github API entities.

var repo = api.load_repo("nitlang/nit")
assert repo != null
assert repo.name == "nit"

var user = api.load_user("Morriar")
assert user != null
assert user.login == "Morriar"

Authentification

Error: Multiple entities for auth: auth, auth, auth, auth

Token can also be recovered from user config with get_github_oauth.

get_github_oauth - Gets the Github token from git configuration

Return the value of git config --get github.oauthtoken or "" if no key exists.

Retrieving user data

load_user - Get the Github user with login

Loads the User from the API or returns null if the user cannot be found.

var api = new GithubAPI(get_github_oauth)
var user = api.load_user("Morriar")
print user or else "null"
assert user.login == "Morriar"

User - A Github user

Provides access to Github user data. Should be accessed from GithubAPI::load_user.

  • SELF - Type of this instance, automatically specialized in every class
  • _avatar_url - Avatar image url for this user.
  • _blog - User public blog if any.
  • _email - User public email if any.
  • _login - Github login.
  • _name - User public name if any.
  • avatar_url - Avatar image url for this user.
  • avatar_url= - Avatar image url for this user.
  • blog - User public blog if any.
  • blog= - User public blog if any.
  • core_serialize_to - Actual serialization of self to serializer
  • email - User public email if any.
  • email= - User public email if any.
  • from_deserializer - Create an instance of this class from the deserializer
  • init
  • login - Github login.
  • login= - Github login.
  • name - User public name if any.
  • name= - User public name if any.

Retrieving repo data

load_repo - Get the Github repo with full_name.

Loads the Repo from the API or returns null if the repo cannot be found.

var api = new GithubAPI(get_github_oauth)
var repo = api.load_repo("nitlang/nit")
assert repo.name == "nit"
assert repo.owner.login == "nitlang"
assert repo.default_branch == "master"

Repo - A Github repository.

Provides access to Github repo data. Should be accessed from GithubAPI::load_repo.

Other data

Advanced uses

Caching

Error: Multiple entities for cache: cache, cache, cache, cache, cache, cache, cache

Custom requests

get - Execute a GET request on Github API.

This method returns raw json data. See other load_* methods to use more expressive types.

var api = new GithubAPI(get_github_oauth)
var obj = api.get("/repos/nitlang/nit")
assert obj isa JsonObject
assert obj["name"] == "nit"

Returns null in case of error.

obj = api.get("/foo/bar/baz")
assert obj == null
assert api.was_error
var err = api.last_error
assert err isa GithubError
assert err.name == "GithubAPIError"
assert err.message == "Not Found"

Change the user agent

user_agent - User agent used for HTTP requests.

Debugging

verbose_lvl - Verbosity level.

  • 0: only errors (default)
  • 1: verbose

Using with GitLab

If URL scheme of GitLab API follows the one of Github API, it may be possible to configure this wrapper to use a custom URL.

api_url - Github API base url.

Default is https://api.github.com and should not be changed.

Creating hooks

Using this API you can create Github hooks able to respond to actions performed on a repository.

hooks - Github hook event listening with nitcorn.

Usage:

import github::hooks

# A simple hook listener that print received events in stdout.
class LogHookListener
   super HookListener

   # Use double dispatch to implement log behavior.
   redef fun apply_event(event) do event.log_event(self)
end

redef class GithubEvent
   # Log this event.
   #
   # Do nothing by default.
   fun log_event(l: LogHookListener) do end
end

redef class CommitCommentEvent

   redef fun log_event(l) do
       print "new comment on commit {comment.commit_id}"
   end
end

var api = new GithubAPI(get_github_oauth)
var listener = new LogHookListener(api, "127.0.0.1", 8080)

Dealing with events

GithubAPI can trigger different events depending on the hook configuration.

GithubEvent - Github event stub.

All groups and modules

module api

github :: api

Nit object oriented interface to Github api.
group bin

github > bin

module cache

github :: cache

Enable caching on Github API accesses.
module events

github :: events

Events are emitted by Github Hooks.
module github

github :: github

Nit wrapper for Github API
module github_curl

github :: github_curl

Curl extention to access the Github API
module hooks

github :: hooks

Github hook event listening with nitcorn.
module loader

github :: loader

group man

github > man

module wallet

github :: wallet

Github OAuth tokens management
package_diagram github github json json github->json curl curl github->curl nitcorn nitcorn github->nitcorn popcorn popcorn github->popcorn console console github->console parser_base parser_base json->parser_base serialization serialization json->serialization curl->json core core curl->core popcorn->json popcorn->nitcorn popcorn->console config config popcorn->config csv csv popcorn->csv realtime realtime popcorn->realtime mongodb mongodb popcorn->mongodb pthreads pthreads popcorn->pthreads template template popcorn->template ...parser_base ... ...parser_base->parser_base ...serialization ... ...serialization->serialization ...core ... ...core->core ...nitcorn ... ...nitcorn->nitcorn ...config ... ...config->config ...csv ... ...csv->csv ...console ... ...console->console ...realtime ... ...realtime->realtime ...mongodb ... ...mongodb->mongodb ...pthreads ... ...pthreads->pthreads ...template ... ...template->template

Ancestors

package base64

base64

Offers the base 64 encoding and decoding algorithms
package c

c

Structures and services for compatibility with the C language
package config

config

Configuration options for nit tools and apps
package core

core

Nit common library of core classes and methods
package csv

csv

CSV document handling.
package ini

ini

Handle ini config files.
package libevent

libevent

Low-level wrapper around the libevent library to manage events on file descriptors
package md5

md5

Native MD5 digest implementation as Text::md5
package meta

meta

Simple user-defined meta-level to manipulate types of instances as object.
package mongodb

mongodb

MongoDB Nit Driver.
package more_collections

more_collections

Highly specific, but useful, collections-related classes.
package opts

opts

Management of options on the command line
package parser_base

parser_base

Simple base for hand-made parsers of all kinds
package performance_analysis

performance_analysis

Services to gather information on the performance of events by categories
package poset

poset

Pre order sets and partial order set (ie hierarchies)
package posix

posix

Services conforming to POSIX
package privileges

privileges

Process privileges management utilities
package pthreads

pthreads

POSIX Threads support
package realtime

realtime

Services to keep time of the wall clock time
package serialization

serialization

Abstract serialization services
package template

template

Basic template system

Parents

package console

console

Defines some ANSI Terminal Control Escape Sequences.
package curl

curl

Data transfer powered by the native curl library
package json

json

read and write JSON formatted text
package nitcorn

nitcorn

Lightweight framework for Web applications development
package popcorn

popcorn

Popcorn

Children

package popcorn

popcorn

Popcorn