lib/link_shrink/cli.rb in link_shrink-0.0.4 vs lib/link_shrink/cli.rb in link_shrink-0.0.5

- old
+ new

@@ -16,10 +16,11 @@ %w(@json @qr_code @tiny_url) @json = false @qr_code = false @tiny_url = false @google = false + @is_gd = false opts.version = LinkShrink::VERSION opts.banner = <<MSG Usage: link_shrink [OPTION] [URL] Description: LinkShrink, Turn long and nasty links into short urls. @@ -29,10 +30,14 @@ opts.set_program_name 'LinkShrink' opts.on_head('-t', '--tinyurl', 'use TinyURL') do @tiny_url = :true end + opts.on_head('-i', '--isgd', 'use Is.gd') do + @is_gd = :true + end + opts.on_head('-g', '--google', 'use Google (Default)') do @google = :true end opts.on_head('-j', '--json', 'return JSON response') do @@ -62,14 +67,26 @@ return process_url if url_present? opts.help end def process_url - LinkShrink.configure { |c| c.api = 'TinyUrl' } if @tiny_url + api = select_api + LinkShrink.configure { |c| c.api = api } LinkShrink.shrink_url(@args.last, { json: @json, qr_code: @qr_code }) end def url_present? !!(@args.last =~ /^(http?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/) + end + + def select_api + case + when @tiny_url + 'TinyUrl' + when @is_gd + 'IsGd' + else + 'Google' + end end end end