googl 0.2.0 → 0.3.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.
@@ -0,0 +1,17 @@
1
+ HTTP/1.1 200 OK
2
+ ETag: "EEZ1AD443JkEgW3KJFaymzTd26A/gwecVfJbUMJGMk3OPVUqhzMMyY8"
3
+ Expires: Mon, 17 Jan 2011 20:11:13 GMT
4
+ Date: Mon, 17 Jan 2011 20:11:13 GMT
5
+ Cache-Control: public, 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#url",
15
+ "id": "http://goo.gl/R7f68",
16
+ "status": "REMOVED"
17
+ }
@@ -0,0 +1,12 @@
1
+ HTTP/1.1 400 Bad Request
2
+ Content-Type: text/html; charset=UTF-8
3
+ Date: Mon, 17 Jan 2011 20:35:55 GMT
4
+ Expires: Mon, 17 Jan 2011 20:35:55 GMT
5
+ Cache-Control: private, max-age=0
6
+ X-Content-Type-Options: nosniff
7
+ X-Frame-Options: SAMEORIGIN
8
+ X-XSS-Protection: 1; mode=block
9
+ Server: GSE
10
+ Transfer-Encoding: chunked
11
+
12
+ Unsupported content with type: application/x-www-form-urlencoded
@@ -0,0 +1,39 @@
1
+ shared_examples_for 'a period' do
2
+
3
+ describe "#referrers" do
4
+ it { element.should respond_to(:referrers) }
5
+ it { element.referrers.first.should respond_to(:count) }
6
+ it { element.referrers.first.should respond_to(:label) }
7
+ end
8
+
9
+ describe "#countries" do
10
+ it { element.should respond_to(:countries) }
11
+ it { element.countries.first.should respond_to(:count) }
12
+ it { element.countries.first.should respond_to(:label) }
13
+ end
14
+
15
+ describe "#browsers" do
16
+ it { element.should respond_to(:browsers) }
17
+ it { element.browsers.first.should respond_to(:count) }
18
+ it { element.browsers.first.should respond_to(:label) }
19
+ end
20
+
21
+ describe "#platforms" do
22
+ it { element.should respond_to(:platforms) }
23
+ it { element.platforms.first.should respond_to(:count) }
24
+ it { element.platforms.first.should respond_to(:label) }
25
+ end
26
+
27
+ end
28
+
29
+ shared_examples_for 'a clicks' do
30
+
31
+ describe "#short_url_clicks" do
32
+ it { element.should respond_to(:short_url_clicks) }
33
+ end
34
+
35
+ describe "#long_url_clicks" do
36
+ it { element.should respond_to(:long_url_clicks) }
37
+ end
38
+
39
+ end
data/spec/shorten_spec.rb CHANGED
@@ -10,24 +10,41 @@ describe Googl::Shorten do
10
10
 
11
11
  it { Googl.should respond_to(:shorten) }
12
12
 
13
- subject { Googl.shorten('http://www.zigotto.com') }
13
+ context "with invalid url" do
14
14
 
15
- describe "#short_url" do
16
- it "should return a short URL" do
17
- subject.short_url.should == 'http://goo.gl/ump4S'
15
+ it "should return error for required url" do
16
+ lambda { Googl.shorten }.should raise_error(ArgumentError, "URL to shorten is required")
18
17
  end
19
- end
20
18
 
21
- describe "#long_url" do
22
- it "should return a long url" do
23
- subject.long_url.should == 'http://www.zigotto.com/'
19
+ it "should return Unsupported content with type" do
20
+ Request.headers.delete('Content-Type')
21
+ lambda { Googl.shorten('http://www.uol.com') }.should raise_error(Exception, /Unsupported content with type: application\/x-www-form-urlencoded/)
24
22
  end
23
+
25
24
  end
26
25
 
27
- describe "#qr_code" do
28
- it "should return a url for generate a qr code" do
29
- subject.qr_code.should == 'http://goo.gl/ump4S.qr'
26
+ context "with valid url" do
27
+
28
+ subject { Googl.shorten('http://www.zigotto.com') }
29
+
30
+ describe "#short_url" do
31
+ it "should return a short URL" do
32
+ subject.short_url.should == 'http://goo.gl/ump4S'
33
+ end
34
+ end
35
+
36
+ describe "#long_url" do
37
+ it "should return a long url" do
38
+ subject.long_url.should == 'http://www.zigotto.com/'
39
+ end
40
+ end
41
+
42
+ describe "#qr_code" do
43
+ it "should return a url for generate a qr code" do
44
+ subject.qr_code.should == 'http://goo.gl/ump4S.qr'
45
+ end
30
46
  end
47
+
31
48
  end
32
49
 
33
50
  end
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,8 @@ require "rspec"
6
6
  require 'webmock/rspec'
7
7
  require 'googl'
8
8
 
9
+ require 'shared_examples'
10
+
9
11
  def load_fixture(name)
10
12
  File.new(File.join(File.expand_path(File.dirname(__FILE__)), '/fixtures', name))
11
13
  end
@@ -20,9 +22,36 @@ def fake_urls
20
22
  :headers => {'Content-Type'=>'application/json'}).
21
23
  to_return(load_fixture('shorten.json'))
22
24
 
25
+ # Shorten Unsupported content with type
26
+ url_shorten = "https://www.googleapis.com/urlshortener/v1/url"
27
+ params = {"longUrl" => "http://www.uol.com"}.inspect
28
+ stub_request(:post, url_shorten).
29
+ with(:body => params).
30
+ to_return(load_fixture('shorten_invalid_content_type.json'))
31
+
23
32
  # Expand
24
33
  url_expand = "https://www.googleapis.com/urlshortener/v1/url?shortUrl=http://goo.gl/7lob"
25
34
  stub_request(:get, url_expand).to_return(load_fixture('expand.json'))
35
+
36
+ # Expand with projection FULL
37
+ url_expand = "https://www.googleapis.com/urlshortener/v1/url?projection=full&shortUrl=http://goo.gl/DWDfi"
38
+ stub_request(:get, url_expand).to_return(load_fixture('expand_projection_full.json'))
39
+
40
+ # Expand with projection ANALYTICS_CLICKS
41
+ url_expand = "https://www.googleapis.com/urlshortener/v1/url?projection=analytics_clicks&shortUrl=http://goo.gl/DWDfi"
42
+ stub_request(:get, url_expand).to_return(load_fixture('expand_projection_clicks.json'))
43
+
44
+ # Expand with projection ANALYTICS_TOP_STRINGS
45
+ url_expand = "https://www.googleapis.com/urlshortener/v1/url?projection=analytics_top_strings&shortUrl=http://goo.gl/DWDfi"
46
+ stub_request(:get, url_expand).to_return(load_fixture('expand_projection_strings.json'))
47
+
48
+ # Expand error 404
49
+ url_expand = "https://www.googleapis.com/urlshortener/v1/url?shortUrl=http://goo.gl/blajjddkksijj"
50
+ stub_request(:get, url_expand).to_return(load_fixture('expand_404.json'))
51
+
52
+ # Expand REMOVED
53
+ url_expand = "https://www.googleapis.com/urlshortener/v1/url?shortUrl=http://goo.gl/R7f68"
54
+ stub_request(:get, url_expand).to_return(load_fixture('expand_removed.json'))
26
55
 
27
56
  # Authentication
28
57
  url_login = "https://www.google.com/accounts/ClientLogin"
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: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.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-13 00:00:00 -02:00
18
+ date: 2011-01-17 00:00:00 -02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -25,7 +25,7 @@ dependencies:
25
25
  version_requirements: &id001 !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
- - - "="
28
+ - - ">="
29
29
  - !ruby/object:Gem::Version
30
30
  hash: 5
31
31
  segments:
@@ -149,14 +149,22 @@ files:
149
149
  - lib/googl/client_login.rb
150
150
  - lib/googl/expand.rb
151
151
  - lib/googl/request.rb
152
+ - lib/googl/ruby_extensions.rb
152
153
  - lib/googl/shorten.rb
153
154
  - spec/client_spec.rb
154
155
  - spec/expand_spec.rb
155
156
  - spec/fixtures/client_login_invalid.json
156
157
  - spec/fixtures/client_login_valid.json
157
158
  - spec/fixtures/expand.json
159
+ - spec/fixtures/expand_404.json
160
+ - spec/fixtures/expand_projection_clicks.json
161
+ - spec/fixtures/expand_projection_full.json
162
+ - spec/fixtures/expand_projection_strings.json
163
+ - spec/fixtures/expand_removed.json
158
164
  - spec/fixtures/shorten.json
159
165
  - spec/fixtures/shorten_authenticated.json
166
+ - spec/fixtures/shorten_invalid_content_type.json
167
+ - spec/shared_examples.rb
160
168
  - spec/shorten_spec.rb
161
169
  - spec/spec_helper.rb
162
170
  has_rdoc: true
@@ -196,5 +204,6 @@ summary: Wrapper for Google URL Shortener API
196
204
  test_files:
197
205
  - spec/client_spec.rb
198
206
  - spec/expand_spec.rb
207
+ - spec/shared_examples.rb
199
208
  - spec/shorten_spec.rb
200
209
  - spec/spec_helper.rb