Class: MyCLI

Inherits:
Object
  • Object
show all
Defined in:
lib/ombu_labs/shortener/cli/application.rb

Class Method Summary collapse

Class Method Details

.helpObject



22
23
24
25
26
27
28
29
30
# File 'lib/ombu_labs/shortener/cli/application.rb', line 22

def self.help
  puts ""
  puts "Stopping. Can't run without REBRANDLY_API_KEY in your shell. "
  puts ""
  puts "Try following these steps:"
  puts ""
  puts "export REBRANDLY_API_KEY=<your api key>"
  puts "shorten <your long url here>"
end

.invalid_uriObject



32
33
34
35
36
37
38
39
40
# File 'lib/ombu_labs/shortener/cli/application.rb', line 32

def self.invalid_uri
  puts ""
  puts "Stopping. Can't run with an invalid URL. "
  puts ""
  puts "Try following these steps:"
  puts ""
  puts "export REBRANDLY_API_KEY=<your api key>"
  puts "shorten <valid long url here>"
end

.invalid_uri?(args = []) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
# File 'lib/ombu_labs/shortener/cli/application.rb', line 42

def self.invalid_uri?(args = [])
  url = args.first
  uri = URI.parse(url)
  false
rescue URI::InvalidURIError
  true
end

.no_api_key?Boolean

REBRANDLY_API_KEY env variable present?

Returns:

  • (Boolean)


53
54
55
# File 'lib/ombu_labs/shortener/cli/application.rb', line 53

def self.no_api_key?
  ENV['REBRANDLY_API_KEY'].to_s == ''
end

.start(args = []) ⇒ Object



15
16
17
18
19
20
# File 'lib/ombu_labs/shortener/cli/application.rb', line 15

def self.start(args = [])
  return puts help if no_api_key?
  return puts invalid_uri if invalid_uri?(args)

  OmbuLabs::Shortener::RebrandlyClient.new(args.first).shorten
end