Sha256: 9a2bbc2da1049389f3ec841451efaade66de74623e6064349f026749cbe21fa1
Contents?: true
Size: 1.46 KB
Versions: 21
Compression:
Stored size: 1.46 KB
Contents
# frozen_string_literal: true require_relative "../base" module Neetob class CLI module Heroku class Stack < Base attr_accessor :app def initialize(app) super() @app = app end def run raise(StandardError, "HEROKU_API_KEY is not given") if ENV["HEROKU_API_KEY"].nil? url = create_url(app) response = get(url) ui.success(response[:build_stack][:name]) end private def create_url(app) "https://api.heroku.com/apps/#{app}" end def parse_response(http_result) case http_result when Net::HTTPSuccess JSON.parse(http_result.body, symbolize_names: true) else error_message = JSON.parse(http_result.body)["message"] raise(StandardError, "Request failed with status code #{http_result.code}: #{error_message}") end end def get(url, headers: { "Accept" => "application/vnd.heroku+json; version=3", "Authorization" => "Bearer #{ENV["HEROKU_API_KEY"]}" }) uri = URI(url) request = Net::HTTP::Get.new(uri) headers.each { |key, value| request[key] = value } response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http| http.request(request) end parse_response(response) end end end end end
Version data entries
21 entries across 21 versions & 1 rubygems