Class: ChangesSince::ApiClient
- Inherits:
-
Object
- Object
- ChangesSince::ApiClient
- Defined in:
- lib/changes_since/api_client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
- #fetch_authorization(otp_token = nil) ⇒ Object
-
#initialize ⇒ ApiClient
constructor
A new instance of ApiClient.
- #pull_request_risks(number) ⇒ Object
Constructor Details
#initialize ⇒ ApiClient
Returns a new instance of ApiClient.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/changes_since/api_client.rb', line 9 def initialize puts "Please enter your Github credentials:" print "Username:" username = gets.chomp print "Password:" password = STDIN.noecho(&:gets).chomp puts @client = Octokit::Client.new( :login => username, :password => password ) begin rescue Octokit::OneTimePasswordRequired => e puts "Enter two factor auth token:" otp_token = gets.chomp (otp_token) end @client = Octokit::Client.new(:access_token => access_token) git = Git.open(Dir.pwd) @repo = git.remote.url.split(/[:.]/)[-2] end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
7 8 9 |
# File 'lib/changes_since/api_client.rb', line 7 def access_token @access_token end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/changes_since/api_client.rb', line 7 def client @client end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
7 8 9 |
# File 'lib/changes_since/api_client.rb', line 7 def repo @repo end |
Instance Method Details
#fetch_authorization(otp_token = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/changes_since/api_client.rb', line 35 def (otp_token=nil) = { :scopes => ["repo"], :note => "Changes Since" } headers = {} if otp_token headers = { "X-GitHub-OTP" => otp_token } .merge!(:headers => headers) end begin @access_token = client.() rescue Octokit::UnprocessableEntity => e = client.(:headers => headers) @access_token = .find { |a| a.note == "Changes Since" }.token end end |
#pull_request_risks(number) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/changes_since/api_client.rb', line 52 def pull_request_risks(number) pr = client.pull_request(repo, number) body = pr.body if pr.body.include?("Risks") body = body[pr.body.index("Risks") + 5, body.size] elsif pr.body.include?("Risk") body = body[pr.body.index("Risk") + 4, body.size] else return " " end body = body.strip if index = body.index(/\r\n\r\n/) body = body[0, index] end body end |