module Github
Interface for the Github
API (V3)
Constants
- APP_NAME
- OWNER
- REPO
- REQUEST_PARAMS
- ROOT_ENDPOINT
- VALID_VERBS
Public Class Methods
enabled?()
click to toggle source
# File lib/github.rb, line 18 def self.enabled? APP_NAME.present? && OWNER.present? && REPO.present? end
get(url, params={})
click to toggle source
# File lib/github.rb, line 49 def self.get(url, params={}) send_request(:get, url, params) end
patch(url, params={})
click to toggle source
# File lib/github.rb, line 57 def self.patch(url, params={}) send_request(:patch, url, params) end
post(url, params={})
click to toggle source
# File lib/github.rb, line 53 def self.post(url, params={}) send_request(:post, url, params) end
pusher()
click to toggle source
# File lib/github.rb, line 22 def self.pusher @pusher ||= Pusher.new end
send_request(verb, url, params={})
click to toggle source
# 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)
click to toggle source
# File lib/github.rb, line 61 def self.valid_sha?(sha) sha.present? && sha.length == 40 && sha =~ /^[0-9A-F]+$/i end