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, stdin: false, description: nil, publik: false, open_browser: false) ⇒ Object

options:

:description
:publik:      defaults to false
:open_browser defaults to true


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, stdin: false, description: nil, publik: false, open_browser: false)
  content = stdin ? $stdin.read : 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 open_browser
    open_file_with_default_application(gist.link)
  else
    @out.puts "Gist address: #{gist.link}"
  end
end