Class: Bcli::Commands::Bookmarks::Create

Inherits:
Bcli::Command show all
Defined in:
lib/bcli/commands/bookmarks/create.rb

Instance Method Summary collapse

Methods inherited from Bcli::Command

#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.



10
11
12
13
14
15
16
# File 'lib/bcli/commands/bookmarks/create.rb', line 10

def initialize(options)
  @options = options
  @check_valid_url = proc { |url|
    uri_regex = URI::DEFAULT_PARSER.make_regexp(%w[http https])
    !!(url =~ uri_regex)
  }
end

Instance Method Details

#execute(input: $stdin, output: $stdout) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/bcli/commands/bookmarks/create.rb', line 18

def execute(input: $stdin, output: $stdout)
  res = client.post("/bookmarks", payload)
  if res.code == 201
    response = parse_json(res)
    output.puts pastel.green response.url
  else
    output.puts pastel.red res.body
  end
end