shortly 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/shortly +84 -0
  2. data/lib/shortly.rb +9 -1
  3. metadata +7 -6
data/bin/shortly ADDED
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDOUT.sync = true
4
+
5
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
6
+
7
+ require 'rubygems'
8
+ require 'optparse'
9
+ require 'shortly'
10
+
11
+ ORIG_ARGV = ARGV.dup
12
+
13
+ services = {:googl => Shortly::Clients::Googl, :isgd => Shortly::Clients::Isgd, :bitly => Shortly::Clients::Bitly}
14
+
15
+ options = {:service => :googl, :method => :shorten}
16
+
17
+ opts = OptionParser.new do |opts|
18
+ opts.banner = <<-EOS
19
+ Usage:
20
+ shortly url -s service -m method -l login -p apikey
21
+
22
+ Options:
23
+ EOS
24
+
25
+ opts.on("-s", "--service SERVICE", "Service to be used in shortner(e.g. bitly, googl(default), isgd)") do |service|
26
+ options[:service] = service.to_sym
27
+ end
28
+
29
+ opts.on("-l", "--login LOGIN", "Login creadential (for bitly only)") do |login|
30
+ options[:login] = login
31
+ end
32
+
33
+ opts.on("-p", "--apikey APIKEY", "API Key credentials (for bitly only)") do |apikey|
34
+ options[:apikey] = apikey
35
+ end
36
+
37
+ opts.on("-u", "--url URL", "The long/short URL on which operation is to be performed.") do |url|
38
+ options[:url] = url
39
+ end
40
+
41
+ opts.on("-m", "--method METHOD", "method to be used(e.g. shorten(default), expand)") do |method|
42
+ options[:method] = method.to_sym
43
+ end
44
+
45
+ opts.on("-v", "--version", "Version of shortly") do
46
+ options[:version] = true
47
+ end
48
+ end
49
+
50
+ opts.parse!
51
+
52
+ if options[:version]
53
+ abort("Version: " + Shortly.version)
54
+ end
55
+
56
+ options[:url] = ARGV.first if ARGV.length == 1
57
+
58
+ #validate for bitly services
59
+ if options[:service] == :bitly
60
+ abort("login is required for Bitly Services") unless options[:login]
61
+ abort("API Key is required for Bitly Services") unless options[:apikey]
62
+ end
63
+
64
+ unless options[:url]
65
+ abort("Please provide atleast a valid URL. To see help type --help or -h")
66
+ end
67
+
68
+ command = services[options[:service]]
69
+
70
+ if options[:service] == :bitly
71
+ command.login = options[:login]
72
+ command.apiKey = options[:apikey]
73
+ end
74
+
75
+ response = command.send(options[:method], options[:url])
76
+
77
+ output = case options[:service]
78
+ when :bitly then response.url || response.long_url
79
+ when :googl then response.short_url
80
+ when :isgd then response.shorturl
81
+ else abort("Something went wrong. Please raise an issue on Github")
82
+ end
83
+
84
+ puts output
data/lib/shortly.rb CHANGED
@@ -7,4 +7,12 @@ require 'shortly/errors'
7
7
  require 'shortly/client'
8
8
  require 'shortly/clients/bitly'
9
9
  require 'shortly/clients/googl'
10
- require 'shortly/clients/isgd'
10
+ require 'shortly/clients/isgd'
11
+
12
+ module Shortly
13
+
14
+ def self.version
15
+ File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
16
+ end
17
+
18
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shortly
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bagwan Pankaj
@@ -16,7 +16,7 @@ bindir: bin
16
16
  cert_chain: []
17
17
 
18
18
  date: 2011-01-16 00:00:00 +05:30
19
- default_executable:
19
+ default_executable: shortly
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  type: :runtime
@@ -96,14 +96,15 @@ dependencies:
96
96
  requirement: *id005
97
97
  description: Ruby Wrapper for different Url Shortner Services Ruby Wrapper
98
98
  email: bagwanpankaj@gmail.com
99
- executables: []
100
-
99
+ executables:
100
+ - shortly
101
101
  extensions: []
102
102
 
103
103
  extra_rdoc_files:
104
104
  - LICENSE.txt
105
105
  - README.textile
106
106
  files:
107
+ - bin/shortly
107
108
  - lib/shortly.rb
108
109
  - lib/shortly/client.rb
109
110
  - lib/shortly/clients/bitly.rb