gus 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.bundle/config +2 -0
- data/Gemfile.lock +1 -1
- data/lib/gus/shortener.rb +8 -8
- data/lib/gus/version.rb +1 -1
- data/spec/gus/shortener_spec.rb +5 -0
- metadata +4 -3
data/.bundle/config
ADDED
data/Gemfile.lock
CHANGED
data/lib/gus/shortener.rb
CHANGED
@@ -8,15 +8,15 @@ module Gus
|
|
8
8
|
private
|
9
9
|
|
10
10
|
def get_result(url)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
response = Net::HTTP.post_form(
|
12
|
+
URI.parse('http://goo.gl/api/shorten'),
|
13
|
+
{'url'=>url}
|
14
|
+
)
|
15
|
+
result = Crack::JSON.parse(response.body)
|
16
|
+
if response.code == "201"
|
17
17
|
result['short_url']
|
18
|
-
|
19
|
-
|
18
|
+
else
|
19
|
+
raise result['error_message']
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
data/lib/gus/version.rb
CHANGED
data/spec/gus/shortener_spec.rb
CHANGED
@@ -12,8 +12,13 @@ describe Gus::Shortener do
|
|
12
12
|
it 'should create a shortened url' do
|
13
13
|
shortener.shorten(long_url).should_not be_nil
|
14
14
|
end
|
15
|
+
|
15
16
|
it 'should shorten the url' do
|
16
17
|
short_url = shortener.shorten(long_url)
|
17
18
|
(short_url.length < long_url.length).should be_true
|
18
19
|
end
|
20
|
+
|
21
|
+
it 'should raise an error for a bad url' do
|
22
|
+
lambda{ shortener.shorten("eat more chicken") }.should raise_error( "Bad request" )
|
23
|
+
end
|
19
24
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors: []
|
12
12
|
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-23 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -59,6 +59,7 @@ extensions: []
|
|
59
59
|
extra_rdoc_files: []
|
60
60
|
|
61
61
|
files:
|
62
|
+
- .bundle/config
|
62
63
|
- .gitignore
|
63
64
|
- Gemfile
|
64
65
|
- Gemfile.lock
|