shortly 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.textile CHANGED
@@ -33,11 +33,11 @@ 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)
36
+ *ShortSwitch* (Credit 'Steve Price (steveprice67)'. See Credits section)
37
37
 
38
- @lggd = Shortly::Clients::Lggd@
39
- @lggd.apiKey = '<api-key>'@
40
- @lggd.shorten('http://justatest.com').shortUrl@
38
+ @shortswitch = Shortly::Clients::ShortSwitch@
39
+ @shortswitch.apiKey = '<api-key>'@
40
+ @shortswitch.shorten('http://justatest.com').shortUrl@
41
41
 
42
42
  *Is.gd*
43
43
 
@@ -54,6 +54,13 @@ Optionally you can set apiKey and login beforehand (it would be more DRY i think
54
54
  @tinyurl = Shortly::Clients::Tinyurl@
55
55
  @tinyurl.shorten('http://justatest.com').shorturl@
56
56
 
57
+ *Sn.im*
58
+ @snim = Shortly::Clients::Snim@
59
+ @snim.apiKey = "<apiKey>"@
60
+ @snim.login = "<login>"@
61
+ @snim.shorten(long_url).shortUrl@
62
+ @snim.expand(url_id/shorturl).url@
63
+
57
64
  h4. Command Line Utility
58
65
 
59
66
  Shortly also provides command line utility. See some uses below.
@@ -91,6 +98,11 @@ For more info write me at bagwanpankaj[at]gmail.com or me[at]bagwanpankaj.com
91
98
 
92
99
  Copyright (c) 2010 Bagwan Pankaj: http://bagwanpankaj.com, released under the MIT license
93
100
 
101
+ h2. TODO's
102
+
103
+ * Better documentation
104
+ * Example series
105
+
94
106
  h2. Contributing to shortly
95
107
 
96
108
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
data/bin/shortly CHANGED
@@ -15,9 +15,12 @@ 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
+ :lggd => Shortly::Clients::ShortSwitch,
19
+ :shortswitch => Shortly::Clients::ShortSwitch,
19
20
  :bitly => Shortly::Clients::Bitly,
20
- :tinyurl => Shortly::Clients::Tinyurl
21
+ :jmp => Shortly::Clients::Jmp,
22
+ :tinyurl => Shortly::Clients::Tinyurl,
23
+ :snim => Shortly::Clients::Snim,
21
24
  }
22
25
 
23
26
  options = {:service => :googl, :method => :shorten} #defaults to be used
@@ -30,15 +33,15 @@ opts = OptionParser.new do |opts|
30
33
  Options:
31
34
  EOS
32
35
 
33
- opts.on("-s", "--service SERVICE", "Service to be used in shortner(e.g. bitly, googl(default), isgd)") do |service|
36
+ opts.on("-s", "--service SERVICE", "Service to be used in shortner(e.g. bitly, googl(default), isgd etc..)") do |service|
34
37
  options[:service] = service.to_sym
35
38
  end
36
39
 
37
- opts.on("-l", "--login LOGIN", "Login creadential (for bitly only)") do |login|
40
+ opts.on("-l", "--login LOGIN", "Login creadential") do |login|
38
41
  options[:login] = login
39
42
  end
40
43
 
41
- opts.on("-p", "--apikey APIKEY", "API Key credentials (for bitly only)") do |apikey|
44
+ opts.on("-p", "--apikey APIKEY", "API Key credentials") do |apikey|
42
45
  options[:apikey] = apikey
43
46
  end
44
47
 
@@ -52,7 +55,8 @@ opts = OptionParser.new do |opts|
52
55
 
53
56
  opts.on("-v", "--version", "Version of shortly") do
54
57
  options[:version] = true
55
- end
58
+ end
59
+
56
60
  end
57
61
 
58
62
  opts.parse!
@@ -63,14 +67,16 @@ end
63
67
 
64
68
  options[:url] = ARGV.first if ARGV.length == 1
65
69
 
66
- #validate for bitly services
67
- if options[:service] == :bitly
68
- abort("login is required for Bitly Services") unless options[:login]
69
- abort("API Key is required for Bitly Services") unless options[:apikey]
70
+ #validate for bitly/jmp services
71
+ if [:bitly, :jmp, :snim].include? options[:service]
72
+ abort("login is required this service") unless options[:login]
73
+ abort("API Key is required this services") unless options[:apikey]
74
+ elsif [:shortswitch].include? options[:service]
75
+ abort("API Key is required this services") unless options[:apikey]
70
76
  end
71
77
 
72
78
  unless options[:url]
73
- abort("Please provide atleast a valid URL. To see help type --help or -h")
79
+ abort("Please provide atleast a valid URL. To see help type --help or -h") and exit(1)
74
80
  end
75
81
  unless services.include?(options[:service])
76
82
  abort("#{options[:service]} sevice is not supported currently.")
@@ -78,17 +84,17 @@ end
78
84
 
79
85
  command = services[options[:service]]
80
86
 
81
- if options[:service] == :bitly
87
+ if [:bitly, :jmp, :snim].include? options[:service]
82
88
  command.login = options.delete(:login)
83
89
  command.apiKey = options.delete(:apikey)
84
- elsif options[:service] == :lggd
90
+ elsif [:lggd, :googl, :shortswitch].include? options[:service]
85
91
  command.apiKey = options.delete(:apikey)
86
92
  end
87
93
 
88
94
  response = command.send(options[:method], options[:url])
89
95
 
90
96
  output = case options[:service]
91
- when :bitly
97
+ when :bitly, :jmp
92
98
  case options[:method]
93
99
  when :shorten
94
100
  response.url
@@ -103,9 +109,15 @@ output = case options[:service]
103
109
  else
104
110
  response.analytics.to_json
105
111
  end
106
- when :isgd then response.shorturl
107
- when :vgd then response.shorturl
108
- when :lggd then response.shortUrl
112
+ when :snim
113
+ case options[:method]
114
+ when :shorten
115
+ response.shortUrl
116
+ when :expand
117
+ response.url
118
+ end
119
+ when :isgd, :vgd then response.shorturl
120
+ when :lggd, :shortswitch then response.shortUrl
109
121
  when :tinyurl then response.shorturl
110
122
  else abort("Something went wrong. Please raise an issue on Github")
111
123
  end
@@ -22,16 +22,14 @@
22
22
  module Shortly
23
23
 
24
24
  module Clients
25
-
26
- class RubyUrl < Client
27
-
28
- base_uri 'rubyurl.com'
25
+
26
+ class Jmp < Bitly
29
27
 
30
- def self.shorten(url)
31
- post('/api/links.json', :query => { :link => { :website_url => url } })
32
- end
28
+ self.register!
29
+
30
+ base_uri 'api.j.mp'
31
+
33
32
  end
34
-
33
+
35
34
  end
36
-
37
35
  end
@@ -23,7 +23,7 @@ module Shortly
23
23
 
24
24
  module Clients
25
25
 
26
- class Lggd < Client
26
+ class ShortSwitch < Client
27
27
 
28
28
  self.register!
29
29
 
@@ -31,7 +31,7 @@ module Shortly
31
31
  attr_accessor :apiKey
32
32
  end
33
33
 
34
- base_uri 'lg.gd'
34
+ base_uri 'api.shortswitch.com'
35
35
 
36
36
  #shorts provided url by making call to is.gd api with given options.
37
37
  def self.shorten(url, options = {})
@@ -0,0 +1,75 @@
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 Snim < Client
27
+
28
+ self.register!
29
+
30
+ class << self
31
+ #login = "<your login>"
32
+ #apiKey = "<your apiKey>"
33
+ attr_accessor :login, :apiKey
34
+ end
35
+
36
+ base_uri 'http://sn.im/site'
37
+
38
+ #shorts provided url by making call to bitly api with given options.
39
+ def self.shorten(url, options = {})
40
+ validate_uri!(url)
41
+ options = {:snipapi => self.apiKey,:snipuser => self.login, :sniplink => url}.merge(options)
42
+ validate!(options)
43
+ response = post("/getsnip", post_params(options))
44
+ OpenStruct.new(response["snip"].merge(:shortUrl => response["snip"]["id"]))
45
+ end
46
+
47
+ #expands provided url by making call to bitly api with given options.
48
+ def self.expand(short_url, options = {})
49
+ analytics(short_url.gsub('http://sn.im/', ''), options)
50
+ end
51
+
52
+ #gets analytics
53
+ def self.analytics(short_id, options = {})
54
+ options = {:snipapi => self.apiKey,:snipuser => self.login, :snipid => short_id}.merge(options)
55
+ validate!(options)
56
+ response = post("/getsnipdetails", post_params(options))
57
+ OpenStruct.new(unescape_url(response)["snip"])
58
+ end
59
+
60
+ private
61
+
62
+ def self.validate!(options)
63
+ raise NotAuthorizedError.new("Credentials required(login and apiKey)") unless
64
+ options.authenticable?(:snipapi, :snipuser)
65
+ end
66
+
67
+ def self.unescape_url(response)
68
+ response["snip"]["url"] = CGI.unescape(response["snip"]["url"]) if response["snip"]
69
+ response
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+ end
data/lib/shortly.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'uri'
2
+ require 'cgi'
2
3
  require 'ostruct'
3
4
  require 'json'
4
5
  require 'httparty'
@@ -7,11 +8,13 @@ require 'shortly/helper'
7
8
  require 'shortly/errors'
8
9
  require 'shortly/client'
9
10
  require 'shortly/clients/bitly'
11
+ require 'shortly/clients/jmp'
10
12
  require 'shortly/clients/googl'
11
13
  require 'shortly/clients/isgd'
12
- require 'shortly/clients/lggd'
14
+ require 'shortly/clients/shortswitch'
13
15
  require 'shortly/clients/tinyurl'
14
16
  require 'shortly/clients/vgd'
17
+ require 'shortly/clients/snim'
15
18
 
16
19
  module Shortly
17
20
 
data/spec/shortly_spec.rb CHANGED
@@ -9,9 +9,11 @@ describe "Shortly" do
9
9
  @invalid_url = "bagwanpankaj.com"
10
10
  @short_url = "http://goo.gl/17pbM"
11
11
  @googl = Shortly::Clients::Googl
12
+ @uri = @googl.base_uri + @googl.send(:relative_path)
12
13
  end
13
14
 
14
15
  it "should get a short url from googl(provided valid url)" do
16
+ mock_request_for(@uri, :method => :post, :fixture => "googl_shorten")
15
17
  res = @googl.shorten(@long_url)
16
18
  res.shortUrl.should_not be_empty
17
19
  res.shortUrl.should == @short_url
@@ -23,6 +25,7 @@ describe "Shortly" do
23
25
  end
24
26
 
25
27
  it "should get a long url back for given valid short url" do
28
+ mock_request_for(@uri + "?shortUrl=#{CGI.escape(@short_url)}", :method => :get, :fixture => "googl_expand")
26
29
  res = @googl.expand(@short_url)
27
30
  res.longUrl.should_not be_empty
28
31
  res.longUrl.should == @long_url
@@ -34,9 +37,14 @@ describe "Shortly" do
34
37
  end
35
38
 
36
39
  it "should give analytics for given short url" do
40
+ mock_request_for(@uri + "?shortUrl=#{CGI.escape(@short_url)}&projection=FULL",
41
+ :fixture => "googl_analytics")
42
+
37
43
  res = @googl.analytics(@short_url)
38
44
  res.analytics.should_not be_empty
39
45
  res.analytics.should be_an_instance_of(Hash)
46
+ res.analytics["week"].should be_an_instance_of(Hash)
47
+ res.analytics["day"].should be_an_instance_of(Hash)
40
48
  end
41
49
 
42
50
  it "should throw an error on wrong uri format" do
@@ -52,13 +60,18 @@ describe "Shortly" do
52
60
  before(:all) do
53
61
  @isgd = Shortly::Clients::Isgd
54
62
  @long_url = "http://bagwanpankaj.com"
63
+ @shorturl = "http://is.gd/bs9smw"
55
64
  @invalid_url = "bagwanpankaj.com"
65
+ @uri = @isgd.base_uri
56
66
  end
57
67
 
58
68
  it "should get a short url from Is.gd(provided valid url)" do
69
+ mock_request_for(@uri + "/create.php?url=#{CGI.escape(@long_url)}&format=json",
70
+ :fixture => "isgd_shorten")
71
+
59
72
  res = @isgd.shorten(@long_url)
60
73
  res.shorturl.should_not be_empty
61
- res.shorturl.should == @isgd.shorten(@long_url).shorturl
74
+ res.shorturl.should == @shorturl
62
75
  end
63
76
 
64
77
  it "result should be an instance of OpenStruct" do
@@ -85,25 +98,29 @@ describe "Shortly" do
85
98
  @vgd = Shortly::Clients::Vgd
86
99
  @long_url = "http://bagwanpankaj.com"
87
100
  @invalid_url = "bagwanpankaj.com"
101
+ @uri = @vgd.base_uri
88
102
  end
89
-
90
- it "should get a short url from Is.gd(provided valid url)" do
103
+
104
+ it "should get a short url from v.gd(provided valid url)" do
105
+ mock_request_for(@uri + "/create.php?url=#{CGI.escape(@long_url)}&format=json",
106
+ :fixture => "vgd_shorten")
107
+
91
108
  res = @vgd.shorten(@long_url)
92
109
  res.shorturl.should_not be_empty
93
110
  res.shorturl.should == @vgd.shorten(@long_url).shorturl
94
111
  end
95
-
112
+
96
113
  it "result should be an instance of OpenStruct" do
97
114
  res = @vgd.shorten(@long_url)
98
115
  res.should be_an_instance_of(OpenStruct)
99
116
  end
100
-
117
+
101
118
  it "should throw an error on wrong uri format" do
102
119
  lambda do
103
120
  @vgd.shorten(@invalid_url)
104
121
  end.should raise_error(Shortly::Errors::InvalidURIError)
105
122
  end
106
-
123
+
107
124
  it "should raise MethodNotAvailableError if method is not implemented for" do
108
125
  lambda do
109
126
  @vgd.expand(@long_url)
@@ -116,14 +133,18 @@ describe "Shortly" do
116
133
 
117
134
  before(:all) do
118
135
  @bitly = Shortly::Clients::Bitly
119
- @bitly.login = "modulo9"
120
- @bitly.apiKey = "R_0f17f32f11de7e3e953de49c6f255104"
136
+ @bitly.login = "TEST_LOGIN"
137
+ @bitly.apiKey = "R_TEST_API_KEY"
121
138
  @long_url = "http://bagwanpankaj.com"
122
139
  @invalid_url = "bagwanpankaj.com"
123
140
  @short_url = "http://bit.ly/dUdiIJ"
141
+ @uri = @bitly.base_uri + "/v3"
124
142
  end
125
143
 
126
- it "should get a short url from googl(provided valid url)" do
144
+ it "should get a short url from bitly(provided valid url)" do
145
+ mock_request_for(@uri + "/shorten?longUrl=#{CGI.escape(@long_url)}&format=json&login=#{@bitly.login}&apiKey=#{@bitly.apiKey}",
146
+ :fixture => "bitly_shorten")
147
+
127
148
  res = @bitly.shorten(@long_url)
128
149
  res.url.should_not be_empty
129
150
  res.url.should == @short_url
@@ -141,20 +162,70 @@ describe "Shortly" do
141
162
  end
142
163
 
143
164
  it "should expand a given short url" do
165
+ mock_request_for(@uri + "/expand?shortUrl=#{CGI.escape(@short_url)}&format=json&login=#{@bitly.login}&apiKey=#{@bitly.apiKey}",
166
+ :fixture => "bitly_expand")
167
+
144
168
  res = @bitly.expand("http://bit.ly/dUdiIJ")
145
169
  res.long_url.should == @long_url
146
170
  end
147
171
 
148
172
  end
149
173
 
174
+ #tests for client jmp
175
+ describe "Jmp" do
176
+
177
+ before(:all) do
178
+ @jmp = Shortly::Clients::Jmp
179
+ @jmp.login = "TEST_LOGIN"
180
+ @jmp.apiKey = "R_TEST_API_KEY"
181
+ @long_url = "http://bagwanpankaj.com"
182
+ @invalid_url = "bagwanpankaj.com"
183
+ @short_url = "http://j.mp/dUdiIJ"
184
+ @uri = @jmp.base_uri + '/v3'
185
+ end
186
+
187
+ it "should get a short url from jmp(provided valid url)" do
188
+ mock_request_for(@uri + "/shorten?longUrl=#{CGI.escape(@long_url)}&format=json&login=#{@jmp.login}&apiKey=#{@jmp.apiKey}",
189
+ :fixture => "jmp_shorten")
190
+
191
+ res = @jmp.shorten(@long_url)
192
+ res.url.should_not be_empty
193
+ res.url.should == @short_url
194
+ end
195
+
196
+ it "result should be an instance of OpenStruct" do
197
+ res = @jmp.shorten(@long_url)
198
+ res.should be_an_instance_of(OpenStruct)
199
+ end
200
+
201
+ it "should throw an error on wrong uri format" do
202
+ lambda do
203
+ @jmp.shorten(@invalid_url)
204
+ end.should raise_error(Shortly::Errors::InvalidURIError)
205
+ end
206
+
207
+ it "should expand a given short url" do
208
+ mock_request_for(@uri + "/expand?shortUrl=#{CGI.escape(@short_url)}&format=json&login=#{@jmp.login}&apiKey=#{@jmp.apiKey}",
209
+ :fixture => "jmp_expand")
210
+
211
+ res = @jmp.expand(@short_url)
212
+ res.long_url.should == @long_url
213
+ end
214
+
215
+ end
216
+
150
217
  #tests for client tinyurl
151
218
  describe "TinyUrl" do
152
219
  before(:all) do
153
220
  @long_url = "http://bagwanpankaj.com"
154
221
  @invalid_url = "bagwanpankaj.com"
222
+ @uri = Shortly::Clients::Tinyurl.base_uri
155
223
  end
156
224
 
157
225
  it "should get a short url from TinyUrl(provided valid url)" do
226
+ mock_request_for(@uri + "/api-create.php", :method => :post,
227
+ :fixture => "tinyurl_shorten", :content_type => "text/plain")
228
+
158
229
  res = Shortly::Clients::Tinyurl.shorten(@long_url)
159
230
  res.shorturl.should_not be_empty
160
231
  res.shorturl.should == "http://tinyurl.com/6jt3pjr"
@@ -178,35 +249,81 @@ describe "Shortly" do
178
249
  end
179
250
  end
180
251
 
181
- #tests for client lg.gd
182
- describe "Lggd" do
252
+ #tests for client ShortSwitch
253
+ describe "ShortSwitch" do
183
254
 
184
255
  before(:all) do
185
- Shortly::Clients::Lggd.apiKey = "87171b48ff5487f8817021667298e059081d7cc0"
186
- @long_url = "http://google.com"
256
+ @ss = Shortly::Clients::ShortSwitch
257
+ Shortly::Clients::ShortSwitch.apiKey = "TESTKEY"
258
+ @long_url = "http://bagwanpankaj.com"
187
259
  @invalid_url = "bagwanpankaj.com"
188
- @short_url = "http://demo.shortswitch.com/1"
260
+ @short_url = "http://demo.shortswitch.com/t"
261
+ @uri = @ss.base_uri
189
262
  end
263
+
264
+ it "should get a short url from ShortSwitch(provided valid url)" do
265
+ mock_request_for(@uri + "/shorten?longUrl=#{CGI.escape(@long_url)}&format=json&apiKey=TESTKEY",
266
+ :fixture => "shortswitch_shorten")
190
267
 
191
- it "should get a short url from lg.gd(provided valid url)" do
192
- res = Shortly::Clients::Lggd.shorten(@long_url)
268
+ res = Shortly::Clients::ShortSwitch.shorten(@long_url)
193
269
  res.shortUrl.should_not be_empty
194
270
  res.shortUrl.should == @short_url
195
271
  end
196
272
 
197
273
  it "result should be an instance of OpenStruct" do
198
- res = Shortly::Clients::Lggd.shorten(@long_url)
274
+ res = Shortly::Clients::ShortSwitch.shorten(@long_url)
199
275
  res.should be_an_instance_of(OpenStruct)
200
276
  end
201
277
 
202
278
  it "should throw an error on wrong uri format" do
203
279
  lambda do
204
- Shortly::Clients::Lggd.shorten(@invalid_url)
280
+ Shortly::Clients::ShortSwitch.shorten(@invalid_url)
205
281
  end.should raise_error(Shortly::Errors::InvalidURIError)
206
282
  end
207
283
 
208
284
  end
209
285
 
286
+ #tests for client sn.im
287
+ describe "Snim" do
288
+ before(:all) do
289
+ @snim = Shortly::Clients::Snim
290
+ @snim.apiKey = "TESTKEY"
291
+ @snim.login = "TESTER"
292
+ @long_url = "http://bagwanpankaj.com/"
293
+ @invalid_url = "bagwanpankaj.com"
294
+ @short_url = "http://sn.im/1wvkof"
295
+ @uri = @snim.base_uri
296
+ end
297
+
298
+ it "should get a short url from Snim(provided valid url)" do
299
+ mock_request_for(@uri + "/getsnip", :method => :post,
300
+ :fixture => "snim_shorten")
301
+
302
+ res = @snim.shorten(@long_url)
303
+ res.shortUrl.should_not be_empty
304
+ res.shortUrl.should == @short_url
305
+ end
306
+
307
+ it "should get analytics from Snim(provided valid id)" do
308
+ mock_request_for(@uri + "/getsnipdetails", :method => :post,
309
+ :fixture => "snim_analytics")
310
+
311
+ res = @snim.analytics("1wvkof")
312
+ res.url.should_not be_empty
313
+ res.clicks.should_not be_nil
314
+ res.clicks.should == 10000
315
+ end
316
+
317
+ it "should get long url from Snim(provided valid shorturl)" do
318
+ mock_request_for(@uri + "/getsnipdetails", :method => :post,
319
+ :fixture => "snim_analytics")
320
+
321
+ res = @snim.expand(@short_url)
322
+ res.url.should_not be_empty
323
+ res.url.should == @long_url
324
+ end
325
+ end
326
+
210
327
  describe "Client" do
211
328
 
212
329
  before(:all) do
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'cgi'
3
4
  require 'rspec'
4
5
  require 'shortly'
5
-
6
+ require 'fakeweb'
6
7
  # Requires supporting files with custom matchers and macros, etc,
7
8
  # in ./support/ and its subdirectories.
8
9
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+ include FakewebStub
11
+ FakeWeb.allow_net_connect = false
9
12
 
10
13
  RSpec.configure do |config|
11
14
 
@@ -0,0 +1,16 @@
1
+ module FakewebStub
2
+
3
+ def mock_request_for(url, options = {})
4
+
5
+ method = options[:method] || :get
6
+ fixture = options[:fixture] || "Fakeweb request body"
7
+ content_type = options[:content_type] || "application/json"
8
+ body = begin
9
+ File.read(File.expand_path(File.dirname(__FILE__)) + "/../fixtures/#{fixture}.json")
10
+ rescue Errno::ENOENT
11
+ raise "Could not find fixture file named '#{fixture}'!"
12
+ end
13
+
14
+ FakeWeb.register_uri(method, url, :body => body, :status => ["200", "OK"], :content_type => content_type)
15
+ end
16
+ 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: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 1
10
- version: 0.3.1
9
+ - 2
10
+ version: 0.3.2
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-23 00:00:00 +05:30
18
+ date: 2011-01-26 00:00:00 +05:30
19
19
  default_executable: shortly
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -108,6 +108,20 @@ dependencies:
108
108
  - 0
109
109
  version: "0"
110
110
  requirement: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ type: :development
113
+ prerelease: false
114
+ name: fakeweb
115
+ version_requirements: &id007 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ requirement: *id007
111
125
  description: Ruby Wrapper for different Url Shortner Services Ruby Wrapper
112
126
  email: bagwanpankaj@gmail.com
113
127
  executables:
@@ -126,8 +140,9 @@ files:
126
140
  - lib/shortly/clients/bitly.rb
127
141
  - lib/shortly/clients/googl.rb
128
142
  - lib/shortly/clients/isgd.rb
129
- - lib/shortly/clients/lggd.rb
130
- - lib/shortly/clients/rubyurl.rb
143
+ - lib/shortly/clients/jmp.rb
144
+ - lib/shortly/clients/shortswitch.rb
145
+ - lib/shortly/clients/snim.rb
131
146
  - lib/shortly/clients/tinyurl.rb
132
147
  - lib/shortly/clients/vgd.rb
133
148
  - lib/shortly/errors.rb
@@ -135,6 +150,7 @@ files:
135
150
  - README.textile
136
151
  - spec/shortly_spec.rb
137
152
  - spec/spec_helper.rb
153
+ - spec/support/fakeweb_stub.rb
138
154
  has_rdoc: true
139
155
  homepage: http://github.com/bagwanpankaj/shortly
140
156
  licenses:
@@ -172,3 +188,4 @@ summary: Url Shortner Services Ruby Wrapper
172
188
  test_files:
173
189
  - spec/shortly_spec.rb
174
190
  - spec/spec_helper.rb
191
+ - spec/support/fakeweb_stub.rb