Class: GithubAuthentication::Generator::App
- Inherits:
-
Object
- Object
- GithubAuthentication::Generator::App
- Defined in:
- lib/github_authentication/generator/app.rb
Instance Attribute Summary collapse
-
#app_id ⇒ Object
readonly
Returns the value of attribute app_id.
-
#installation_id ⇒ Object
readonly
Returns the value of attribute installation_id.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(pem:, installation_id:, app_id:) ⇒ App
constructor
A new instance of App.
Constructor Details
#initialize(pem:, installation_id:, app_id:) ⇒ App
Returns a new instance of App.
14 15 16 17 18 |
# File 'lib/github_authentication/generator/app.rb', line 14 def initialize(pem:, installation_id:, app_id:) @private_key = OpenSSL::PKey::RSA.new(pem) @installation_id = installation_id @app_id = app_id end |
Instance Attribute Details
#app_id ⇒ Object (readonly)
Returns the value of attribute app_id.
12 13 14 |
# File 'lib/github_authentication/generator/app.rb', line 12 def app_id @app_id end |
#installation_id ⇒ Object (readonly)
Returns the value of attribute installation_id.
12 13 14 |
# File 'lib/github_authentication/generator/app.rb', line 12 def installation_id @installation_id end |
Instance Method Details
#generate ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/github_authentication/generator/app.rb', line 20 def generate url = "https://api.github.com/app/installations/#{installation_id}/access_tokens" response = Http.post(url) do |request| request["Authorization"] = "Bearer #{jwt}" request["Accept"] = "application/vnd.github.machine-man-preview+json" request end unless response.is_a?(Net::HTTPSuccess) raise TokenGeneratorError, "[#{response.code}] #{response.body}" end Token.from_json(response.body) end |