Module: Github
- Defined in:
- lib/github.rb,
lib/github/blob.rb,
lib/github/refs.rb,
lib/github/tree.rb,
lib/github/commit.rb,
lib/github/pusher.rb
Overview
Interface for the Github API (V3)
Defined Under Namespace
Modules: Blob, Commit, Refs, Tree
Classes: Pusher
Constant Summary
collapse
- ROOT_ENDPOINT =
'https://api.github.com'
- APP_NAME =
APP_CONFIG['github_app_name']
- OWNER =
APP_CONFIG['github_owner']
- REPO =
APP_CONFIG['github_repo']
- REQUEST_PARAMS =
{
'access_token' => ENV['GITHUB_APPLICATION_ACCESS_TOKEN'],
'client_id' => ENV['GITHUB_APPLICATION_CLIENT_ID'],
'client_secret' => ENV['GITHUB_APPLICATION_CLIENT_SECRET']
}
- VALID_VERBS =
{
get: Net::HTTP::Get,
post: Net::HTTP::Post,
patch: Net::HTTP::Patch
}
Class Method Summary
collapse
Class Method Details
.enabled? ⇒ Boolean
18
19
20
|
# File 'lib/github.rb', line 18
def self.enabled?
APP_NAME.present? && OWNER.present? && REPO.present?
end
|
.get(url, params = {}) ⇒ Object
49
50
51
|
# File 'lib/github.rb', line 49
def self.get(url, params={})
send_request(:get, url, params)
end
|
.patch(url, params = {}) ⇒ Object
57
58
59
|
# File 'lib/github.rb', line 57
def self.patch(url, params={})
send_request(:patch, url, params)
end
|
.post(url, params = {}) ⇒ Object
53
54
55
|
# File 'lib/github.rb', line 53
def self.post(url, params={})
send_request(:post, url, params)
end
|
.pusher ⇒ Object
22
23
24
|
# File 'lib/github.rb', line 22
def self.pusher
@pusher ||= Pusher.new
end
|
.send_request(verb, url, params = {}) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/github.rb', line 26
def self.send_request(verb, url, params={})
raise "invalid HTTP verb #{verb}" unless VALID_VERBS.include?(verb)
query_params = REQUEST_PARAMS
query_params.merge!(params) if verb == :get
url += "?#{query_params.to_query}"
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = VALID_VERBS[verb].new(uri.request_uri)
request['Accept'] = 'application/vnd.github.v3+json'
request['User-Agent'] = APP_NAME
if request.request_body_permitted?
request.body = params.to_json
request.content_type = 'application/json'
end
http.request(request)
end
|
.valid_sha?(sha) ⇒ Boolean
61
62
63
|
# File 'lib/github.rb', line 61
def self.valid_sha?(sha)
sha.present? && sha.length == 40 && sha =~ /^[0-9A-F]+$/i
end
|