oso 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ === 2.0.0 / 2011-03-30
2
+
3
+ * Return the unshortened URL if Oso#shorten encounters a problem.
4
+ * Add Oso#shorten!, which raises if it encounters a problem.
5
+
1
6
  === 1.0.1 / 2011-03-28
2
7
 
3
8
  * Support Bundler for development/deployment.
data/Gemfile CHANGED
@@ -1,9 +1,8 @@
1
1
  source :rubygems
2
2
 
3
- gem "new_base_60", "1.0.3"
4
- gem "rack", "1.2.1"
3
+ gem "new_base_60", "1.0.4"
5
4
  gem "redis-namespace", "0.10.0"
6
- gem "sinatra", "1.1.2"
5
+ gem "sinatra", "1.2.1"
7
6
 
8
7
  group :development do
9
8
  gem "heroku"
@@ -13,7 +12,7 @@ group :development do
13
12
  end
14
13
 
15
14
  group :test do
16
- gem "fakeweb", "1.3.0"
17
- gem "minitest", "2.0.2"
18
- gem "mocha", "0.9.12"
15
+ gem "fakeweb"
16
+ gem "minitest"
17
+ gem "mocha"
19
18
  end
data/Gemfile.lock CHANGED
@@ -19,31 +19,30 @@ GEM
19
19
  mime-types (1.16)
20
20
  minitest (2.0.2)
21
21
  mocha (0.9.12)
22
- new_base_60 (1.0.3)
23
- rack (1.2.1)
22
+ new_base_60 (1.0.4)
23
+ rack (1.2.2)
24
24
  rake (0.8.7)
25
25
  redis (2.1.1)
26
26
  redis-namespace (0.10.0)
27
27
  redis (< 3.0.0)
28
28
  rest-client (1.6.1)
29
29
  mime-types (>= 1.16)
30
- sinatra (1.1.2)
30
+ sinatra (1.2.1)
31
31
  rack (~> 1.1)
32
- tilt (~> 1.2)
32
+ tilt (>= 1.2.2, < 2.0)
33
33
  tilt (1.2.2)
34
34
 
35
35
  PLATFORMS
36
36
  ruby
37
37
 
38
38
  DEPENDENCIES
39
- fakeweb (= 1.3.0)
39
+ fakeweb
40
40
  heroku
41
41
  hoe
42
42
  hoe-doofus
43
43
  hoe-git
44
- minitest (= 2.0.2)
45
- mocha (= 0.9.12)
46
- new_base_60 (= 1.0.3)
47
- rack (= 1.2.1)
44
+ minitest
45
+ mocha
46
+ new_base_60 (= 1.0.4)
48
47
  redis-namespace (= 0.10.0)
49
- sinatra (= 1.1.2)
48
+ sinatra (= 1.2.1)
data/README.rdoc CHANGED
@@ -46,6 +46,10 @@ If you install the <tt>oso</tt> RubyGem:
46
46
  Oso.shorten "github.com" # => "http://oso.local/Acf"
47
47
  Oso.shorten "github.com", :life => 30 # => "http://oso.local/Ad0"
48
48
 
49
+ If <tt>Oso.shorten</tt> doesn't receive a response within one second
50
+ it returns the original, unshortened URL. To raise an error, call
51
+ <tt>Oso.shorten!</tt> instead.
52
+
49
53
  Set the <tt>OSO_URL</tt> environment variable to control where the
50
54
  client looks for the server, or see the RDocs for information on
51
55
  creating multiple instances.
data/lib/oso.rb CHANGED
@@ -13,7 +13,7 @@ class Oso
13
13
 
14
14
  # Duh.
15
15
 
16
- VERSION = "1.0.1"
16
+ VERSION = "2.0.0"
17
17
 
18
18
  # :nodoc:
19
19
 
@@ -30,6 +30,12 @@ class Oso
30
30
  instance.shorten(*args)
31
31
  end
32
32
 
33
+ # See #shorten! for more information.
34
+
35
+ def self.shorten! *args
36
+ instance.shorten!(*args)
37
+ end
38
+
33
39
  # A URI. Where does the Oso server live? If unspecified during
34
40
  # initialization it'll default to the contents of the
35
41
  # <tt>OSO_URL</tt> environment variable. If that's unset, it's
@@ -54,10 +60,10 @@ class Oso
54
60
  # the URL can be hit before it's deactivated. Pass a <tt>:name</tt>
55
61
  # option to explicitly set the shortened URL.
56
62
  #
57
- # +shorten+ will raise an Oso::Error if network or server
63
+ # +shorten!+ will raise an Oso::Error if network or server
58
64
  # conditions keep +url+ from being shortened in one second.
59
-
60
- def shorten url, options = {}
65
+
66
+ def shorten! url, options = {}
61
67
  params = options.merge :url => url
62
68
 
63
69
  params[:life] &&= params[:life].to_i
@@ -82,4 +88,11 @@ class Oso
82
88
  end
83
89
  end
84
90
  end
91
+
92
+ # Create a short URL like #shorten!, but return the original URL if
93
+ # an error is raised.
94
+
95
+ def shorten url, options = {}
96
+ shorten! url, options rescue url
97
+ end
85
98
  end
data/test/test_oso.rb CHANGED
@@ -32,6 +32,15 @@ class TestOso < MiniTest::Unit::TestCase
32
32
  assert_equal "bar", Oso.shorten("foo")
33
33
  end
34
34
 
35
+ def test_shorten!
36
+ FakeWeb.register_uri :post, "http://example.org/",
37
+ :body => "http://example.org/1", :status => 201
38
+
39
+ oso = Oso.new "example.org"
40
+
41
+ assert_equal "http://example.org/1", oso.shorten!("whatever")
42
+ end
43
+
35
44
  def test_shorten
36
45
  FakeWeb.register_uri :post, "http://example.org/",
37
46
  :body => "http://example.org/1", :status => 201
@@ -42,13 +51,22 @@ class TestOso < MiniTest::Unit::TestCase
42
51
  end
43
52
 
44
53
  def test_shorten_bad
54
+ FakeWeb.register_uri :post, "http://example.org/",
55
+ :body => "BAD!", :status => 500
56
+
57
+ oso = Oso.new "example.org"
58
+
59
+ assert_equal "whatever", oso.shorten("whatever")
60
+ end
61
+
62
+ def test_shorten_bang_bad
45
63
  FakeWeb.register_uri :post, "http://example.org/",
46
64
  :body => "No luck.", :status => 404
47
65
 
48
66
  oso = Oso.new "example.org"
49
67
 
50
68
  assert_raises Oso::Error do
51
- oso.shorten "blah"
69
+ oso.shorten! "blah"
52
70
  end
53
71
  end
54
72
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oso
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
- - 1
7
+ - 2
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 0
10
+ version: 2.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Audiosocket
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-28 00:00:00 -05:00
18
+ date: 2011-03-30 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency