shortly 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -33,6 +33,12 @@ Optionally you can set apiKey and login beforehand (it would be more DRY i think
33
33
  @googl.expand('http://goo.gl/shrt').longUrl@
34
34
  @googl.analytics('http://goo.gl/shrt').analytics@
35
35
 
36
+ *Lggd* (Credit 'Steve Price (steveprice67)'. See Credits section)
37
+
38
+ @lggd = Shortly::Clients::Lggd@
39
+ @lggd.apiKey = '<api-key>'@
40
+ @lggd.shorten('http://justatest.com').shortUrl@
41
+
36
42
  *Is.gd*
37
43
 
38
44
  @isgd = Shortly::Clients::Isgd@
@@ -73,6 +79,10 @@ spits formatted json at CLI
73
79
  * Bitly
74
80
  @shortly 'http://bit.ly/shrt -s bitly -p my_api_key -l my_login -m expand@
75
81
 
82
+ h2. Credits
83
+
84
+ * "Steve Price(steveprice67)":https://github.com/steveprice67 (For implementing Lggd service support)
85
+
76
86
  h2. More Info
77
87
 
78
88
  For detailed info visit my blog "http://BagwanPankaj.com":http://bagwanpankaj.com
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/bin/shortly CHANGED
@@ -15,6 +15,7 @@ services = {
15
15
  :googl => Shortly::Clients::Googl,
16
16
  :isgd => Shortly::Clients::Isgd,
17
17
  :vgd => Shortly::Clients::Vgd,
18
+ :lggd => Shortly::Clients::Lggd,
18
19
  :bitly => Shortly::Clients::Bitly,
19
20
  :tinyurl => Shortly::Clients::Tinyurl
20
21
  }
@@ -71,12 +72,17 @@ end
71
72
  unless options[:url]
72
73
  abort("Please provide atleast a valid URL. To see help type --help or -h")
73
74
  end
75
+ unless services.include?(options[:service])
76
+ abort("#{options[:service]} sevice is not supported currently.")
77
+ end
74
78
 
75
79
  command = services[options[:service]]
76
80
 
77
81
  if options[:service] == :bitly
78
- command.login = options[:login]
79
- command.apiKey = options[:apikey]
82
+ command.login = options.delete(:login)
83
+ command.apiKey = options.delete(:apikey)
84
+ elsif options[:service] == :lggd
85
+ command.apiKey = options.delete(:apikey)
80
86
  end
81
87
 
82
88
  response = command.send(options[:method], options[:url])
@@ -99,6 +105,7 @@ output = case options[:service]
99
105
  end
100
106
  when :isgd then response.shorturl
101
107
  when :vgd then response.shorturl
108
+ when :lggd then response.shortUrl
102
109
  when :tinyurl then response.shorturl
103
110
  else abort("Something went wrong. Please raise an issue on Github")
104
111
  end
@@ -47,7 +47,8 @@ module Shortly
47
47
  #expands provided url by making call to bitly api with given options.
48
48
  def self.expand(short_url, options = {})
49
49
  validate_uri!(short_url)
50
- options = {:login => self.login, :apiKey => self.apiKey, :shortUrl => short_url, :format => "json"}.merge(options)
50
+ options = {:login => self.login, :apiKey => self.apiKey, :shortUrl => short_url, :format => "json"}.merge(options)
51
+ validate!(options)
51
52
  response = get("/v3/expand", get_params(options))
52
53
  OpenStruct.new(response["data"]["expand"].first)
53
54
  end
@@ -62,7 +63,8 @@ module Shortly
62
63
  private
63
64
 
64
65
  def self.validate!(options)
65
- raise NotAuthorizedError.new("Credentials required(login and apiKey)") unless options.authenticable?
66
+ raise NotAuthorizedError.new("Credentials required(login and apiKey)") unless
67
+ options.authenticable?(:login, :apiKey)
66
68
  end
67
69
 
68
70
  end
@@ -0,0 +1,54 @@
1
+ # Copyright (c) 2011 Bagwan Pankaj
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module Shortly
23
+
24
+ module Clients
25
+
26
+ class Lggd < Client
27
+
28
+ self.register!
29
+
30
+ class << self
31
+ attr_accessor :apiKey
32
+ end
33
+
34
+ base_uri 'lg.gd'
35
+
36
+ #shorts provided url by making call to is.gd api with given options.
37
+ def self.shorten(url, options = {})
38
+ validate_uri!(url)
39
+ options = {:apiKey => self.apiKey, :format => :json, :longUrl => url}.merge(options)
40
+ validate!(options)
41
+ response = get("/shorten", get_params(options))
42
+ OpenStruct.new(response['results'][url])
43
+ end
44
+
45
+ private
46
+
47
+ def self.validate!(options)
48
+ raise NotAuthorizedError.new("Credentials required(apiKey)") unless
49
+ options.authenticable?(:apiKey)
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -32,8 +32,8 @@ module Shortly
32
32
 
33
33
  module MonkeyHash
34
34
 
35
- def authenticable?
36
- [:login, :apiKey].all?{|k| self.key?(k)} && !self.values.any?(&:blank?)
35
+ def authenticable?(*args)
36
+ args.all?{|k| self.key?(k)} && !self.values.any?(&:blank?)
37
37
  end
38
38
 
39
39
  end
data/lib/shortly.rb CHANGED
@@ -9,6 +9,7 @@ require 'shortly/client'
9
9
  require 'shortly/clients/bitly'
10
10
  require 'shortly/clients/googl'
11
11
  require 'shortly/clients/isgd'
12
+ require 'shortly/clients/lggd'
12
13
  require 'shortly/clients/tinyurl'
13
14
  require 'shortly/clients/vgd'
14
15
 
data/spec/shortly_spec.rb CHANGED
@@ -178,6 +178,35 @@ describe "Shortly" do
178
178
  end
179
179
  end
180
180
 
181
+ #tests for client lg.gd
182
+ describe "Lggd" do
183
+
184
+ before(:all) do
185
+ Shortly::Clients::Lggd.apiKey = "87171b48ff5487f8817021667298e059081d7cc0"
186
+ @long_url = "http://google.com"
187
+ @invalid_url = "bagwanpankaj.com"
188
+ @short_url = "http://demo.shortswitch.com/1"
189
+ end
190
+
191
+ it "should get a short url from lg.gd(provided valid url)" do
192
+ res = Shortly::Clients::Lggd.shorten(@long_url)
193
+ res.shortUrl.should_not be_empty
194
+ res.shortUrl.should == @short_url
195
+ end
196
+
197
+ it "result should be an instance of OpenStruct" do
198
+ res = Shortly::Clients::Lggd.shorten(@long_url)
199
+ res.should be_an_instance_of(OpenStruct)
200
+ end
201
+
202
+ it "should throw an error on wrong uri format" do
203
+ lambda do
204
+ Shortly::Clients::Lggd.shorten(@invalid_url)
205
+ end.should raise_error(Shortly::Errors::InvalidURIError)
206
+ end
207
+
208
+ end
209
+
181
210
  describe "Client" do
182
211
 
183
212
  before(:all) do
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: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bagwan Pankaj
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-22 00:00:00 +05:30
18
+ date: 2011-01-23 00:00:00 +05:30
19
19
  default_executable: shortly
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -126,6 +126,7 @@ files:
126
126
  - lib/shortly/clients/bitly.rb
127
127
  - lib/shortly/clients/googl.rb
128
128
  - lib/shortly/clients/isgd.rb
129
+ - lib/shortly/clients/lggd.rb
129
130
  - lib/shortly/clients/rubyurl.rb
130
131
  - lib/shortly/clients/tinyurl.rb
131
132
  - lib/shortly/clients/vgd.rb