itrigga-net_helper 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -151,17 +151,17 @@ module Itrigga
151
151
 
152
152
  # uses the url shortener service defined for this site
153
153
  # by default will use bit.ly
154
- def shorten_url(raw_url,attempts = 0)
154
+ def shorten_url(opts={})
155
+ opts[:attempts] ||= 0
156
+ return opts[:url] if opts[:attempts] > 3
155
157
 
156
- return raw_url if attempts > 3
157
-
158
- url = self.format_url_shortener_api_url(raw_url)
158
+ api_url = self.format_url_shortener_api_url(opts[:url], opts[:config])
159
159
 
160
160
  begin
161
- response = NetHelper.get :url => url
161
+ response = NetHelper.get :url => api_url
162
162
  rescue Exception => e
163
163
  sleep 10 unless defined?(RAILS_ENV) && RAILS_ENV == "test"
164
- return shorten_url(raw_url,attempts+1)
164
+ return shorten_url(:url=>opts[:url], :attempts=>opts[:attempts]+1)
165
165
  end
166
166
 
167
167
  data = JSON.parse(response).recursive_symbolize_keys!
@@ -172,7 +172,7 @@ module Itrigga
172
172
  else # theres been a problem, try again if we have tries left
173
173
 
174
174
  sleep 10 unless defined?(RAILS_ENV) && RAILS_ENV == "test"
175
- return shorten_url(raw_url,attempts+1)
175
+ return shorten_url(:url=>opts[:url], :attempts=>opts[:attempts]+1)
176
176
 
177
177
  end
178
178
 
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'trigga/core_ext'
3
2
 
4
3
  describe "Itrigga::NetHelper" do
5
4
  before(:each) do
@@ -370,23 +369,23 @@ describe "Itrigga::NetHelper" do
370
369
  end
371
370
 
372
371
  describe "with valid input" do
373
- it "should call format_url_shortener_api_url" do
374
- Itrigga::NetHelper.should_receive(:format_url_shortener_api_url).with(@raw_url)
375
- Itrigga::NetHelper.shorten_url(@raw_url)
372
+ it "should call format_url_shortener_api_url with the given url and config" do
373
+ Itrigga::NetHelper.should_receive(:format_url_shortener_api_url).with(@raw_url, {:blart=>'flange'})
374
+ Itrigga::NetHelper.shorten_url(:url=>@raw_url, :config=>{:blart=>'flange'})
376
375
  end
377
376
 
378
377
  it "should return a short url" do
379
- Itrigga::NetHelper.shorten_url(@raw_url).should == @shortened_url
378
+ Itrigga::NetHelper.shorten_url(:url=>@raw_url).should == @shortened_url
380
379
  end
381
380
 
382
381
  it "should return raw_url on web request timesout" do
383
382
  Itrigga::NetHelper.stub!(:get).and_raise(Exception)
384
- Itrigga::NetHelper.shorten_url(@raw_url).should == @raw_url
383
+ Itrigga::NetHelper.shorten_url(:url=>@raw_url).should == @raw_url
385
384
  end
386
385
 
387
386
  it "should return raw url for anything other than a status 200" do
388
387
  Itrigga::NetHelper.stub!(:get).and_return("{\"status_code\":500,\"data\":{\"url\":\"#{@shortened_url}\"}}")
389
- Itrigga::NetHelper.shorten_url(@raw_url).should == @raw_url
388
+ Itrigga::NetHelper.shorten_url(:url=>@raw_url).should == @raw_url
390
389
  end
391
390
 
392
391
  end
data/spec/spec_helper.rb CHANGED
@@ -12,6 +12,8 @@ require 'rspec'
12
12
 
13
13
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
14
  $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+
16
+ require 'itrigga/core_ext'
15
17
  require 'itrigga/net_helper'
16
18
 
17
19
  RSpec.configure do |config|
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itrigga-net_helper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Al Davidson