Sha256: fc7a0ded77d171b9f450186ba5565a07a6fa13e209ebc10f7c3e416901ea8fa5
Contents?: true
Size: 1.31 KB
Versions: 30
Compression:
Stored size: 1.31 KB
Contents
# frozen_string_literal: true require_relative '../helpers/os_helper' require_relative '../github/api_interface' require_relative '../github/gist' module Geet module Services class CreateGist include Geet::Helpers::OsHelper API_TOKEN_KEY = 'GITHUB_API_TOKEN' DEFAULT_GIT_CLIENT = Geet::Utils::GitClient.new def initialize(out: $stdout) @out = out api_token = extract_env_api_token @api_interface = Geet::Github::ApiInterface.new(api_token) end # options: # :description # :publik: defaults to false # :no_browse defaults to false # def execute(full_filename, description: nil, publik: false, no_browse: false) content = IO.read(full_filename) gist_access = publik ? 'public' : 'private' @out.puts "Creating a #{gist_access} gist..." filename = File.basename(full_filename) gist = Geet::Github::Gist.create(filename, content, @api_interface, description: description, publik: publik) if no_browse @out.puts "Gist address: #{gist.link}" else open_file_with_default_application(gist.link) end end private def extract_env_api_token ENV[API_TOKEN_KEY] || raise("#{API_TOKEN_KEY} not set!") end end end end
Version data entries
30 entries across 30 versions & 1 rubygems