Class: MyCLI
- Inherits:
-
Object
- Object
- MyCLI
- Defined in:
- lib/ombu_labs/shortener/cli/application.rb
Class Method Summary collapse
- .help ⇒ Object
- .invalid_uri ⇒ Object
- .invalid_uri?(args = []) ⇒ Boolean
-
.no_api_key? ⇒ Boolean
REBRANDLY_API_KEY env variable present?.
-
.start(args = []) ⇒ Object
Example:.
Class Method Details
.help ⇒ Object
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_uri ⇒ Object
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
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?
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
Example:
$ shorten fastruby.io/tune go.fastruby.io/tune-twt-779
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 |