googl 0.3.0 → 0.4.0

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 CHANGED
@@ -17,6 +17,9 @@ Google URL Shortener API in Ruby
17
17
  url.qr_code
18
18
  => "http://goo.gl/ump4S.qr"
19
19
 
20
+ url.info
21
+ => "http://goo.gl/ump4S.info"
22
+
20
23
  === Expand a short URL
21
24
 
22
25
  url = Googl.expand('http://goo.gl/ump4S')
@@ -101,6 +104,24 @@ Top platforms or OSes, e.g. "Windows"; sorted by (descending) click counts.
101
104
 
102
105
  For details, see http://code.google.com/intl/pt-BR/apis/urlshortener/v1/reference.html#resource_url
103
106
 
107
+ == History
108
+
109
+ Gets a user's history of shortened URLs. (Authenticated)
110
+
111
+ client = Googl.client('user@gmail.com', 'my_valid_password')
112
+
113
+ history = client.history
114
+ history.total_items
115
+ => 19
116
+
117
+ A list of URL.
118
+
119
+ history.items
120
+
121
+ Analytics details for all items
122
+
123
+ history = client.history(:projection => :analytics_clicks)
124
+
104
125
  == Installation
105
126
 
106
127
  gem install googl
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
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.3.0"
8
+ s.version = "0.4.0"
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-01-17}
12
+ s.date = %q{2011-01-19}
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 = [
@@ -40,6 +40,8 @@ Gem::Specification.new do |s|
40
40
  "spec/fixtures/expand_projection_full.json",
41
41
  "spec/fixtures/expand_projection_strings.json",
42
42
  "spec/fixtures/expand_removed.json",
43
+ "spec/fixtures/history.json",
44
+ "spec/fixtures/history_projection_clicks.json",
43
45
  "spec/fixtures/shorten.json",
44
46
  "spec/fixtures/shorten_authenticated.json",
45
47
  "spec/fixtures/shorten_invalid_content_type.json",
data/lib/googl/base.rb CHANGED
@@ -1,6 +1,30 @@
1
1
  module Googl
2
2
 
3
- class Base # :nodoc:
3
+ class Base
4
+
5
+ # URL for QR Code
6
+ #
7
+ # url = Googl.shorten('http://goo.gl/ump4S')
8
+ # ur.qr_code
9
+ # => http://goo.gl/ump4S.qr
10
+ #
11
+ # Usage:
12
+ #
13
+ # <img src="http://goo.gl/ump4S.qr" />
14
+ #
15
+ def qr_code
16
+ "#{short_url}.qr"
17
+ end
18
+
19
+ # URL for analytics
20
+ #
21
+ # url = Googl.shorten('http://goo.gl/ump4S')
22
+ # ur.info
23
+ # => http://goo.gl/ump4S.info
24
+ #
25
+ def info
26
+ "#{short_url}.info"
27
+ end
4
28
 
5
29
  private
6
30
 
@@ -2,17 +2,16 @@ module Googl
2
2
 
3
3
  class ClientLogin < Base
4
4
 
5
- API_URL = "https://www.google.com/accounts/ClientLogin"
5
+ API_URL = "https://www.google.com/accounts/ClientLogin"
6
+ API_HISTORY_URL = "https://www.googleapis.com/urlshortener/v1/url/history"
6
7
 
7
- PARAMS = {'accountType' => 'HOSTED_OR_GOOGLE', 'service' => 'urlshortener', 'source' => 'gem-googl-ruby'}
8
-
9
- attr_accessor :code
8
+ attr_accessor :code, :items
10
9
 
11
10
  # The Google URL Shortener API ClientLogin authentication. See Googl.client
12
11
  #
13
12
  def initialize(email, passwd)
14
13
  modify_headers('Content-Type' => 'application/x-www-form-urlencoded')
15
- resp = Request.post(API_URL, :body => PARAMS.merge!('Email' => email, 'Passwd' => passwd))
14
+ resp = Request.post(API_URL, :body => params.merge!('Email' => email, 'Passwd' => passwd))
16
15
  @code = resp.code
17
16
  if resp.code == 200
18
17
  token = resp.split('=').last.gsub(/\n/, '')
@@ -30,6 +29,37 @@ module Googl
30
29
  Googl::Shorten.new(url)
31
30
  end
32
31
 
32
+ # Gets a user's history of shortened URLs. (Authenticated)
33
+ #
34
+ # client = Googl.client('user@gmail.com', 'my_valid_password')
35
+ #
36
+ # history = client.history
37
+ # history.total_items
38
+ # => 19
39
+ #
40
+ # A list of URL.
41
+ #
42
+ # history.items
43
+ #
44
+ # Analytics details for all items
45
+ #
46
+ # history = client.history(:projection => :analytics_clicks)
47
+ #
48
+ def history(options={})
49
+ resp = options.blank? ? Request.get(API_HISTORY_URL) : Request.get(API_HISTORY_URL, :query => options)
50
+ if resp.code == 200
51
+ @items = resp.parsed_response.to_openstruct
52
+ else
53
+ raise Exception.new("#{resp.code} #{resp.parsed_response}")
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def params
60
+ {'accountType' => 'HOSTED_OR_GOOGLE', 'service' => 'urlshortener', 'source' => 'gem-googl-ruby'}
61
+ end
62
+
33
63
  end
34
64
 
35
65
  end
data/lib/googl/expand.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  module Googl
2
2
 
3
- class Expand
3
+ class Expand < Base
4
4
 
5
5
  API_URL = "https://www.googleapis.com/urlshortener/v1/url"
6
6
 
7
- attr_accessor :long_url, :analytics, :status
7
+ attr_accessor :long_url, :analytics, :status, :short_url
8
8
 
9
9
  # Expands a short URL or gets creation time and analytics. See Googl.expand
10
10
  #
@@ -17,6 +17,7 @@ module Googl
17
17
  @long_url = resp['longUrl']
18
18
  @analytics = resp['analytics'].to_openstruct if resp.has_key?('analytics')
19
19
  @status = resp['status']
20
+ @short_url = resp['id']
20
21
  else
21
22
  raise Exception.new("#{resp.code} #{resp.message}")
22
23
  end
data/lib/googl/shorten.rb CHANGED
@@ -20,20 +20,6 @@ module Googl
20
20
  end
21
21
  end
22
22
 
23
- # URL for QR Code
24
- #
25
- # url = Googl.shorten('http://goo.gl/ump4S')
26
- # ur.qr_code
27
- # => http://goo.gl/ump4S.qr
28
- #
29
- # Usage:
30
- #
31
- # <img src="http://goo.gl/ump4S.qr" />
32
- #
33
- def qr_code
34
- "#{short_url}.qr" if !short_url.blank?
35
- end
36
-
37
23
  end
38
24
 
39
25
  end
data/spec/client_spec.rb CHANGED
@@ -24,8 +24,6 @@ describe Googl::ClientLogin do
24
24
 
25
25
  context "when invalid" do
26
26
 
27
- subject { Googl.client('my_invalid_gmail', 'my_invalid_passwod') }
28
-
29
27
  it "should return BadAuthentication" do
30
28
  lambda { Googl.client('my_invalid_gmail', 'my_invalid_passwod') }.should raise_error(Exception, /403 Error=BadAuthentication/)
31
29
  end
@@ -34,7 +32,7 @@ describe Googl::ClientLogin do
34
32
 
35
33
  end
36
34
 
37
- context "request new shor url" do
35
+ context "request new short url" do
38
36
 
39
37
  before :each do
40
38
  @client = Googl.client('my_user@gmail.com', 'my_valid_password')
@@ -52,4 +50,73 @@ describe Googl::ClientLogin do
52
50
 
53
51
  end
54
52
 
53
+ context "when gets a user history of shortened" do
54
+
55
+ let(:client) { Googl.client('my_user@gmail.com', 'my_valid_password') }
56
+
57
+ it { client.should respond_to(:history) }
58
+
59
+ subject { client.history }
60
+
61
+ it { subject.should respond_to(:total_items) }
62
+ it { subject.should respond_to(:items_per_page) }
63
+
64
+ describe "#items" do
65
+
66
+ it { subject.should respond_to(:items) }
67
+
68
+ let(:item) { subject.items.first }
69
+
70
+ it { item.kind.should == 'urlshortener#url'}
71
+ it { item.label.should == 'http://goo.gl/Ue8sQ' }
72
+ it { item.long_url.should == 'http://facebook.com/' }
73
+ it { item.status.should == 'OK' }
74
+ it { item.created.should be_instance_of(Time)}
75
+
76
+ end
77
+
78
+ context "with projection" do
79
+
80
+ context "analytics_clicks" do
81
+
82
+ subject { client.history(:projection => :analytics_clicks) }
83
+
84
+ describe "#analytics" do
85
+
86
+ let(:item) { subject.items.first }
87
+
88
+ it { item.should respond_to(:analytics) }
89
+
90
+ describe "#all_time" do
91
+ let(:all_time) { item.analytics.all_time }
92
+ it { all_time.should respond_to(:short_url_clicks) }
93
+ end
94
+
95
+ describe "#month" do
96
+ let(:month) { subject.items.first.analytics.month }
97
+ it { month.should respond_to(:short_url_clicks) }
98
+ end
99
+
100
+ describe "#week" do
101
+ let(:week) { subject.items.first.analytics.week }
102
+ it { week.should respond_to(:short_url_clicks) }
103
+ end
104
+
105
+ describe "#day" do
106
+ let(:day) { subject.items.first.analytics.day }
107
+ it { day.should respond_to(:short_url_clicks) }
108
+ end
109
+
110
+ describe "#two_hours" do
111
+ let(:two_hours) { subject.items.first.analytics.two_hours }
112
+ it { two_hours.should respond_to(:short_url_clicks) }
113
+ end
114
+ end
115
+
116
+ end
117
+
118
+ end
119
+
120
+ end
121
+
55
122
  end
data/spec/expand_spec.rb CHANGED
@@ -42,6 +42,18 @@ describe Googl::Expand do
42
42
  end
43
43
  end
44
44
 
45
+ describe "#qr_code" do
46
+ it "should return a url for generate a qr code" do
47
+ subject.qr_code.should == 'http://goo.gl/7lob.qr'
48
+ end
49
+ end
50
+
51
+ describe "#info" do
52
+ it "should return url for analytics" do
53
+ subject.info.should == 'http://goo.gl/7lob.info'
54
+ end
55
+ end
56
+
45
57
  context "with projection" do
46
58
 
47
59
  context "full" do
@@ -0,0 +1,152 @@
1
+ HTTP/1.1 200 OK
2
+ ETag: "EEZ1AD443JkEgW3KJFaymzTd26A/0Nsa5rkDJGqkjbl2cYt7w_X1fNY"
3
+ Expires: Tue, 18 Jan 2011 22:27:13 GMT
4
+ Date: Tue, 18 Jan 2011 22:27:13 GMT
5
+ Cache-Control: private, max-age=0, 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#urlHistory",
15
+ "totalItems": 19,
16
+ "itemsPerPage": 30,
17
+ "items": [
18
+ {
19
+ "kind": "urlshortener#url",
20
+ "id": "http://goo.gl/Ue8sQ",
21
+ "longUrl": "http://facebook.com/",
22
+ "status": "OK",
23
+ "created": "2011-01-13T21:39:17.271+00:00"
24
+ },
25
+ {
26
+ "kind": "urlshortener#url",
27
+ "id": "http://goo.gl/Si1FH",
28
+ "longUrl": "http://globo.com/",
29
+ "status": "OK",
30
+ "created": "2011-01-13T18:35:57.146+00:00"
31
+ },
32
+ {
33
+ "kind": "urlshortener#url",
34
+ "id": "http://goo.gl/YdbC7",
35
+ "longUrl": "http://valeideia.com.br/",
36
+ "status": "OK",
37
+ "created": "2011-01-13T18:29:57.086+00:00"
38
+ },
39
+ {
40
+ "kind": "urlshortener#url",
41
+ "id": "http://goo.gl/EYwdh",
42
+ "longUrl": "http://www.zigotto.net/",
43
+ "status": "OK",
44
+ "created": "2011-01-13T18:04:50.387+00:00"
45
+ },
46
+ {
47
+ "kind": "urlshortener#url",
48
+ "id": "http://goo.gl/AT2BW",
49
+ "longUrl": "http://www.zigotto.net/",
50
+ "status": "OK",
51
+ "created": "2011-01-13T14:52:30.401+00:00"
52
+ },
53
+ {
54
+ "kind": "urlshortener#url",
55
+ "id": "http://goo.gl/Ju6Bn",
56
+ "longUrl": "http://www.zigotto.net/",
57
+ "status": "OK",
58
+ "created": "2011-01-13T13:43:10.197+00:00"
59
+ },
60
+ {
61
+ "kind": "urlshortener#url",
62
+ "id": "http://goo.gl/4JIf6",
63
+ "longUrl": "http://euheueuhe.net/",
64
+ "status": "OK",
65
+ "created": "2011-01-13T13:39:43.335+00:00"
66
+ },
67
+ {
68
+ "kind": "urlshortener#url",
69
+ "id": "http://goo.gl/7w7QL",
70
+ "longUrl": "http://uol.com.br/",
71
+ "status": "OK",
72
+ "created": "2011-01-13T13:38:31.442+00:00"
73
+ },
74
+ {
75
+ "kind": "urlshortener#url",
76
+ "id": "http://goo.gl/NUydr",
77
+ "longUrl": "http://www.zigotto.net/",
78
+ "status": "OK",
79
+ "created": "2011-01-13T13:36:50.013+00:00"
80
+ },
81
+ {
82
+ "kind": "urlshortener#url",
83
+ "id": "http://goo.gl/OoQrm",
84
+ "longUrl": "http://www.zigotto.net/",
85
+ "status": "OK",
86
+ "created": "2011-01-13T13:30:35.533+00:00"
87
+ },
88
+ {
89
+ "kind": "urlshortener#url",
90
+ "id": "http://goo.gl/r3Rtx",
91
+ "longUrl": "http://www.zigotto.net/",
92
+ "status": "OK",
93
+ "created": "2011-01-13T13:17:12.163+00:00"
94
+ },
95
+ {
96
+ "kind": "urlshortener#url",
97
+ "id": "http://goo.gl/KyVNi",
98
+ "longUrl": "http://www.zigotto.net/",
99
+ "status": "OK",
100
+ "created": "2011-01-13T13:14:26.260+00:00"
101
+ },
102
+ {
103
+ "kind": "urlshortener#url",
104
+ "id": "http://goo.gl/R3mYj",
105
+ "longUrl": "http://www.zigotto.net/",
106
+ "status": "OK",
107
+ "created": "2011-01-13T13:07:26.670+00:00"
108
+ },
109
+ {
110
+ "kind": "urlshortener#url",
111
+ "id": "http://goo.gl/DWDfi",
112
+ "longUrl": "https://github.com/zigotto/googl",
113
+ "status": "OK",
114
+ "created": "2011-01-13T03:48:10.309+00:00"
115
+ },
116
+ {
117
+ "kind": "urlshortener#url",
118
+ "id": "http://goo.gl/bQlzC",
119
+ "longUrl": "http://www.zigotto.com/",
120
+ "status": "OK",
121
+ "created": "2011-01-13T03:46:45.726+00:00"
122
+ },
123
+ {
124
+ "kind": "urlshortener#url",
125
+ "id": "http://goo.gl/DyrZA",
126
+ "longUrl": "http://www.zigotto.com/",
127
+ "status": "OK",
128
+ "created": "2011-01-13T03:45:13.289+00:00"
129
+ },
130
+ {
131
+ "kind": "urlshortener#url",
132
+ "id": "http://goo.gl/79b6R",
133
+ "longUrl": "http://www.zigotto.com.br/",
134
+ "status": "OK",
135
+ "created": "2011-01-13T02:53:38.731+00:00"
136
+ },
137
+ {
138
+ "kind": "urlshortener#url",
139
+ "id": "http://goo.gl/iKGy3",
140
+ "longUrl": "http://jlopes.me/",
141
+ "status": "OK",
142
+ "created": "2011-01-11T17:31:43.697+00:00"
143
+ },
144
+ {
145
+ "kind": "urlshortener#url",
146
+ "id": "http://goo.gl/7lob",
147
+ "longUrl": "http://jlopes.zigotto.com.br/",
148
+ "status": "OK",
149
+ "created": "2010-10-01T13:26:04.029+00:00"
150
+ }
151
+ ]
152
+ }
@@ -0,0 +1,499 @@
1
+ HTTP/1.1 200 OK
2
+ ETag: "EEZ1AD443JkEgW3KJFaymzTd26A/PbzQ2L06oEe6J7JEar98vOUL7gI"
3
+ Expires: Tue, 18 Jan 2011 22:35:56 GMT
4
+ Date: Tue, 18 Jan 2011 22:35:56 GMT
5
+ Cache-Control: private, max-age=0, 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#urlHistory",
15
+ "totalItems": 20,
16
+ "itemsPerPage": 30,
17
+ "items": [
18
+ {
19
+ "kind": "urlshortener#url",
20
+ "id": "http://goo.gl/Ue8sQ",
21
+ "longUrl": "http://facebook.com/",
22
+ "status": "OK",
23
+ "created": "2011-01-13T21:39:17.271+00:00",
24
+ "analytics": {
25
+ "allTime": {
26
+ "shortUrlClicks": "1"
27
+ },
28
+ "month": {
29
+ "shortUrlClicks": "1"
30
+ },
31
+ "week": {
32
+ "shortUrlClicks": "1"
33
+ },
34
+ "day": {
35
+ "shortUrlClicks": "0"
36
+ },
37
+ "twoHours": {
38
+ "shortUrlClicks": "0"
39
+ }
40
+ }
41
+ },
42
+ {
43
+ "kind": "urlshortener#url",
44
+ "id": "http://goo.gl/OSsmn",
45
+ "longUrl": "http://icity.com.br/",
46
+ "status": "OK",
47
+ "created": "2011-01-13T19:25:10.266+00:00",
48
+ "analytics": {
49
+ "allTime": {
50
+ "shortUrlClicks": "3"
51
+ },
52
+ "month": {
53
+ "shortUrlClicks": "3"
54
+ },
55
+ "week": {
56
+ "shortUrlClicks": "3"
57
+ },
58
+ "day": {
59
+ "shortUrlClicks": "0"
60
+ },
61
+ "twoHours": {
62
+ "shortUrlClicks": "0"
63
+ }
64
+ }
65
+ },
66
+ {
67
+ "kind": "urlshortener#url",
68
+ "id": "http://goo.gl/Si1FH",
69
+ "longUrl": "http://globo.com/",
70
+ "status": "OK",
71
+ "created": "2011-01-13T18:35:57.146+00:00",
72
+ "analytics": {
73
+ "allTime": {
74
+ "shortUrlClicks": "0"
75
+ },
76
+ "month": {
77
+ "shortUrlClicks": "0"
78
+ },
79
+ "week": {
80
+ "shortUrlClicks": "0"
81
+ },
82
+ "day": {
83
+ "shortUrlClicks": "0"
84
+ },
85
+ "twoHours": {
86
+ "shortUrlClicks": "0"
87
+ }
88
+ }
89
+ },
90
+ {
91
+ "kind": "urlshortener#url",
92
+ "id": "http://goo.gl/YdbC7",
93
+ "longUrl": "http://valeideia.com.br/",
94
+ "status": "OK",
95
+ "created": "2011-01-13T18:29:57.086+00:00",
96
+ "analytics": {
97
+ "allTime": {
98
+ "shortUrlClicks": "0"
99
+ },
100
+ "month": {
101
+ "shortUrlClicks": "0"
102
+ },
103
+ "week": {
104
+ "shortUrlClicks": "0"
105
+ },
106
+ "day": {
107
+ "shortUrlClicks": "0"
108
+ },
109
+ "twoHours": {
110
+ "shortUrlClicks": "0"
111
+ }
112
+ }
113
+ },
114
+ {
115
+ "kind": "urlshortener#url",
116
+ "id": "http://goo.gl/EYwdh",
117
+ "longUrl": "http://www.zigotto.net/",
118
+ "status": "OK",
119
+ "created": "2011-01-13T18:04:50.387+00:00",
120
+ "analytics": {
121
+ "allTime": {
122
+ "shortUrlClicks": "0"
123
+ },
124
+ "month": {
125
+ "shortUrlClicks": "0"
126
+ },
127
+ "week": {
128
+ "shortUrlClicks": "0"
129
+ },
130
+ "day": {
131
+ "shortUrlClicks": "0"
132
+ },
133
+ "twoHours": {
134
+ "shortUrlClicks": "0"
135
+ }
136
+ }
137
+ },
138
+ {
139
+ "kind": "urlshortener#url",
140
+ "id": "http://goo.gl/AT2BW",
141
+ "longUrl": "http://www.zigotto.net/",
142
+ "status": "OK",
143
+ "created": "2011-01-13T14:52:30.401+00:00",
144
+ "analytics": {
145
+ "allTime": {
146
+ "shortUrlClicks": "0"
147
+ },
148
+ "month": {
149
+ "shortUrlClicks": "0"
150
+ },
151
+ "week": {
152
+ "shortUrlClicks": "0"
153
+ },
154
+ "day": {
155
+ "shortUrlClicks": "0"
156
+ },
157
+ "twoHours": {
158
+ "shortUrlClicks": "0"
159
+ }
160
+ }
161
+ },
162
+ {
163
+ "kind": "urlshortener#url",
164
+ "id": "http://goo.gl/Ju6Bn",
165
+ "longUrl": "http://www.zigotto.net/",
166
+ "status": "OK",
167
+ "created": "2011-01-13T13:43:10.197+00:00",
168
+ "analytics": {
169
+ "allTime": {
170
+ "shortUrlClicks": "0"
171
+ },
172
+ "month": {
173
+ "shortUrlClicks": "0"
174
+ },
175
+ "week": {
176
+ "shortUrlClicks": "0"
177
+ },
178
+ "day": {
179
+ "shortUrlClicks": "0"
180
+ },
181
+ "twoHours": {
182
+ "shortUrlClicks": "0"
183
+ }
184
+ }
185
+ },
186
+ {
187
+ "kind": "urlshortener#url",
188
+ "id": "http://goo.gl/4JIf6",
189
+ "longUrl": "http://euheueuhe.net/",
190
+ "status": "OK",
191
+ "created": "2011-01-13T13:39:43.335+00:00",
192
+ "analytics": {
193
+ "allTime": {
194
+ "shortUrlClicks": "0"
195
+ },
196
+ "month": {
197
+ "shortUrlClicks": "0"
198
+ },
199
+ "week": {
200
+ "shortUrlClicks": "0"
201
+ },
202
+ "day": {
203
+ "shortUrlClicks": "0"
204
+ },
205
+ "twoHours": {
206
+ "shortUrlClicks": "0"
207
+ }
208
+ }
209
+ },
210
+ {
211
+ "kind": "urlshortener#url",
212
+ "id": "http://goo.gl/7w7QL",
213
+ "longUrl": "http://uol.com.br/",
214
+ "status": "OK",
215
+ "created": "2011-01-13T13:38:31.442+00:00",
216
+ "analytics": {
217
+ "allTime": {
218
+ "shortUrlClicks": "1"
219
+ },
220
+ "month": {
221
+ "shortUrlClicks": "1"
222
+ },
223
+ "week": {
224
+ "shortUrlClicks": "1"
225
+ },
226
+ "day": {
227
+ "shortUrlClicks": "0"
228
+ },
229
+ "twoHours": {
230
+ "shortUrlClicks": "0"
231
+ }
232
+ }
233
+ },
234
+ {
235
+ "kind": "urlshortener#url",
236
+ "id": "http://goo.gl/NUydr",
237
+ "longUrl": "http://www.zigotto.net/",
238
+ "status": "OK",
239
+ "created": "2011-01-13T13:36:50.013+00:00",
240
+ "analytics": {
241
+ "allTime": {
242
+ "shortUrlClicks": "0"
243
+ },
244
+ "month": {
245
+ "shortUrlClicks": "0"
246
+ },
247
+ "week": {
248
+ "shortUrlClicks": "0"
249
+ },
250
+ "day": {
251
+ "shortUrlClicks": "0"
252
+ },
253
+ "twoHours": {
254
+ "shortUrlClicks": "0"
255
+ }
256
+ }
257
+ },
258
+ {
259
+ "kind": "urlshortener#url",
260
+ "id": "http://goo.gl/OoQrm",
261
+ "longUrl": "http://www.zigotto.net/",
262
+ "status": "OK",
263
+ "created": "2011-01-13T13:30:35.533+00:00",
264
+ "analytics": {
265
+ "allTime": {
266
+ "shortUrlClicks": "0"
267
+ },
268
+ "month": {
269
+ "shortUrlClicks": "0"
270
+ },
271
+ "week": {
272
+ "shortUrlClicks": "0"
273
+ },
274
+ "day": {
275
+ "shortUrlClicks": "0"
276
+ },
277
+ "twoHours": {
278
+ "shortUrlClicks": "0"
279
+ }
280
+ }
281
+ },
282
+ {
283
+ "kind": "urlshortener#url",
284
+ "id": "http://goo.gl/r3Rtx",
285
+ "longUrl": "http://www.zigotto.net/",
286
+ "status": "OK",
287
+ "created": "2011-01-13T13:17:12.163+00:00",
288
+ "analytics": {
289
+ "allTime": {
290
+ "shortUrlClicks": "0"
291
+ },
292
+ "month": {
293
+ "shortUrlClicks": "0"
294
+ },
295
+ "week": {
296
+ "shortUrlClicks": "0"
297
+ },
298
+ "day": {
299
+ "shortUrlClicks": "0"
300
+ },
301
+ "twoHours": {
302
+ "shortUrlClicks": "0"
303
+ }
304
+ }
305
+ },
306
+ {
307
+ "kind": "urlshortener#url",
308
+ "id": "http://goo.gl/KyVNi",
309
+ "longUrl": "http://www.zigotto.net/",
310
+ "status": "OK",
311
+ "created": "2011-01-13T13:14:26.260+00:00",
312
+ "analytics": {
313
+ "allTime": {
314
+ "shortUrlClicks": "0"
315
+ },
316
+ "month": {
317
+ "shortUrlClicks": "0"
318
+ },
319
+ "week": {
320
+ "shortUrlClicks": "0"
321
+ },
322
+ "day": {
323
+ "shortUrlClicks": "0"
324
+ },
325
+ "twoHours": {
326
+ "shortUrlClicks": "0"
327
+ }
328
+ }
329
+ },
330
+ {
331
+ "kind": "urlshortener#url",
332
+ "id": "http://goo.gl/R3mYj",
333
+ "longUrl": "http://www.zigotto.net/",
334
+ "status": "OK",
335
+ "created": "2011-01-13T13:07:26.670+00:00",
336
+ "analytics": {
337
+ "allTime": {
338
+ "shortUrlClicks": "0"
339
+ },
340
+ "month": {
341
+ "shortUrlClicks": "0"
342
+ },
343
+ "week": {
344
+ "shortUrlClicks": "0"
345
+ },
346
+ "day": {
347
+ "shortUrlClicks": "0"
348
+ },
349
+ "twoHours": {
350
+ "shortUrlClicks": "0"
351
+ }
352
+ }
353
+ },
354
+ {
355
+ "kind": "urlshortener#url",
356
+ "id": "http://goo.gl/DWDfi",
357
+ "longUrl": "https://github.com/zigotto/googl",
358
+ "status": "OK",
359
+ "created": "2011-01-13T03:48:10.309+00:00",
360
+ "analytics": {
361
+ "allTime": {
362
+ "shortUrlClicks": "20"
363
+ },
364
+ "month": {
365
+ "shortUrlClicks": "20"
366
+ },
367
+ "week": {
368
+ "shortUrlClicks": "20"
369
+ },
370
+ "day": {
371
+ "shortUrlClicks": "0"
372
+ },
373
+ "twoHours": {
374
+ "shortUrlClicks": "0"
375
+ }
376
+ }
377
+ },
378
+ {
379
+ "kind": "urlshortener#url",
380
+ "id": "http://goo.gl/bQlzC",
381
+ "longUrl": "http://www.zigotto.com/",
382
+ "status": "OK",
383
+ "created": "2011-01-13T03:46:45.726+00:00",
384
+ "analytics": {
385
+ "allTime": {
386
+ "shortUrlClicks": "0"
387
+ },
388
+ "month": {
389
+ "shortUrlClicks": "0"
390
+ },
391
+ "week": {
392
+ "shortUrlClicks": "0"
393
+ },
394
+ "day": {
395
+ "shortUrlClicks": "0"
396
+ },
397
+ "twoHours": {
398
+ "shortUrlClicks": "0"
399
+ }
400
+ }
401
+ },
402
+ {
403
+ "kind": "urlshortener#url",
404
+ "id": "http://goo.gl/DyrZA",
405
+ "longUrl": "http://www.zigotto.com/",
406
+ "status": "OK",
407
+ "created": "2011-01-13T03:45:13.289+00:00",
408
+ "analytics": {
409
+ "allTime": {
410
+ "shortUrlClicks": "0"
411
+ },
412
+ "month": {
413
+ "shortUrlClicks": "0"
414
+ },
415
+ "week": {
416
+ "shortUrlClicks": "0"
417
+ },
418
+ "day": {
419
+ "shortUrlClicks": "0"
420
+ },
421
+ "twoHours": {
422
+ "shortUrlClicks": "0"
423
+ }
424
+ }
425
+ },
426
+ {
427
+ "kind": "urlshortener#url",
428
+ "id": "http://goo.gl/79b6R",
429
+ "longUrl": "http://www.zigotto.com.br/",
430
+ "status": "OK",
431
+ "created": "2011-01-13T02:53:38.731+00:00",
432
+ "analytics": {
433
+ "allTime": {
434
+ "shortUrlClicks": "0"
435
+ },
436
+ "month": {
437
+ "shortUrlClicks": "0"
438
+ },
439
+ "week": {
440
+ "shortUrlClicks": "0"
441
+ },
442
+ "day": {
443
+ "shortUrlClicks": "0"
444
+ },
445
+ "twoHours": {
446
+ "shortUrlClicks": "0"
447
+ }
448
+ }
449
+ },
450
+ {
451
+ "kind": "urlshortener#url",
452
+ "id": "http://goo.gl/iKGy3",
453
+ "longUrl": "http://jlopes.me/",
454
+ "status": "OK",
455
+ "created": "2011-01-11T17:31:43.697+00:00",
456
+ "analytics": {
457
+ "allTime": {
458
+ "shortUrlClicks": "1"
459
+ },
460
+ "month": {
461
+ "shortUrlClicks": "1"
462
+ },
463
+ "week": {
464
+ "shortUrlClicks": "0"
465
+ },
466
+ "day": {
467
+ "shortUrlClicks": "0"
468
+ },
469
+ "twoHours": {
470
+ "shortUrlClicks": "0"
471
+ }
472
+ }
473
+ },
474
+ {
475
+ "kind": "urlshortener#url",
476
+ "id": "http://goo.gl/7lob",
477
+ "longUrl": "http://jlopes.zigotto.com.br/",
478
+ "status": "OK",
479
+ "created": "2010-10-01T13:26:04.029+00:00",
480
+ "analytics": {
481
+ "allTime": {
482
+ "shortUrlClicks": "2"
483
+ },
484
+ "month": {
485
+ "shortUrlClicks": "1"
486
+ },
487
+ "week": {
488
+ "shortUrlClicks": "1"
489
+ },
490
+ "day": {
491
+ "shortUrlClicks": "0"
492
+ },
493
+ "twoHours": {
494
+ "shortUrlClicks": "0"
495
+ }
496
+ }
497
+ }
498
+ ]
499
+ }
data/spec/shorten_spec.rb CHANGED
@@ -45,6 +45,12 @@ describe Googl::Shorten do
45
45
  end
46
46
  end
47
47
 
48
+ describe "#info" do
49
+ it "should return url for analytics" do
50
+ subject.info.should == 'http://goo.gl/ump4S.info'
51
+ end
52
+ end
53
+
48
54
  end
49
55
 
50
56
  end
data/spec/spec_helper.rb CHANGED
@@ -74,4 +74,14 @@ def fake_urls
74
74
  :headers => {'Authorization'=>'GoogleLogin auth=DQAAAK8AAAC9ahL-o7g', 'Content-Type'=>'application/json'}).
75
75
  to_return(load_fixture('shorten_authenticated.json'))
76
76
 
77
+ # History
78
+ stub_request(:get, "https://www.googleapis.com/urlshortener/v1/url/history").
79
+ with(:headers => {'Authorization'=>'GoogleLogin auth=DQAAAK8AAAC9ahL-o7g'}).
80
+ to_return(load_fixture('history.json'))
81
+
82
+ # History with projection ANALYTICS_CLICKS
83
+ stub_request(:get, "https://www.googleapis.com/urlshortener/v1/url/history?projection=analytics_clicks").
84
+ with(:headers => {'Authorization'=>'GoogleLogin auth=DQAAAK8AAAC9ahL-o7g'}).
85
+ to_return(load_fixture('history_projection_clicks.json'))
86
+
77
87
  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: 19
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
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-01-17 00:00:00 -02:00
18
+ date: 2011-01-19 00:00:00 -02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -161,6 +161,8 @@ files:
161
161
  - spec/fixtures/expand_projection_full.json
162
162
  - spec/fixtures/expand_projection_strings.json
163
163
  - spec/fixtures/expand_removed.json
164
+ - spec/fixtures/history.json
165
+ - spec/fixtures/history_projection_clicks.json
164
166
  - spec/fixtures/shorten.json
165
167
  - spec/fixtures/shorten_authenticated.json
166
168
  - spec/fixtures/shorten_invalid_content_type.json