google_url_shortner 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.redcar/tags +25 -1
- data/README.rdoc +34 -3
- data/VERSION +1 -1
- data/google_url_shortner.gemspec +3 -20
- data/lib/google_url_shortner.rb +83 -15
- metadata +6 -16
- data/lib/google/expander.rb +0 -18
- data/lib/google/request.rb +0 -6
- data/lib/google/shortner.rb +0 -20
- data/spec/expand_spec.rb +0 -24
- data/spec/fixtures/expand.json +0 -18
- data/spec/fixtures/shorten.json +0 -18
- data/spec/shorten_spec.rb +0 -29
- data/spec/spec_helper.rb +0 -27
data/.redcar/tags
CHANGED
@@ -1 +1,25 @@
|
|
1
|
-
|
1
|
+
1295084597
|
2
|
+
Analytics /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb class Analytics
|
3
|
+
Client /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb class Client
|
4
|
+
Expander /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb class Expander
|
5
|
+
Google /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb module Google
|
6
|
+
Google /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb module Google
|
7
|
+
Google /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb module Google
|
8
|
+
Google /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb module Google
|
9
|
+
Request /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb class Request
|
10
|
+
Shortner /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb class Shortner
|
11
|
+
UrlShortner /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb module UrlShortner
|
12
|
+
UrlShortner /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb module UrlShortner
|
13
|
+
expand /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb def expand(url)
|
14
|
+
initialize /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb def initialize
|
15
|
+
initialize /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb def initialize( url="" )
|
16
|
+
initialize /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb def initialize( short_url="" )
|
17
|
+
initialize /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb def initialize(long_url)
|
18
|
+
long_url /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb attr_reader :long_url, :short_url
|
19
|
+
long_url /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb attr_accessor :short_url, :long_url
|
20
|
+
long_url /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb attr_accessor :short_url, :long_url
|
21
|
+
short_url /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb attr_reader :long_url, :short_url
|
22
|
+
short_url /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb attr_accessor :short_url, :long_url
|
23
|
+
short_url /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb attr_accessor :short_url, :long_url
|
24
|
+
shorten /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb def shorten(url)
|
25
|
+
visitors /home/hassane/ruby_apps/google_url_shortner/lib/google_url_shortner.rb attr_reader :visitors,
|
data/README.rdoc
CHANGED
@@ -6,12 +6,43 @@ Client Ruby pour accèder à l'API Google URL Shortener.
|
|
6
6
|
|
7
7
|
gem install google_url_shortner
|
8
8
|
|
9
|
+
|
10
|
+
= Nouveautés :
|
11
|
+
|
12
|
+
-- Google::UrlShortner::Analytics --
|
13
|
+
Cette classe nous donne un accès complet aux analytics de Url Shortner :
|
14
|
+
|
15
|
+
* visiteurs
|
16
|
+
* plateformes
|
17
|
+
* navigateurs
|
18
|
+
* pays
|
19
|
+
|
20
|
+
-- Google::UrlShortner::Client --
|
21
|
+
Shorten et Expand pour encoder et décoder une adress.
|
22
|
+
|
23
|
+
Exemple :
|
24
|
+
|
25
|
+
-- Google::UrlShortner::Client.shorten( long_url ) --
|
26
|
+
|
27
|
+
-- Google::UrlShortner::Client.expand( short_url) --
|
28
|
+
|
9
29
|
== Utilisation
|
10
30
|
|
31
|
+
|
32
|
+
pre.
|
33
|
+
|
34
|
+
require "rubygems"
|
35
|
+
|
11
36
|
require "google_url_shortner"
|
12
37
|
|
13
|
-
client
|
38
|
+
Création d'un client connecté à l'API Google Url Shorten
|
39
|
+
|
40
|
+
client = Google::UrlShortner::Client.new
|
41
|
+
|
42
|
+
# Shortening an url.
|
43
|
+
|
44
|
+
resp = client.shorten("http://www.gtug-dakar.org")
|
14
45
|
|
15
|
-
|
46
|
+
#Getting analytics.
|
16
47
|
|
17
|
-
|
48
|
+
analytics = client.get_analytics_for(resp.short_url)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/google_url_shortner.gemspec
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
1
|
|
6
2
|
Gem::Specification.new do |s|
|
7
3
|
s.name = %q{google_url_shortner}
|
@@ -22,27 +18,14 @@ Gem::Specification.new do |s|
|
|
22
18
|
"README.rdoc",
|
23
19
|
"Rakefile",
|
24
20
|
"VERSION",
|
25
|
-
"
|
26
|
-
"lib/google_url_shortner.rb"
|
27
|
-
"lib/google/expander.rb",
|
28
|
-
"lib/google/request.rb",
|
29
|
-
"lib/google/shortner.rb",
|
30
|
-
"spec/expand_spec.rb",
|
31
|
-
"spec/fixtures/expand.json",
|
32
|
-
"spec/fixtures/shorten.json",
|
33
|
-
"spec/shorten_spec.rb",
|
34
|
-
"spec/spec_helper.rb"
|
21
|
+
"google_url_shortner.gemspec",
|
22
|
+
"lib/google_url_shortner.rb"
|
35
23
|
]
|
36
24
|
s.homepage = %q{http://github.com/hkairi/google_url_shortner}
|
37
25
|
s.licenses = ["MIT"]
|
38
26
|
s.require_paths = ["lib"]
|
39
27
|
s.rubygems_version = %q{1.4.2}
|
40
|
-
s.summary = %q{Client Ruby pour accèder à l'API Google URL Shortener.}
|
41
|
-
s.test_files = [
|
42
|
-
"spec/expand_spec.rb",
|
43
|
-
"spec/shorten_spec.rb",
|
44
|
-
"spec/spec_helper.rb"
|
45
|
-
]
|
28
|
+
s.summary = %q{Client Ruby pour accèder à l'API Google URL Shortener et aux Analytics.}
|
46
29
|
|
47
30
|
if s.respond_to? :specification_version then
|
48
31
|
s.specification_version = 3
|
data/lib/google_url_shortner.rb
CHANGED
@@ -1,18 +1,86 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
require "rubygems"
|
2
|
+
require "httparty"
|
3
|
+
# Google::UrlShortner::Analytics
|
4
|
+
module Google
|
5
|
+
module UrlShortner
|
6
|
+
class Analytics
|
7
|
+
attr_reader :visitors,
|
8
|
+
:browsers,
|
9
|
+
:countries,
|
10
|
+
:platforms,
|
11
|
+
:long_url
|
12
|
+
|
13
|
+
def initialize( url="" )
|
14
|
+
return {} if url == ""
|
15
|
+
resp ||= Request.get("/urlshortener/v1/url?shortUrl=#{url}&projection=FULL")
|
16
|
+
@analytics ||= resp['analytics']['allTime'] if resp
|
17
|
+
|
18
|
+
@long_url = url
|
19
|
+
@visitors = @analytics['shortUrlClicks'].to_i if @analytics
|
20
|
+
@browsers = @analytics['browsers'] if @analytics
|
21
|
+
@countries = @analytics['countries'] if @analytics
|
22
|
+
@platforms = @analytics['platforms'] if @analytics
|
23
|
+
[@long_url]
|
24
|
+
end
|
25
|
+
end
|
12
26
|
end
|
13
|
-
|
14
|
-
|
15
|
-
|
27
|
+
end
|
28
|
+
# Google::UrlShortner::Client
|
29
|
+
module Google
|
30
|
+
module UrlShortner
|
31
|
+
class Client
|
32
|
+
attr_reader :long_url, :short_url
|
33
|
+
#Création d'un nouveau client.
|
34
|
+
def initialize
|
35
|
+
@short_url = @long_url = nil
|
36
|
+
end
|
37
|
+
# Crée la short url d'un site donné.
|
38
|
+
def shorten(url)
|
39
|
+
Google::Shortner.new(url)
|
40
|
+
end
|
41
|
+
# Retrouve ou retourne l'url d'un site donné à partir du "short_url"
|
42
|
+
def expand(url)
|
43
|
+
Google::Expander.new(url)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
# Google::UrlShortner::Expander
|
49
|
+
module Google
|
50
|
+
class Expander
|
51
|
+
attr_accessor :short_url, :long_url
|
52
|
+
def initialize( short_url="" )
|
53
|
+
return nil if !short_url.blank?
|
54
|
+
rep = Request.get("/urlshortener/v1/url?shortUrl=#{short_url}")
|
55
|
+
if rep.code == 200
|
56
|
+
self.long_url = rep['longUrl']
|
57
|
+
self.short_url = short_url
|
58
|
+
else
|
59
|
+
rep.response
|
60
|
+
end
|
61
|
+
end
|
16
62
|
end
|
17
|
-
|
18
63
|
end
|
64
|
+
# Google::UrlShortner::Shortner
|
65
|
+
module Google
|
66
|
+
class Shortner
|
67
|
+
attr_accessor :short_url, :long_url
|
68
|
+
def initialize(long_url)
|
69
|
+
options = {"longUrl" => long_url}.inspect
|
70
|
+
resp = Request.post('/urlshortener/v1/url', :body => options)
|
71
|
+
if resp.code == 200
|
72
|
+
self.short_url = resp['id']
|
73
|
+
self.long_url = resp['longUrl']
|
74
|
+
else
|
75
|
+
resp.response
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
# Google::UrlShortner::Resquest
|
81
|
+
class Request
|
82
|
+
include HTTParty
|
83
|
+
base_uri 'https://www.googleapis.com'
|
84
|
+
headers 'Content-Type' => 'application/json'
|
85
|
+
headers "Content-length" => "0"
|
86
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_url_shortner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Hassane Moustapha
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-15 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -129,15 +129,7 @@ files:
|
|
129
129
|
- Rakefile
|
130
130
|
- VERSION
|
131
131
|
- google_url_shortner.gemspec
|
132
|
-
- lib/google/expander.rb
|
133
|
-
- lib/google/request.rb
|
134
|
-
- lib/google/shortner.rb
|
135
132
|
- lib/google_url_shortner.rb
|
136
|
-
- spec/expand_spec.rb
|
137
|
-
- spec/fixtures/expand.json
|
138
|
-
- spec/fixtures/shorten.json
|
139
|
-
- spec/shorten_spec.rb
|
140
|
-
- spec/spec_helper.rb
|
141
133
|
has_rdoc: true
|
142
134
|
homepage: http://github.com/hkairi/google_url_shortner
|
143
135
|
licenses:
|
@@ -172,7 +164,5 @@ rubygems_version: 1.4.1
|
|
172
164
|
signing_key:
|
173
165
|
specification_version: 3
|
174
166
|
summary: "Client Ruby pour acc\xC3\xA8der \xC3\xA0 l'API Google URL Shortener."
|
175
|
-
test_files:
|
176
|
-
|
177
|
-
- spec/shorten_spec.rb
|
178
|
-
- spec/spec_helper.rb
|
167
|
+
test_files: []
|
168
|
+
|
data/lib/google/expander.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Google
|
2
|
-
|
3
|
-
class Expander
|
4
|
-
|
5
|
-
attr_accessor :long_url
|
6
|
-
|
7
|
-
def initialize(short_url)
|
8
|
-
rep = Request.get("/urlshortener/v1/url?shortUrl=#{short_url}")
|
9
|
-
if rep.code == 200
|
10
|
-
self.long_url = rep['longUrl']
|
11
|
-
else
|
12
|
-
rep.response
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
data/lib/google/request.rb
DELETED
data/lib/google/shortner.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module Google
|
2
|
-
|
3
|
-
class Shortner
|
4
|
-
|
5
|
-
attr_accessor :short_url, :long_url
|
6
|
-
|
7
|
-
def initialize(long_url)
|
8
|
-
options = {"longUrl" => long_url}.inspect
|
9
|
-
resp = Request.post('/urlshortener/v1/url', :body => options)
|
10
|
-
if resp.code == 200
|
11
|
-
self.short_url = resp['id']
|
12
|
-
self.long_url = resp['longUrl']
|
13
|
-
else
|
14
|
-
resp.response
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
data/spec/expand_spec.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Googl::Expand do
|
4
|
-
|
5
|
-
before :each do
|
6
|
-
fake_urls
|
7
|
-
end
|
8
|
-
|
9
|
-
context "when expand any goo.gl short URL" do
|
10
|
-
|
11
|
-
it { Googl.should respond_to(:expand) }
|
12
|
-
|
13
|
-
subject { Googl.expand('http://goo.gl/7lob') }
|
14
|
-
|
15
|
-
describe "#long_url" do
|
16
|
-
it "should return a long url" do
|
17
|
-
subject.long_url.should == 'http://jlopes.zigotto.com.br/'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
end
|
data/spec/fixtures/expand.json
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
HTTP/1.1 200 OK
|
2
|
-
ETag: "EEZ1AD443JkEgW3KJFaymzTd26A/wKW1RiLjLbyUh3AbmrhLHKj0R24"
|
3
|
-
Expires: Tue, 11 Jan 2011 21:49:04 GMT
|
4
|
-
Date: Tue, 11 Jan 2011 21:44:04 GMT
|
5
|
-
Cache-Control: public, max-age=300, must-revalidate, no-transform
|
6
|
-
Content-Type: application/json; charset=UTF-8
|
7
|
-
X-Content-Type-Options: nosniff
|
8
|
-
X-Frame-Options: SAMEORIGIN
|
9
|
-
X-XSS-Protection: 1; mode=block
|
10
|
-
Server: GSE
|
11
|
-
Transfer-Encoding: chunked
|
12
|
-
|
13
|
-
{
|
14
|
-
"kind": "urlshortener#url",
|
15
|
-
"id": "http://goo.gl/7lob",
|
16
|
-
"longUrl": "http://jlopes.zigotto.com.br/",
|
17
|
-
"status": "OK"
|
18
|
-
}
|
data/spec/fixtures/shorten.json
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
HTTP/1.1 200 OK
|
2
|
-
ETag: "EEZ1AD443JkEgW3KJFaymzTd26A/1axClUUG_6eCdLbWHvqnOKYu85E"
|
3
|
-
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
|
4
|
-
Pragma: no-cache
|
5
|
-
Expires: Fri, 01 Jan 1990 00:00:00 GMT
|
6
|
-
Date: Tue, 11 Jan 2011 21:26:33 GMT
|
7
|
-
Content-Type: application/json; charset=UTF-8
|
8
|
-
X-Content-Type-Options: nosniff
|
9
|
-
X-Frame-Options: SAMEORIGIN
|
10
|
-
X-XSS-Protection: 1; mode=block
|
11
|
-
Server: GSE
|
12
|
-
Transfer-Encoding: chunked
|
13
|
-
|
14
|
-
{
|
15
|
-
"kind": "urlshortener#url",
|
16
|
-
"id": "http://goo.gl/ump4S",
|
17
|
-
"longUrl": "http://www.zigotto.com/"
|
18
|
-
}
|
data/spec/shorten_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Googl::Shorten do
|
4
|
-
|
5
|
-
before :each do
|
6
|
-
fake_urls
|
7
|
-
end
|
8
|
-
|
9
|
-
context "when request new short url" do
|
10
|
-
|
11
|
-
it { Googl.should respond_to(:shorten) }
|
12
|
-
|
13
|
-
subject { Googl.shorten('http://www.zigotto.com') }
|
14
|
-
|
15
|
-
describe "#short_url" do
|
16
|
-
it "should return a short URL" do
|
17
|
-
subject.short_url.should == 'http://goo.gl/ump4S'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#long_url" do
|
22
|
-
it "should return a long url" do
|
23
|
-
subject.long_url.should == 'http://www.zigotto.com/'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "rspec"
|
3
|
-
require 'fakeweb'
|
4
|
-
|
5
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__)))
|
6
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
-
|
8
|
-
require 'googl'
|
9
|
-
|
10
|
-
def load_fixture(name)
|
11
|
-
File.join(File.expand_path(File.dirname(__FILE__)), '/fixtures', name)
|
12
|
-
end
|
13
|
-
|
14
|
-
def fake_urls
|
15
|
-
|
16
|
-
FakeWeb.allow_net_connect = false
|
17
|
-
|
18
|
-
# Shorten
|
19
|
-
url = "https://www.googleapis.com/urlshortener/v1/url"
|
20
|
-
options = {"longUrl" => "http://www.zigotto.com"}.inspect
|
21
|
-
FakeWeb.register_uri(:post, url, :response => load_fixture('shorten.json'), :body => options)
|
22
|
-
|
23
|
-
# Expand
|
24
|
-
url = "https://www.googleapis.com/urlshortener/v1/url?shortUrl=http://goo.gl/7lob"
|
25
|
-
FakeWeb.register_uri(:get, url, :response => load_fixture('expand.json'))
|
26
|
-
|
27
|
-
end
|