googl 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -1
- data/Rakefile +1 -3
- data/VERSION +1 -1
- data/googl.gemspec +5 -5
- data/lib/googl.rb +1 -0
- data/lib/googl/shorten.rb +1 -1
- data/spec/client_spec.rb +1 -1
- data/spec/expand_spec.rb +1 -1
- data/spec/shorten_spec.rb +1 -1
- data/spec/spec_helper.rb +75 -71
- metadata +29 -29
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -5,12 +5,13 @@ GEM
|
|
5
5
|
crack (0.1.8)
|
6
6
|
diff-lcs (1.1.2)
|
7
7
|
git (1.2.5)
|
8
|
-
httparty (0.
|
8
|
+
httparty (0.7.4)
|
9
9
|
crack (= 0.1.8)
|
10
10
|
jeweler (1.5.2)
|
11
11
|
bundler (~> 1.0.0)
|
12
12
|
git (>= 1.2.5)
|
13
13
|
rake
|
14
|
+
json (1.5.1)
|
14
15
|
rake (0.8.7)
|
15
16
|
rcov (0.9.9)
|
16
17
|
rspec (2.3.0)
|
@@ -32,6 +33,7 @@ DEPENDENCIES
|
|
32
33
|
bundler (~> 1.0.0)
|
33
34
|
httparty (>= 0.6.1)
|
34
35
|
jeweler (~> 1.5.2)
|
36
|
+
json (= 1.5.1)
|
35
37
|
rcov
|
36
38
|
rspec (~> 2.3.0)
|
37
39
|
webmock (~> 1.6.2)
|
data/Rakefile
CHANGED
@@ -19,9 +19,7 @@ Jeweler::Tasks.new do |gem|
|
|
19
19
|
gem.description = %Q{Small library for Google URL Shortener API}
|
20
20
|
gem.email = "jlopes@zigotto.com.br"
|
21
21
|
gem.authors = ["Jesus Lopes"]
|
22
|
-
#
|
23
|
-
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
-
gem.add_dependency "httparty", ">= 0.6.1"
|
22
|
+
# dependencies defined in Gemfile
|
25
23
|
end
|
26
24
|
Jeweler::RubygemsDotOrgTasks.new
|
27
25
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/googl.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{googl}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jesus Lopes"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-02-16}
|
13
13
|
s.description = %q{Small library for Google URL Shortener API}
|
14
14
|
s.email = %q{jlopes@zigotto.com.br}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -67,29 +67,29 @@ Gem::Specification.new do |s|
|
|
67
67
|
|
68
68
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
69
69
|
s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
|
70
|
+
s.add_runtime_dependency(%q<json>, ["= 1.5.1"])
|
70
71
|
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
71
72
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
72
73
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
73
74
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
74
75
|
s.add_development_dependency(%q<webmock>, ["~> 1.6.2"])
|
75
|
-
s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
|
76
76
|
else
|
77
77
|
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
78
|
+
s.add_dependency(%q<json>, ["= 1.5.1"])
|
78
79
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
79
80
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
80
81
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
81
82
|
s.add_dependency(%q<rcov>, [">= 0"])
|
82
83
|
s.add_dependency(%q<webmock>, ["~> 1.6.2"])
|
83
|
-
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
84
84
|
end
|
85
85
|
else
|
86
86
|
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
87
|
+
s.add_dependency(%q<json>, ["= 1.5.1"])
|
87
88
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
88
89
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
89
90
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
90
91
|
s.add_dependency(%q<rcov>, [">= 0"])
|
91
92
|
s.add_dependency(%q<webmock>, ["~> 1.6.2"])
|
92
|
-
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
data/lib/googl.rb
CHANGED
data/lib/googl/shorten.rb
CHANGED
@@ -10,7 +10,7 @@ module Googl
|
|
10
10
|
#
|
11
11
|
def initialize(long_url)
|
12
12
|
modify_headers('Content-Type' => 'application/json')
|
13
|
-
options = {"longUrl" => long_url}.
|
13
|
+
options = {"longUrl" => long_url}.to_json
|
14
14
|
resp = Request.post(API_URL, :body => options)
|
15
15
|
if resp.code == 200
|
16
16
|
@short_url = resp['id']
|
data/spec/client_spec.rb
CHANGED
data/spec/expand_spec.rb
CHANGED
data/spec/shorten_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -12,76 +12,80 @@ def load_fixture(name)
|
|
12
12
|
File.new(File.join(File.expand_path(File.dirname(__FILE__)), '/fixtures', name))
|
13
13
|
end
|
14
14
|
|
15
|
-
def fake_urls
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
15
|
+
def fake_urls?(status)
|
16
|
+
|
17
|
+
if status
|
18
|
+
# Shorten
|
19
|
+
url_shorten = "https://www.googleapis.com/urlshortener/v1/url"
|
20
|
+
params = "{\"longUrl\":\"http://www.zigotto.com\"}" #json
|
21
|
+
stub_request(:post, url_shorten).
|
22
|
+
with(:body => params,
|
23
|
+
:headers => {'Content-Type'=>'application/json'}).
|
24
|
+
to_return(load_fixture('shorten.json'))
|
25
|
+
|
26
|
+
# Shorten Unsupported content with type
|
27
|
+
url_shorten = "https://www.googleapis.com/urlshortener/v1/url"
|
28
|
+
params = "{\"longUrl\":\"http://www.uol.com\"}" #json
|
29
|
+
stub_request(:post, url_shorten).
|
30
|
+
with(:body => params).
|
31
|
+
to_return(load_fixture('shorten_invalid_content_type.json'))
|
32
|
+
|
33
|
+
# Expand
|
34
|
+
url_expand = "https://www.googleapis.com/urlshortener/v1/url?shortUrl=http://goo.gl/7lob"
|
35
|
+
stub_request(:get, url_expand).to_return(load_fixture('expand.json'))
|
36
|
+
|
37
|
+
# Expand with projection FULL
|
38
|
+
url_expand = "https://www.googleapis.com/urlshortener/v1/url?projection=full&shortUrl=http://goo.gl/DWDfi"
|
39
|
+
stub_request(:get, url_expand).to_return(load_fixture('expand_projection_full.json'))
|
40
|
+
|
41
|
+
# Expand with projection ANALYTICS_CLICKS
|
42
|
+
url_expand = "https://www.googleapis.com/urlshortener/v1/url?projection=analytics_clicks&shortUrl=http://goo.gl/DWDfi"
|
43
|
+
stub_request(:get, url_expand).to_return(load_fixture('expand_projection_clicks.json'))
|
44
|
+
|
45
|
+
# Expand with projection ANALYTICS_TOP_STRINGS
|
46
|
+
url_expand = "https://www.googleapis.com/urlshortener/v1/url?projection=analytics_top_strings&shortUrl=http://goo.gl/DWDfi"
|
47
|
+
stub_request(:get, url_expand).to_return(load_fixture('expand_projection_strings.json'))
|
48
|
+
|
49
|
+
# Expand error 404
|
50
|
+
url_expand = "https://www.googleapis.com/urlshortener/v1/url?shortUrl=http://goo.gl/blajjddkksijj"
|
51
|
+
stub_request(:get, url_expand).to_return(load_fixture('expand_404.json'))
|
52
|
+
|
53
|
+
# Expand REMOVED
|
54
|
+
url_expand = "https://www.googleapis.com/urlshortener/v1/url?shortUrl=http://goo.gl/R7f68"
|
55
|
+
stub_request(:get, url_expand).to_return(load_fixture('expand_removed.json'))
|
56
|
+
|
57
|
+
# Authentication
|
58
|
+
url_login = "https://www.google.com/accounts/ClientLogin"
|
59
|
+
|
60
|
+
# ClientLogin valid
|
61
|
+
params = "Passwd=my_valid_password&service=urlshortener&accountType=HOSTED_OR_GOOGLE&Email=my_user%40gmail.com&source=gem-googl-ruby"
|
62
|
+
stub_request(:post, url_login).
|
63
|
+
with(:body => params,
|
64
|
+
:headers => {'Content-Type'=>'application/x-www-form-urlencoded'}).
|
65
|
+
to_return(load_fixture('client_login_valid.json'))
|
66
|
+
|
67
|
+
# ClientLogin invalid
|
68
|
+
params = "Passwd=my_invalid_passwod&service=urlshortener&accountType=HOSTED_OR_GOOGLE&Email=my_invalid_gmail&source=gem-googl-ruby"
|
69
|
+
stub_request(:post, url_login).with(:body => params).to_return(load_fixture('client_login_invalid.json'))
|
70
|
+
|
71
|
+
# Shorten authenticated
|
72
|
+
params = "{\"longUrl\":\"http://www.zigotto.net\"}"
|
73
|
+
stub_request(:post, url_shorten).
|
74
|
+
with(:body => params,
|
75
|
+
:headers => {'Authorization'=>'GoogleLogin auth=DQAAAK8AAAC9ahL-o7g', 'Content-Type'=>'application/json'}).
|
76
|
+
to_return(load_fixture('shorten_authenticated.json'))
|
77
|
+
|
78
|
+
# History
|
79
|
+
stub_request(:get, "https://www.googleapis.com/urlshortener/v1/url/history").
|
80
|
+
with(:headers => {'Authorization'=>'GoogleLogin auth=DQAAAK8AAAC9ahL-o7g'}).
|
81
|
+
to_return(load_fixture('history.json'))
|
82
|
+
|
83
|
+
# History with projection ANALYTICS_CLICKS
|
84
|
+
stub_request(:get, "https://www.googleapis.com/urlshortener/v1/url/history?projection=analytics_clicks").
|
85
|
+
with(:headers => {'Authorization'=>'GoogleLogin auth=DQAAAK8AAAC9ahL-o7g'}).
|
86
|
+
to_return(load_fixture('history_projection_clicks.json'))
|
87
|
+
else
|
88
|
+
WebMock.allow_net_connect!
|
89
|
+
end
|
86
90
|
|
87
91
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: googl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 1
|
10
|
+
version: 0.4.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jesus Lopes
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-02-16 00:00:00 -02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -34,11 +34,27 @@ dependencies:
|
|
34
34
|
- 1
|
35
35
|
version: 0.6.1
|
36
36
|
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
prerelease: false
|
39
|
+
name: json
|
40
|
+
type: :runtime
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - "="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 1
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 5
|
50
|
+
- 1
|
51
|
+
version: 1.5.1
|
52
|
+
requirement: *id002
|
37
53
|
- !ruby/object:Gem::Dependency
|
38
54
|
prerelease: false
|
39
55
|
name: rspec
|
40
56
|
type: :development
|
41
|
-
version_requirements: &
|
57
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
42
58
|
none: false
|
43
59
|
requirements:
|
44
60
|
- - ~>
|
@@ -49,12 +65,12 @@ dependencies:
|
|
49
65
|
- 3
|
50
66
|
- 0
|
51
67
|
version: 2.3.0
|
52
|
-
requirement: *
|
68
|
+
requirement: *id003
|
53
69
|
- !ruby/object:Gem::Dependency
|
54
70
|
prerelease: false
|
55
71
|
name: bundler
|
56
72
|
type: :development
|
57
|
-
version_requirements: &
|
73
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
58
74
|
none: false
|
59
75
|
requirements:
|
60
76
|
- - ~>
|
@@ -65,12 +81,12 @@ dependencies:
|
|
65
81
|
- 0
|
66
82
|
- 0
|
67
83
|
version: 1.0.0
|
68
|
-
requirement: *
|
84
|
+
requirement: *id004
|
69
85
|
- !ruby/object:Gem::Dependency
|
70
86
|
prerelease: false
|
71
87
|
name: jeweler
|
72
88
|
type: :development
|
73
|
-
version_requirements: &
|
89
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
74
90
|
none: false
|
75
91
|
requirements:
|
76
92
|
- - ~>
|
@@ -81,12 +97,12 @@ dependencies:
|
|
81
97
|
- 5
|
82
98
|
- 2
|
83
99
|
version: 1.5.2
|
84
|
-
requirement: *
|
100
|
+
requirement: *id005
|
85
101
|
- !ruby/object:Gem::Dependency
|
86
102
|
prerelease: false
|
87
103
|
name: rcov
|
88
104
|
type: :development
|
89
|
-
version_requirements: &
|
105
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
90
106
|
none: false
|
91
107
|
requirements:
|
92
108
|
- - ">="
|
@@ -95,12 +111,12 @@ dependencies:
|
|
95
111
|
segments:
|
96
112
|
- 0
|
97
113
|
version: "0"
|
98
|
-
requirement: *
|
114
|
+
requirement: *id006
|
99
115
|
- !ruby/object:Gem::Dependency
|
100
116
|
prerelease: false
|
101
117
|
name: webmock
|
102
118
|
type: :development
|
103
|
-
version_requirements: &
|
119
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
104
120
|
none: false
|
105
121
|
requirements:
|
106
122
|
- - ~>
|
@@ -111,22 +127,6 @@ dependencies:
|
|
111
127
|
- 6
|
112
128
|
- 2
|
113
129
|
version: 1.6.2
|
114
|
-
requirement: *id006
|
115
|
-
- !ruby/object:Gem::Dependency
|
116
|
-
prerelease: false
|
117
|
-
name: httparty
|
118
|
-
type: :runtime
|
119
|
-
version_requirements: &id007 !ruby/object:Gem::Requirement
|
120
|
-
none: false
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
hash: 5
|
125
|
-
segments:
|
126
|
-
- 0
|
127
|
-
- 6
|
128
|
-
- 1
|
129
|
-
version: 0.6.1
|
130
130
|
requirement: *id007
|
131
131
|
description: Small library for Google URL Shortener API
|
132
132
|
email: jlopes@zigotto.com.br
|