GoogleURL 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/GoogleURL.gemspec +30 -0
- data/Manifest +6 -0
- data/README.rdoc +9 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/lib/GoogleURL.rb +50 -0
- data/test/example.rb +12 -0
- metadata +80 -0
data/GoogleURL.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{GoogleURL}
|
5
|
+
s.version = "0.1.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Antonio Barra"]
|
9
|
+
s.date = %q{2011-02-05}
|
10
|
+
s.description = %q{GoogleURL is a library that allows the creation of shortlink using the service's goo.gl.}
|
11
|
+
s.email = %q{antonio.barra [at] ymail.com}
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/GoogleURL.rb"]
|
13
|
+
s.files = ["Manifest", "README.rdoc", "Rakefile", "VERSION", "lib/GoogleURL.rb", "test/example.rb", "GoogleURL.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/Dad-89/GoogleURL}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "GoogleURL", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{googleurl}
|
18
|
+
s.rubygems_version = %q{1.4.2}
|
19
|
+
s.summary = %q{GoogleURL is a library that allows the creation of shortlink using the service's goo.gl.}
|
20
|
+
s.test_files = ["test/example.rb"]
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
data/Manifest
ADDED
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('GoogleURL', '0.1.1') do |p|
|
6
|
+
p.description = "GoogleURL is a library that allows the creation of shortlink using the service's goo.gl."
|
7
|
+
p.url = "http://github.com/Dad-89/GoogleURL"
|
8
|
+
p.author = "Antonio Barra"
|
9
|
+
p.email = "antonio.barra [at] ymail.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.test_pattern = "test/example.rb"
|
12
|
+
p.development_dependencies = []
|
13
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/lib/GoogleURL.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module GoogleURL
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
def self.c(url)
|
7
|
+
regexp = /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix
|
8
|
+
if (regexp =~ url)
|
9
|
+
return true
|
10
|
+
end
|
11
|
+
return false
|
12
|
+
end
|
13
|
+
|
14
|
+
class Shorting
|
15
|
+
def initialize(long_url)
|
16
|
+
if !(GoogleURL.c(long_url))
|
17
|
+
p "#{long_url}: Is not a valid link."
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
par = {#'user' => 'youruser@google.com',
|
21
|
+
'url' => long_url,
|
22
|
+
#'auth_token' => '78925814685'
|
23
|
+
#'key' => "your API key"
|
24
|
+
}
|
25
|
+
res = Net::HTTP.post_form(URI.parse("http://goo.gl/api/url"), par)
|
26
|
+
return_link = JSON.parse(res.body)
|
27
|
+
puts return_link['short_url']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Expand
|
32
|
+
def initialize(short_url)
|
33
|
+
if !(GoogleURL.c(short_url))
|
34
|
+
p "#{short_url}: Is not a valid link."
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
url = "https://www.googleapis.com/urlshortener/v1/url?"
|
38
|
+
uri = URI.parse(url + "shortUrl=" + short_url)
|
39
|
+
# Security check SSL do
|
40
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
41
|
+
http.use_ssl = true
|
42
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
43
|
+
# end
|
44
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
45
|
+
response = http.request(request)
|
46
|
+
return_link = JSON.parse(response.body)
|
47
|
+
puts return_link['longUrl']
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/test/example.rb
ADDED
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: GoogleURL
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Antonio Barra
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-05 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: GoogleURL is a library that allows the creation of shortlink using the service's goo.gl.
|
23
|
+
email: antonio.barra [at] ymail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.rdoc
|
30
|
+
- lib/GoogleURL.rb
|
31
|
+
files:
|
32
|
+
- Manifest
|
33
|
+
- README.rdoc
|
34
|
+
- Rakefile
|
35
|
+
- VERSION
|
36
|
+
- lib/GoogleURL.rb
|
37
|
+
- test/example.rb
|
38
|
+
- GoogleURL.gemspec
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/Dad-89/GoogleURL
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --line-numbers
|
46
|
+
- --inline-source
|
47
|
+
- --title
|
48
|
+
- GoogleURL
|
49
|
+
- --main
|
50
|
+
- README.rdoc
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
hash: 11
|
68
|
+
segments:
|
69
|
+
- 1
|
70
|
+
- 2
|
71
|
+
version: "1.2"
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project: googleurl
|
75
|
+
rubygems_version: 1.4.2
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: GoogleURL is a library that allows the creation of shortlink using the service's goo.gl.
|
79
|
+
test_files:
|
80
|
+
- test/example.rb
|