Class: GitHubV3API

Inherits:
Object
  • Object
show all
Defined in:
lib/github_v3_api.rb,
lib/github_v3_api/org.rb,
lib/github_v3_api/repo.rb,
lib/github_v3_api/user.rb,
lib/github_v3_api/issue.rb,
lib/github_v3_api/entity.rb,
lib/github_v3_api/orgs_api.rb,
lib/github_v3_api/repos_api.rb,
lib/github_v3_api/users_api.rb,
lib/github_v3_api/issues_api.rb

Overview

See GitHubV3API documentation in lib/github_v3_api.rb

Defined Under Namespace

Classes: Entity, Issue, IssuesAPI, Org, OrgsAPI, Repo, ReposAPI, User, UsersAPI

Constant Summary collapse

NotFound =

Raised when an API request returns a 404 error

Class.new(RuntimeError)
Unauthorized =

Raised when an API request uses an invalid access token

Class.new(RuntimeError)
MissingRequiredData =

Raised when an API request is missing required data

Class.new(RuntimeError)

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ GitHubV3API

Returns a GitHubV3API instance that is able to access github with the access_token owner’s authorization.

access_token

an OAuth2 access token from GitHub



37
38
39
# File 'lib/github_v3_api.rb', line 37

def initialize(access_token)
  @access_token = access_token
end

Instance Method Details

#delete(path) ⇒ Object

:nodoc:



100
101
102
103
104
105
106
107
# File 'lib/github_v3_api.rb', line 100

def delete(path) #:nodoc:
  result = RestClient.delete("https://api.github.com" + path,
                          {:accept => :json,
                           :authorization => "token #{@access_token}"})
  JSON.parse(result)
rescue RestClient::Unauthorized
  raise Unauthorized, "The access token is invalid according to GitHub"
end

#get(path, params = {}) ⇒ Object

:nodoc:



73
74
75
76
77
78
79
80
# File 'lib/github_v3_api.rb', line 73

def get(path, params={}) #:nodoc:
  result = RestClient.get("https://api.github.com" + path,
                          {:accept => :json,
                           :authorization => "token #{@access_token}"}.merge({:params => params}))
  JSON.parse(result)
rescue RestClient::Unauthorized
  raise Unauthorized, "The access token is invalid according to GitHub"
end

#issuesObject

Entry-point for access to the GitHub Issues API

Returns an instance of GitHubV3API::IssuesAPI that will use the access_token associated with this instance



69
70
71
# File 'lib/github_v3_api.rb', line 69

def issues
  IssuesAPI.new(self)
end

#orgsObject

Entry-point for access to the GitHub Orgs API

Returns an instance of GitHubV3API::OrgsAPI that will use the access_token associated with this instance.



53
54
55
# File 'lib/github_v3_api.rb', line 53

def orgs
  OrgsAPI.new(self)
end

#patch(path, params = {}) ⇒ Object

:nodoc:



91
92
93
94
95
96
97
98
# File 'lib/github_v3_api.rb', line 91

def patch(path, params={}) #:nodoc:
  result = RestClient.post("https://api.github.com" + path, JSON.generate(params),
                          {:accept => :json,
                           :authorization => "token #{@access_token}"})
  JSON.parse(result)
rescue RestClient::Unauthorized
  raise Unauthorized, "The access token is invalid according to GitHub"
end

#post(path, params = {}) ⇒ Object

:nodoc:



82
83
84
85
86
87
88
89
# File 'lib/github_v3_api.rb', line 82

def post(path, params={}) #:nodoc:
  result = RestClient.post("https://api.github.com" + path, JSON.generate(params),
                          {:accept => :json,
                           :authorization => "token #{@access_token}"})
  JSON.parse(result)
rescue RestClient::Unauthorized
  raise Unauthorized, "The access token is invalid according to GitHub"
end

#reposObject

Entry-point for access to the GitHub Repos API

Returns an instance of GitHubV3API::ReposAPI that will use the access_token associated with this instance.



61
62
63
# File 'lib/github_v3_api.rb', line 61

def repos
  ReposAPI.new(self)
end

#usersObject

Entry-point for access to the GitHub Users API

Returns an instance of GitHubV3API::UserAPI that will use the access_token associated with this instance.



45
46
47
# File 'lib/github_v3_api.rb', line 45

def users
  UsersAPI.new(self)
end