github

Version, currently master branch1 version
  • master branchlatestNov 5, 2016

github.com/dukex/github

Crystal toolkit for the GitHub API

2 stars
1 dependent
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  github:
    github: dukex/github
    branch: master

master is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
no constraint declared
License
MIT
Author
Duke

Dependencies

This version declares no dependencies.

README

github

Crystal toolkit for the GitHub API

Installation

Add this to your application's shard.yml:

dependencies:
  github:
    github: dukex/github

Usage

require "github"

First of all create a client

client = Github::Client.new access_token: "YOUR-GITHUB-TOKEN"

Search

You can make an search to any path described on github documentation with search method, but just the repositories search using repositories method will be mapped to an object, the search method returns a HTTP::Response

Example:

client.search('/code', {"q" => "language:crystal"})
client.search('/issues', {"q" => "type:closed"})
client.search('/users', {"q" => "type:org"})
client.search('/repositories', {"q" => "language:crystal"})

Repositories

To search repository you can use Client#repositories, the repositories method accepts the following params:

NameTypeDescription
qstringThe search keywords, as well as any qualifiers.
sortstringThe sort field. One of stars, forks, or updated. Default: results are sorted by best match.
orderstringThe sort order if sort parameter is provided. One of asc or desc. Default: desc

To understand more about this params see github documentation

Example:

client.repositories({"q" => "language:crystal", "sort" => "stars", "asc"})
=> Github::Response::Repositories

Contents

Readme

Github have a shortcut to get contents of 'readme' file

# repository is a Github::Response::Repository
readme = client.readme(repository)
=> Github::Response::Contents
readme.content
=> "Just another Readme"

Content

To get some repository content you can use content method

Example:

main_file = client.content(repository, 'main.c')
=> Github::Response::Contents

Users

To get an user, just use user method, when the username params are ommited will returns the current authenticated user

myself = client.user('dukex')
=> Github::Response::User
me = client.user
=> Github::Response::User

Releases

List releases for a repository using releases methods

myself = client.releases('rails', 'rails')
=> Github::Response::Releases

Contributing

  1. Fork it ( https://github.com/dukex/github/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • dukex Duke - creator, maintainer