goshortener 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +26 -0
- data/lib/goshortener.rb +38 -0
- metadata +79 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Lakshmanan Muthukrishnan
|
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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= GoShortener
|
2
|
+
|
3
|
+
Uses Google URL shortener API service to shorten/expand given URLs.
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
=== Initialize and shorten urls
|
8
|
+
go = GoShortener.new
|
9
|
+
short_url = go.shorten "http://github.com/luckydev"
|
10
|
+
|
11
|
+
=== To expand short urls
|
12
|
+
long_url = go.lengthen short_url
|
13
|
+
|
14
|
+
=== Example usage in irb
|
15
|
+
ruby-1.9.2-p136 :001 > require "goshortener"
|
16
|
+
=> true
|
17
|
+
ruby-1.9.2-p136 :002 > go = GoShortener.new
|
18
|
+
=> #<GoShortener:0x93b35e0 @base_url="https://www.googleapis.com/urlshortener/v1/url">
|
19
|
+
ruby-1.9.2-p136 :003 > go.shorten "http://github.com/luckydev"
|
20
|
+
=> "http://goo.gl/TCZHi"
|
21
|
+
ruby-1.9.2-p136 :004 > go.lengthen "http://goo.gl/TCZHi"
|
22
|
+
=> "http://github.com/luckydev"
|
23
|
+
|
24
|
+
== Author
|
25
|
+
|
26
|
+
lakshmanan (lucky.developer@gmail.com)
|
data/lib/goshortener.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
|
4
|
+
require "rest_client"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
|
8
|
+
class GoShortener
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@base_url = "https://www.googleapis.com/urlshortener/v1/url"
|
12
|
+
end
|
13
|
+
|
14
|
+
def shorten(long_url)
|
15
|
+
if long_url.is_a? String
|
16
|
+
request_json = {'longUrl' => long_url}.to_json
|
17
|
+
response = RestClient.post @base_url, request_json, :accept => :json, :content_type => :json
|
18
|
+
else
|
19
|
+
raise "Please provide a valid Long url string"
|
20
|
+
end
|
21
|
+
response = JSON.parse response
|
22
|
+
short_url = response["id"]
|
23
|
+
return short_url
|
24
|
+
end
|
25
|
+
|
26
|
+
def lengthen(short_url)
|
27
|
+
if short_url.is_a? String
|
28
|
+
request_params = {:shortUrl => short_url}
|
29
|
+
response = RestClient.get @base_url, :params => request_params
|
30
|
+
else
|
31
|
+
raise "Please provide a valid short url string"
|
32
|
+
end
|
33
|
+
response = JSON.parse response
|
34
|
+
long_url = response["longUrl"]
|
35
|
+
return long_url
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: goshortener
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: "1.0"
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- lakshmanan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-05 00:00:00 +05:30
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: json
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
description: GoShortener uses Google URL shortener service to shorten/expand urls.
|
39
|
+
email: lucky.developer@gmail.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- README.rdoc
|
48
|
+
- MIT-LICENSE
|
49
|
+
- lib/goshortener.rb
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/luckydev/goshortener
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.5.0
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: GoShortener uses Google URL shortener service to shorten/expand urls.
|
78
|
+
test_files: []
|
79
|
+
|