Class: Geet::Services::CreateGist
- Inherits:
-
Object
- Object
- Geet::Services::CreateGist
- Includes:
- Helpers::OsHelper
- Defined in:
- lib/geet/services/create_gist.rb
Constant Summary collapse
Instance Method Summary collapse
-
#execute(full_filename, stdin: false, description: nil, publik: false, open_browser: false) ⇒ Object
options: :description :publik: defaults to false :open_browser defaults to true.
-
#initialize(out: $stdout) ⇒ CreateGist
constructor
A new instance of CreateGist.
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 |