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.5.0'
Instance Method Summary collapse
-
#delete(path) ⇒ Object
:nodoc:.
-
#get(path, params = {}) ⇒ Object
:nodoc:.
-
#initialize(access_token, api_url = 'https://api.github.com', header = {}) ⇒ 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, api_url = 'https://api.github.com', header = {}) ⇒ 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 40 41 42 43 44 |
# File 'lib/github_v3_api.rb', line 37 def initialize(access_token, api_url='https://api.github.com', header={}) @access_token = access_token @api_url = api_url @header = {:accept => :json, :authorization => "token #{@access_token}", :user_agent => "rubygem-github-v3-api"} @header.merge!(header) if header.is_a?(Hash) end |
Instance Method Details
#delete(path) ⇒ Object
:nodoc:
113 114 115 116 117 118 119 |
# File 'lib/github_v3_api.rb', line 113 def delete(path) #:nodoc: result = RestClient.delete(@api_url + path, @header) JSON.parse(result) rescue RestClient::Unauthorized raise Unauthorized, "The access token is invalid according to GitHub" end |
#get(path, params = {}) ⇒ Object
:nodoc:
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/github_v3_api.rb', line 78 def get(path, params={}) #:nodoc: result = RestClient.get(@api_url + path, @header.merge({:params => params})) result_data = JSON.parse(result) # check for pagination link = result.headers[:link] if link then re_relnext = %r!<#{@api_url}([^>]*)>; *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
74 75 76 |
# File 'lib/github_v3_api.rb', line 74 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.
58 59 60 |
# File 'lib/github_v3_api.rb', line 58 def orgs OrgsAPI.new(self) end |
#patch(path, params = {}) ⇒ Object
:nodoc:
105 106 107 108 109 110 111 |
# File 'lib/github_v3_api.rb', line 105 def patch(path, params={}) #:nodoc: result = RestClient.post(@api_url + path, JSON.generate(params), @header) JSON.parse(result) rescue RestClient::Unauthorized raise Unauthorized, "The access token is invalid according to GitHub" end |
#post(path, params = {}) ⇒ Object
:nodoc:
97 98 99 100 101 102 103 |
# File 'lib/github_v3_api.rb', line 97 def post(path, params={}) #:nodoc: result = RestClient.post(@api_url + path, JSON.generate(params), @header) JSON.parse(result) rescue RestClient::Unauthorized raise Unauthorized, "The access token is invalid according to GitHub" end |