Class: Bcli::Commands::Snippets::Create
Instance Method Summary
collapse
#ask, #client, #config, #credentials, #download, #link_to, #logger, #open_in_browser, #parse_json, #pastel, #prompt
Constructor Details
#initialize(options) ⇒ Create
Returns a new instance of Create.
9
10
11
|
# File 'lib/bcli/commands/snippets/create.rb', line 9
def initialize(options)
@options = options
end
|
Instance Method Details
#execute(input: $stdin, output: $stdout) ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/bcli/commands/snippets/create.rb', line 13
def execute(input: $stdin, output: $stdout)
res = client.post("/snippets", payload(@options))
if res.code == 201
response = parse_json(res)
output.puts pastel.blue(link_to(response.name, response_url(response.url)))
else
output.puts pastel.red res
end
end
|
#language ⇒ Object
37
38
39
|
# File 'lib/bcli/commands/snippets/create.rb', line 37
def language
ask("Enter the language of the snippet:")
end
|
#name ⇒ Object
41
42
43
|
# File 'lib/bcli/commands/snippets/create.rb', line 41
def name
ask("Enter the name of the snippet:")
end
|
#payload(options) ⇒ Object
27
28
29
30
31
32
33
34
35
|
# File 'lib/bcli/commands/snippets/create.rb', line 27
def payload(options)
{
snippet: {
code: Clipboard.paste,
language:,
name:
}
}
end
|
#response_url(url) ⇒ Object
23
24
25
|
# File 'lib/bcli/commands/snippets/create.rb', line 23
def response_url(url)
url.gsub(".json", "")
end
|