Class: Geet::Services::CreateGist

Inherits:
Object
  • Object
show all
Includes:
Helpers::OsHelper
Defined in:
lib/geet/services/create_gist.rb

Constant Summary collapse

API_TOKEN_KEY =
'GITHUB_API_TOKEN'
DEFAULT_GIT_CLIENT =
Geet::Utils::GitClient.new

Instance Method Summary collapse

Methods included from Helpers::OsHelper

#execute_command, #open_file_with_default_application

Constructor Details

#initialize(out: $stdout) ⇒ CreateGist

Returns a new instance of CreateGist.



15
16
17
18
19
20
# File 'lib/geet/services/create_gist.rb', line 15

def initialize(out: $stdout)
  @out = out

  api_token = extract_env_api_token
  @api_interface = Geet::Github::ApiInterface.new(api_token)
end

Instance Method Details

#execute(full_filename, description: nil, publik: false, no_browse: false) ⇒ Object

options:

:description
:publik:      defaults to false
:no_browse    defaults to false


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/geet/services/create_gist.rb', line 27

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