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 CHANGED
@@ -1,6 +1,7 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem "httparty", ">= 0.6.1"
4
+ gem "json", "1.5.1"
4
5
 
5
6
  group :development do
6
7
  gem "rspec", "~> 2.3.0"
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.6.1)
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
- # Include your dependencies below. Runtime dependencies are required when using your gem,
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.0
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.0"
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-01-19}
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
@@ -1,5 +1,6 @@
1
1
  require 'httparty'
2
2
  require 'ostruct'
3
+ require 'json'
3
4
 
4
5
  require 'googl/base'
5
6
  require 'googl/request'
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}.inspect
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
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Googl::ClientLogin do
4
4
 
5
5
  before :each do
6
- fake_urls
6
+ fake_urls? true
7
7
  end
8
8
 
9
9
  context "request a new client login" do
data/spec/expand_spec.rb CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Googl::Expand do
4
4
 
5
5
  before :each do
6
- fake_urls
6
+ fake_urls? true
7
7
  end
8
8
 
9
9
  context "when expand any goo.gl short URL" do
data/spec/shorten_spec.rb CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Googl::Shorten do
4
4
 
5
5
  before :each do
6
- fake_urls
6
+ fake_urls? true
7
7
  end
8
8
 
9
9
  context "when request new short url" do
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
- # Shorten
18
- url_shorten = "https://www.googleapis.com/urlshortener/v1/url"
19
- params = {"longUrl" => "http://www.zigotto.com"}.inspect
20
- stub_request(:post, url_shorten).
21
- with(:body => params,
22
- :headers => {'Content-Type'=>'application/json'}).
23
- to_return(load_fixture('shorten.json'))
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
-
32
- # Expand
33
- url_expand = "https://www.googleapis.com/urlshortener/v1/url?shortUrl=http://goo.gl/7lob"
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'))
55
-
56
- # Authentication
57
- url_login = "https://www.google.com/accounts/ClientLogin"
58
-
59
- # ClientLogin valid
60
- params = "Passwd=my_valid_password&service=urlshortener&accountType=HOSTED_OR_GOOGLE&Email=my_user%40gmail.com&source=gem-googl-ruby"
61
- stub_request(:post, url_login).
62
- with(:body => params,
63
- :headers => {'Content-Type'=>'application/x-www-form-urlencoded'}).
64
- to_return(load_fixture('client_login_valid.json'))
65
-
66
- # ClientLogin invalid
67
- params = "Passwd=my_invalid_passwod&service=urlshortener&accountType=HOSTED_OR_GOOGLE&Email=my_invalid_gmail&source=gem-googl-ruby"
68
- stub_request(:post, url_login).with(:body => params).to_return(load_fixture('client_login_invalid.json'))
69
-
70
- # Shorten authenticated
71
- params = {"longUrl" => "http://www.zigotto.net"}.inspect
72
- stub_request(:post, url_shorten).
73
- with(:body => params,
74
- :headers => {'Authorization'=>'GoogleLogin auth=DQAAAK8AAAC9ahL-o7g', 'Content-Type'=>'application/json'}).
75
- to_return(load_fixture('shorten_authenticated.json'))
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'))
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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
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-01-19 00:00:00 -02:00
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: &id002 !ruby/object:Gem::Requirement
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: *id002
68
+ requirement: *id003
53
69
  - !ruby/object:Gem::Dependency
54
70
  prerelease: false
55
71
  name: bundler
56
72
  type: :development
57
- version_requirements: &id003 !ruby/object:Gem::Requirement
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: *id003
84
+ requirement: *id004
69
85
  - !ruby/object:Gem::Dependency
70
86
  prerelease: false
71
87
  name: jeweler
72
88
  type: :development
73
- version_requirements: &id004 !ruby/object:Gem::Requirement
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: *id004
100
+ requirement: *id005
85
101
  - !ruby/object:Gem::Dependency
86
102
  prerelease: false
87
103
  name: rcov
88
104
  type: :development
89
- version_requirements: &id005 !ruby/object:Gem::Requirement
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: *id005
114
+ requirement: *id006
99
115
  - !ruby/object:Gem::Dependency
100
116
  prerelease: false
101
117
  name: webmock
102
118
  type: :development
103
- version_requirements: &id006 !ruby/object:Gem::Requirement
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