Class: GitHubV3API
- Inherits:
-
Object
- Object
- GitHubV3API
- 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)
Class.new(RuntimeError)
- MissingRequiredData =
Raised when an API request is missing required data
Class.new(RuntimeError)
Instance Method Summary collapse
-
#delete(path) ⇒ Object
:nodoc:.
-
#get(path, params = {}) ⇒ Object
:nodoc:.
-
#initialize(access_token) ⇒ GitHubV3API
constructor
Returns a GitHubV3API instance that is able to access github with the
access_token
owner’s authorization. -
#issues ⇒ Object
Entry-point for access to the GitHub Issues API.
-
#orgs ⇒ Object
Entry-point for access to the GitHub Orgs API.
-
#patch(path, params = {}) ⇒ Object
:nodoc:.
-
#post(path, params = {}) ⇒ Object
:nodoc:.
-
#repos ⇒ Object
Entry-point for access to the GitHub Repos API.
-
#users ⇒ Object
Entry-point for access to the GitHub Users API.
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 |
#issues ⇒ Object
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 |
#orgs ⇒ Object
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 |