• Stars
    star
    216
  • Rank 183,179 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated about 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Ruby interface to GitHub API v2

octopi

Octopi is a Ruby interface to GitHub API v2 (http://develop.github.com).

To install it as a Gem, just run:

gem install octopi

To include it in your modules or in irb use:

include Octopi

Get notifications via Twitter, following @octopi_gem: http://twitter.com/octopi_gem

Authenticated Usage

Seamless authentication using .gitconfig defaults

If you have your ~/.gitconfig file in place, and you have a [github] section (if you don't, take a look at this GitHub Guides entry, you can use seamless authentication using this method:

authenticated do
  repo = Repository.find(:name => "api-labrat", :user => "fcoury")
end

Explicit authentication

Sometimes, you may not want to get authentication data from ~/.gitconfig. You want to use GitHub API authenticated as a third party. For this use case, you have a couple of options too.

1. Providing login and token inline:

authenticated_with :login => "mylogin", :token => "mytoken" do
  repo = Repository.find(:name => "api-labrat", :user => "fcoury")
  issue = Issue.open :repo => repo, :params => {
    :title => "Sample issue", :body => "This issue was opened using GitHub API and Octopi" }
  puts issue.number
end

2. Providing login and password inline:

authenticated_with :login => "mylogin", :password => "password" do
  repo = Repository.find(:name => "api-labrat", :user => "fcoury")
  issue = Issue.open :repo => repo, :params => {
    :title => "Sample issue", :body => "This issue was opened using GitHub API and Octopi" }
  puts issue.number
end

3. Providing a YAML file with authentication information:

Use the following format:

#
# Octopi GitHub API configuration file
#

# GitHub user login and token
github:
  user: github-username
  token: github-token

# Trace level
# Possible values:
#   false - no tracing, same as if the param is ommited
#   true  - will output each POST or GET operation to the stdout
#   curl  - same as true, but in addition will output the curl equivalent of each command (for debugging)
trace: curl

And change the way you connect to:

authenticated :config => "github.yml") do
  (...)
end

Anonymous Usage

This reflects the usage of the API to retrieve information on a read-only fashion, where the user doesn't have to be authenticated.

Users API

Getting user information

user = User.find("fcoury")
puts "#{user.name} is being followed by #{user.followers.join(", ")} and following #{user.following.join(", ")}"

The bang methods followers! and following! retrieves a full User object for each user login returned, so it has to be used carefully.

user.followers!.each do |u|
  puts "  - #{u.name} (#{u.login}) has #{u.public_repo_count} repo(s)"
end

Searching for user

users = User.find_all("silva")
puts "#{users.size} users found for 'silva':"
users.each do |u|
  puts "  - #{u.name}"
end

Repositories API

repo = user.repository("octopi") # same as: Repository.find("fcoury", "octopi")
puts "Repository: #{repo.name} - #{repo.description} (by #{repo.owner}) - #{repo.url}"
puts "      Tags: #{repo.tags and repo.tags.map {|t| t.name}.join(", ")}"

Search:

repos = Repository.find_all("ruby", "git")
puts "#{repos.size} repository(ies) with 'ruby' and 'git':"
repos.each do |r|
  puts "  - #{r.name}"
end

Issues API integrated into the Repository object:

issue = repo.issues.first
puts "First open issue: #{issue.number} - #{issue.title} - Created at: #{issue.created_at}"

Single issue information:

issue = repo.issue(11)

Commits API information from a Repository object:

first_commit = Commit.find(:user => repo.user, :repo => repo.name, :sha => repo.commits.first.id)
puts "First commit: #{first_commit.id} - #{first_commit.message} - by #{first_commit.author['name']}"

Single commit information:

puts "Diff:"
first_commit.details.modified.each {|m| puts "#{m['filename']} DIFF: #{m['diff']}" }

Author

Contributors

In alphabetical order:

Thanks guys!

Copyright

Copyright (c) 2009 Felipe Coury. See LICENSE for details.

Bitdeli Badge

More Repositories

1

oxide

Teach your PostgreSQL database how to speak MongoDB Wire Protocol
Rust
258
star
2

kbpcb

Automated Keyboard PCB generator for KiCad
HTML
72
star
3

atom-rspec

Atom RSpec runner package
CoffeeScript
69
star
4

jfilehelpers

JFileHelpers is a library that automates the tedious task of parsing and creating structured text files. It handles fixed width or delimited files with Java annotations sweetness.
Java
46
star
5

node-anne-pro

Bluetooth communication library for the Anne Pro keyboard
JavaScript
27
star
6

intweet

Twitter. Keywords. Alerts.
Ruby
18
star
7

gitorious

Gitorious
Ruby
11
star
8

electron-anne-pro

Electron based Anne Pro Keyboard configurator
JavaScript
10
star
9

angular2-reddit

JavaScript
7
star
10

mongodb-language-model-rust

PEG.js
5
star
11

qmk_firmware_anne_pro

C
3
star
12

runst

JavaScript
3
star
13

mrkeebs

JavaScript
3
star
14

api-labrat

Lab rat for GitHub API interaction using Octopi
3
star
15

dotzsh

Shell
2
star
16

vscode-pretty-sql

TypeScript
2
star
17

qmk_configurator_react

CSS
2
star
18

servant

My MacRuby experience with server list selector
2
star
19

phd

Passenger-based Heroku-like Deployment
Ruby
2
star
20

rails-sti-caching

Isolated test for Rails Single-Table Inheritance caching problem
Ruby
2
star
21

ps2msx

Arduino + USB Host shield adapter from USB to MSX PS/2
C++
2
star
22

labelbug

A project to isolate the possible bug with rendering for attribute for label_tag as opposed to radio_button_tag
Ruby
2
star
23

via-layouts

2
star
24

mechpad

JavaScript
2
star
25

elongate

1
star
26

esp8266_mcp23017_oled96x64_rotary

C++
1
star
27

chicory40

1
star
28

scripts

AppleScript
1
star
29

jsmine

JavaScript
1
star
30

cookbooks

Chef cookbooks
Ruby
1
star
31

ajaxenterm

Python
1
star
32

ghostplus

Improved version of ghost
Ruby
1
star
33

ce_ele

Ruby
1
star
34

sample-rust-store

Rust
1
star
35

hirb-isolated

Isolated test for HIRB problem
Ruby
1
star
36

bling

bling bling gem management
Ruby
1
star
37

razermon

Add a Razer device battery monitoring gadget to your macOS menubar.
Rust
1
star
38

cursoprevestibular

Sistema para controle de cursinho prΓ© vestibular
1
star
39

wasmsx

TypeScript
1
star
40

espera

JavaScript
1
star
41

fcoury.github.com

Ruby
1
star
42

emulator-bus-minimal

Rust
1
star