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/version.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)
- VERSION =
'0.4.1'
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_tokenowner’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:
111 112 113 114 115 116 117 118 |
# File 'lib/github_v3_api.rb', line 111 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 81 82 83 84 85 86 87 88 89 90 91 |
# 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})) result_data = JSON.parse(result) # check for pagination link = result.headers[:link] if link then re_relnext = /<https:\/\/api.github.com([^>]*)>; *rel="next"/ relnext_path = link.match re_relnext if relnext_path && relnext_path[1] then next_data = self.get(relnext_path[1], params) result_data += next_data end end result_data 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:
102 103 104 105 106 107 108 109 |
# File 'lib/github_v3_api.rb', line 102 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:
93 94 95 96 97 98 99 100 |
# File 'lib/github_v3_api.rb', line 93 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 |