lib/underway/api.rb in underway-1.1.0 vs lib/underway/api.rb in underway-2.0.0
- old
+ new
@@ -2,28 +2,28 @@
require "octokit"
module Underway
class Api
# Returns a Sawyer::Resource or PORO from the GitHub REST API
- def self.invoke(route, headers: {}, method: :get)
+ def self.invoke(route, headers: {}, data: {}, method: :get)
debug_octokit! if verbose_logging?
- Octokit.api_endpoint = Underway::Settings.config.raw["github_api_host"]
+ Octokit.api_endpoint = Underway::Settings.configuration.github_api_host
if !headers[:authorization] && !headers["Authorization"]
Octokit.bearer_token = generate_jwt
end
- final_headers = {
+ options = {
accept: "application/vnd.github.machine-man-preview+json",
headers: headers
}
begin
case method
- when :post then Octokit.post(route, final_headers)
- else Octokit.get(route, final_headers)
+ when :post then Octokit.post(route, options.merge(data))
+ else Octokit.get(route, options)
end
rescue Octokit::Error => e
{ error: e.to_s }
end
end
@@ -35,11 +35,11 @@
end
return if token.nil?
client = Octokit::Client.new(
- api_endpoint: Underway::Settings.config.raw["github_api_host"],
+ api_endpoint: Underway::Settings.configuration.github_api_host,
access_token: token
)
end
def self.generate_jwt
@@ -47,19 +47,19 @@
# Issued at time:
iat: Time.now.to_i,
# JWT expiration time (10 minute maximum)
exp: Time.now.to_i + (10 * 60),
# GitHub Apps identifier
- iss: Underway::Settings.config.app_issuer
+ iss: Underway::Settings.configuration.app_id
}
- JWT.encode(payload, Underway::Settings.config.private_key, "RS256")
+ JWT.encode(payload, Underway::Settings.configuration.private_key, "RS256")
end
# Returns a valid auth token for the installation
def self.installation_token(id:)
- if token = Underway::Settings.config.token_cache.lookup_installation_auth_token(id: id)
+ if token = Underway::Settings.configuration.token_cache.lookup_installation_auth_token(id: id)
log("token cache: hit")
return token
else
log("token cache: miss")
res = invoke(
@@ -71,11 +71,11 @@
raise ArgumentError.new(error)
end
token = res.token
expires_at = res.expires_at.to_s
- Underway::Settings.config.token_cache.store_installation_auth_token(id: id, token: token, expires_at: expires_at)
+ Underway::Settings.configuration.token_cache.store_installation_auth_token(id: id, token: token, expires_at: expires_at)
token
end
end
def self.debug_octokit!
@@ -88,15 +88,15 @@
end
Octokit.middleware = stack
end
def self.verbose_logging?
- !!Underway::Settings.config.verbose_logging
+ !!Underway::Settings.configuration.verbose_logging
end
def self.log(message)
if verbose_logging?
- ::Underway::Settings.config.logger.info(message)
+ ::Underway::Settings.configuration.logger.info(message)
end
end
end
end