goshortener 1.0 → 1.1
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.rdoc +6 -0
- data/lib/goshortener.rb +34 -6
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -4,6 +4,12 @@ Uses Google URL shortener API service to shorten/expand given URLs.
|
|
4
4
|
|
5
5
|
== Usage
|
6
6
|
|
7
|
+
=== Installation
|
8
|
+
gem install goshortener
|
9
|
+
|
10
|
+
of if you are using bundler, add the following line to your Gemfile.
|
11
|
+
gem "goshortener"
|
12
|
+
|
7
13
|
=== Initialize and shorten urls
|
8
14
|
go = GoShortener.new
|
9
15
|
short_url = go.shorten "http://github.com/luckydev"
|
data/lib/goshortener.rb
CHANGED
@@ -12,11 +12,17 @@ class GoShortener
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def shorten(long_url)
|
15
|
-
if long_url.is_a?
|
15
|
+
if long_url.is_a?(String)
|
16
16
|
request_json = {'longUrl' => long_url}.to_json
|
17
|
-
|
17
|
+
|
18
|
+
begin
|
19
|
+
response = RestClient.post @base_url, request_json, :accept => :json, :content_type => :json
|
20
|
+
rescue
|
21
|
+
raise "Please provide a valid url string"
|
22
|
+
end
|
23
|
+
|
18
24
|
else
|
19
|
-
raise "Please provide a valid
|
25
|
+
raise "Please provide a valid url string"
|
20
26
|
end
|
21
27
|
response = JSON.parse response
|
22
28
|
short_url = response["id"]
|
@@ -24,11 +30,33 @@ class GoShortener
|
|
24
30
|
end
|
25
31
|
|
26
32
|
def lengthen(short_url)
|
27
|
-
|
33
|
+
##
|
34
|
+
# Accepts a short url shortened by http://goo.gl and returns original
|
35
|
+
# long url.
|
36
|
+
#
|
37
|
+
# Examples:
|
38
|
+
# go = GoShortener.new
|
39
|
+
#
|
40
|
+
# go.lengthen("http://goo.gl/TCZHi") #=> "http://github.com/luckydev"
|
41
|
+
#
|
42
|
+
# go.lengthen("http://www.goo.gl/TCZHi") #=> Error
|
43
|
+
# go.lengthen("goo.gl/TCZHi") #=> Error
|
44
|
+
# go.lengthen("http://goo.gl/") #=> Error
|
45
|
+
# go.lengthen("http://goo.gl/T") #=> Error
|
46
|
+
# go.lengthen("http://bit.ly/TCZHi") #=> Error
|
47
|
+
#
|
48
|
+
##
|
49
|
+
if short_url.is_a?(String)
|
28
50
|
request_params = {:shortUrl => short_url}
|
29
|
-
|
51
|
+
|
52
|
+
begin
|
53
|
+
response = RestClient.get @base_url, :params => request_params
|
54
|
+
rescue
|
55
|
+
raise "Please provide a valid goo.gl short url to lengthen"
|
56
|
+
end
|
57
|
+
|
30
58
|
else
|
31
|
-
raise "Please provide a valid short url
|
59
|
+
raise "Please provide a valid goo.gl short url to lengthen"
|
32
60
|
end
|
33
61
|
response = JSON.parse response
|
34
62
|
long_url = response["longUrl"]
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: goshortener
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: "1.
|
5
|
+
version: "1.1"
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- lakshmanan
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-06 00:00:00 +05:30
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|