Class: GitHub::API

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-github.rb

Constant Summary collapse

BASE_URL =
"http://github.com/api/v1/json"

Class Method Summary collapse

Class Method Details

.commit(user, repository, commit) ⇒ Object

Fetches a single commit for a repository.



29
30
31
32
# File 'lib/ruby-github.rb', line 29

def self.commit(user,repository,commit)
  url = BASE_URL + "/#{user}/#{repository}/commit/#{commit}"
  GitHub::Commit.new(JSON.parse(open(url).read).merge(:user => user, :repository => repository))
end

.commits(user, repository, branch = "master") ⇒ Object

Fetches the commits for a given repository.



17
18
19
20
21
22
# File 'lib/ruby-github.rb', line 17

def self.commits(user,repository,branch="master")
  url = BASE_URL + "/#{user}/#{repository}/commits/#{branch}"
  JSON.parse(open(url).read)["commits"].collect{ |c| 
    GitHub::Commit.new(c.merge(:user => user, :repository => repository))
  }
end

.repository(user, repository) ⇒ Object



24
25
26
# File 'lib/ruby-github.rb', line 24

def self.repository(user,repository)
  GitHub::API.user(user).repositories.select{|r| r.name == repository}.first
end

.user(user) ⇒ Object

Fetches information about the specified user name.



11
12
13
14
# File 'lib/ruby-github.rb', line 11

def self.user(user)
  url = BASE_URL + "/#{user}"
  GitHub::User.new(JSON.parse(open(url).read)["user"])
end