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.get_repo("nitlang/nit")
assert repo != null
assert repo.name == "nit"

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

Authentification

Error: Multiple entities for 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

Error: No entity for load_user. Did you mean:

User - A Github user

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

Retrieving repo data

Error: No entity for load_repo. Did you mean:

Repo - A Github repository.

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

Other data

Advanced uses

Caching

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

Custom requests

get - Execute a GET request on Github API.

This method returns a deserialized result.

For raw data see send.

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

Returns null in case of error.

obj = api.get("/foo/bar/baz")
assert obj == null
assert api.was_error
assert api.last_error isa GithubError

Change the user agent

user_agent - User agent used for HTTP requests.

Debugging

Error: No entity for verbose_lvl. Did you mean:

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.

Error: Multiple entities for api_url: api_url, api_url

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 subgroups 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 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 base64 base64 github\>->base64 curl curl github\>->curl json json github\>->json nitcorn nitcorn github\>->nitcorn popcorn popcorn github\>->popcorn logger logger github\>->logger core core base64->core curl->json curl->core popcorn->json popcorn->nitcorn popcorn->logger github github popcorn->github config config popcorn->config csv csv popcorn->csv realtime realtime popcorn->realtime mongodb mongodb popcorn->mongodb pthreads pthreads popcorn->pthreads template template popcorn->template ...core ... ...core->core ...json ... ...json->json ...nitcorn ... ...nitcorn->nitcorn ...github ... ...github->github ...config ... ...config->config ...csv ... ...csv->csv ...logger ... ...logger->logger ...realtime ... ...realtime->realtime ...mongodb ... ...mongodb->mongodb ...pthreads ... ...pthreads->pthreads ...template ... ...template->template nitc nitc nitc->popcorn github... ... github...->github nitc... ... nitc...->nitc

Ancestors

group c

c

Structures and services for compatibility with the C language
group codecs

core > codecs

Group module for all codec-related manipulations
group collection

core > collection

This module define several collection classes.
group config

config

Configuration options for nit tools and apps
group console

console

Defines some ANSI Terminal Control Escape Sequences.
group core

core

Nit common library of core classes and methods
group csv

csv

CSV document handling.
group ini

ini

ini - Read and write INI configuration files
group libevent

libevent

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

md5

Native MD5 digest implementation as Text::md5
group meta

meta

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

mongodb

MongoDB Nit Driver.
group more_collections

more_collections

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

opts

Management of options on the command line
group parser_base

parser_base

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

performance_analysis

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

poset

Pre order sets and partial order set (ie hierarchies)
group pthreads

pthreads

POSIX Threads support
group realtime

realtime

Services to keep time of the wall clock time
group serialization

serialization

Abstract serialization services
group template

template

Basic template system
group text

core > text

All the classes and methods related to the manipulation of text entities

Parents

group base64

base64

Offers the base 64 encoding and decoding algorithms
group curl

curl

Data transfer powered by the native curl library
group json

json

read and write JSON formatted text
group logger

logger

A simple logger for Nit
group nitcorn

nitcorn

Lightweight framework for Web applications development
group popcorn

popcorn

Popcorn

Children

group popcorn

popcorn

Popcorn

Descendants

group api

nitc > doc > api

Components required to build a web server about the nit model.
group catalog

nitc > catalog

Basic catalog generator for Nit packages
group commands

nitc > doc > commands

group compiler

nitc > compiler

Compilation to C
group compiler_ffi

nitc > compiler > compiler_ffi

Full FFI support for the compiler
group doc

nitc > doc

group dynamic_loading_ffi

nitc > interpreter > dynamic_loading_ffi

This group implement a partial support for the Nit FFI in the interpreter.
group ffi

nitc > ffi

Full FFI support, independent of the compiler
group frontend

nitc > frontend

Collect and orchestration of main frontend phases
group interpreter

nitc > interpreter

Interpretation of Nit programs
group metrics

nitc > metrics

Various statistics about Nit models and programs
group model

nitc > model

The meta model of Nit programs
group modelize

nitc > modelize

Create a model from nit source files
group nitc

nitc

Nit compiler and tools
group nitni

nitc > nitni

Native interface related services (used underneath the FFI)
group parser

nitc > parser

Parser and AST for the Nit language
group platform

nitc > platform

Platform system, used to customize the behavior of the compiler.
group saf

nitc > saf

Nit Static Analysis Framework.
group semantize

nitc > semantize

Process bodies of methods in regard with the model.
group static

nitc > doc > static

Nitdoc generation framework
group term

nitc > doc > term

group testing

nitc > testing

Test unit generation and execution for Nit.
group uml

nitc > uml

Group head module for UML generation services
group vm

nitc > vm

Entry point of all vm components