class GithubPivotalFlow::GitHubAPI
Client for the GitHub v3 API.
Attributes
config[R]
oauth_app_url[R]
Public Class Methods
new(config, options)
click to toggle source
# File lib/github_pivotal_flow/github_api.rb, line 6 def initialize config, options @config = config @oauth_app_url = options.fetch(:app_url) end
Public Instance Methods
api_host(host)
click to toggle source
# File lib/github_pivotal_flow/github_api.rb, line 19 def api_host host host = host.downcase 'github.com' == host ? 'api.github.com' : host end
create_pullrequest(options)
click to toggle source
Returns parsed data from the new pull request.
# File lib/github_pivotal_flow/github_api.rb, line 47 def create_pullrequest options project = options.fetch(:project) params = { :base => options.fetch(:base), :head => options.fetch(:head) } if options[:issue] params[:issue] = options[:issue] else params[:title] = options[:title] if options[:title] params[:body] = options[:body] if options[:body] end res = post "https://%s/repos/%s/%s/pulls" % [api_host(project.host), project.owner, project.name], params res.error! unless res.success? res.data end
repo_exists?(project)
click to toggle source
# File lib/github_pivotal_flow/github_api.rb, line 42 def repo_exists? project repo_info(project).success? end
repo_info(project)
click to toggle source
# File lib/github_pivotal_flow/github_api.rb, line 37 def repo_info project get "https://%s/repos/%s/%s" % [api_host(project.host), project.owner, project.name] end
statuses(project, sha)
click to toggle source
# File lib/github_pivotal_flow/github_api.rb, line 68 def statuses project, sha res = get "https://%s/repos/%s/%s/statuses/%s" % [api_host(project.host), project.owner, project.name, sha] res.error! unless res.success? res.data end
username_via_auth_dance(host) { || ... }
click to toggle source
# File lib/github_pivotal_flow/github_api.rb, line 24 def username_via_auth_dance host host = api_host(host) config.github_username(host) do if block_given? yield else res = get("https://%s/user" % host) res.error! unless res.success? config.github_username = res.data['login'] end end end