googl-api 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -3
- data/Gemfile.lock +4 -0
- data/VERSION +1 -1
- data/googl-api.gemspec +4 -1
- data/lib/googl-api/client.rb +3 -0
- data/test/helper.rb +6 -1
- data/test/test_googl.rb +79 -3
- metadata +26 -13
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
crack (0.1.8)
|
4
5
|
git (1.2.5)
|
6
|
+
httparty (0.6.1)
|
7
|
+
crack (= 0.1.8)
|
5
8
|
jeweler (1.5.2)
|
6
9
|
bundler (~> 1.0.0)
|
7
10
|
git (>= 1.2.5)
|
@@ -15,6 +18,7 @@ PLATFORMS
|
|
15
18
|
|
16
19
|
DEPENDENCIES
|
17
20
|
bundler (~> 1.0.0)
|
21
|
+
httparty
|
18
22
|
jeweler (~> 1.5.2)
|
19
23
|
rcov
|
20
24
|
shoulda
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/googl-api.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{googl-api}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["John Allen"]
|
@@ -47,12 +47,14 @@ Gem::Specification.new do |s|
|
|
47
47
|
s.specification_version = 3
|
48
48
|
|
49
49
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
50
51
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
51
52
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
53
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
53
54
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
54
55
|
s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
|
55
56
|
else
|
57
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
56
58
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
57
59
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
60
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
@@ -60,6 +62,7 @@ Gem::Specification.new do |s|
|
|
60
62
|
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
61
63
|
end
|
62
64
|
else
|
65
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
63
66
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
64
67
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
68
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
data/lib/googl-api/client.rb
CHANGED
@@ -19,18 +19,21 @@ module GooglApi
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def shorten(url)
|
22
|
+
raise ArgumentError.new("A URL to shorten is required") if url.blank?
|
22
23
|
load_respose(self.class.post('/url', :body => "{ \"longUrl\" => \"#{url}\" }"))
|
23
24
|
# api key not working at this time
|
24
25
|
# load_respose(self.class.post('/url', :query => @api_key, :body => "{ \"longUrl\" => \"#{url}\" }"))
|
25
26
|
end
|
26
27
|
|
27
28
|
def expand(url)
|
29
|
+
raise ArgumentError.new("A URL to expand is required") if url.blank?
|
28
30
|
load_respose(self.class.get('/url', :query => { :shortUrl => url }))
|
29
31
|
# api key not working at this time
|
30
32
|
# load_respose(self.class.get('/url', :query => @api_key.merge({ :shortUrl => url })))
|
31
33
|
end
|
32
34
|
|
33
35
|
def analytics(url, projection = "FULL")
|
36
|
+
raise ArgumentError.new("A URL to check analytics on is required") if url.blank?
|
34
37
|
load_respose(self.class.get('/url', :query => { :shortUrl => url, :projection => projection }))
|
35
38
|
# api key not working at this time
|
36
39
|
# load_respose(self.class.get('/url', :query => @api_key.merge({ :shortUrl => url, :projection => projection })))
|
data/test/helper.rb
CHANGED
@@ -11,8 +11,13 @@ require 'test/unit'
|
|
11
11
|
require 'shoulda'
|
12
12
|
|
13
13
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib', 'googl-api'))
|
14
15
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
-
require '
|
16
|
+
require 'httparty'
|
17
|
+
require 'googl-api'
|
16
18
|
|
17
19
|
class Test::Unit::TestCase
|
20
|
+
def api_key
|
21
|
+
'test_key'
|
22
|
+
end
|
18
23
|
end
|
data/test/test_googl.rb
CHANGED
@@ -1,7 +1,83 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestGoogl < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
context "googl-api module" do
|
5
|
+
should "create a new googl-api client" do
|
6
|
+
c = GooglApi.new(api_key)
|
7
|
+
assert_equal GooglApi::Client, c.class
|
8
|
+
end
|
9
|
+
end
|
10
|
+
context "using the googl-api client" do
|
11
|
+
setup do
|
12
|
+
@client = GooglApi.new(api_key)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "shortening" do
|
16
|
+
context "a single link" do
|
17
|
+
setup do
|
18
|
+
@url = @client.shorten('http://ruby-lang.org/')
|
19
|
+
end
|
20
|
+
should "return a GooglApi::Response" do
|
21
|
+
assert_kind_of GooglApi::Response, @url
|
22
|
+
end
|
23
|
+
should "return a short goo.gl url" do
|
24
|
+
assert_equal "http://goo.gl/p2Jpa", @url.short_url
|
25
|
+
end
|
26
|
+
should "save the long url" do
|
27
|
+
assert_equal "http://ruby-lang.org/", @url.long_url
|
28
|
+
end
|
29
|
+
end
|
30
|
+
context "no links" do
|
31
|
+
should "raise an ArgumentError" do
|
32
|
+
assert_raise ArgumentError do
|
33
|
+
@client.shorten
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
context "expanding" do
|
39
|
+
context "a short bitly url" do
|
40
|
+
setup do
|
41
|
+
@url = @client.expand("http://goo.gl/p2Jpa")
|
42
|
+
end
|
43
|
+
should "return a GooglApi::Response" do
|
44
|
+
assert_kind_of GooglApi::Response, @url
|
45
|
+
end
|
46
|
+
should "return the expanded url" do
|
47
|
+
assert_equal "http://ruby-lang.org/", @url.long_url
|
48
|
+
end
|
49
|
+
should "save the bitly url" do
|
50
|
+
assert_equal "http://goo.gl/p2Jpa", @url.short_url
|
51
|
+
end
|
52
|
+
end
|
53
|
+
context "no links" do
|
54
|
+
should "raise an ArgumentError" do
|
55
|
+
assert_raise ArgumentError do
|
56
|
+
@client.shorten
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
context "to get analytics on" do
|
62
|
+
context "a single link" do
|
63
|
+
setup do
|
64
|
+
@url = @client.analytics("http://goo.gl/p2Jpa")
|
65
|
+
end
|
66
|
+
should "return a GooglApi::Response" do
|
67
|
+
assert_kind_of GooglApi::Response, @url
|
68
|
+
end
|
69
|
+
should "return a response object with analytics data" do
|
70
|
+
assert_not_nil @url.analytics
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
context "no links" do
|
75
|
+
should "raise an ArgumentError" do
|
76
|
+
assert_raise ArgumentError do
|
77
|
+
@client.shorten
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
7
83
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- John Allen
|
@@ -18,7 +18,7 @@ date: 2011-01-11 00:00:00 -05:00
|
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: httparty
|
22
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
23
|
none: false
|
24
24
|
requirements:
|
@@ -27,12 +27,25 @@ dependencies:
|
|
27
27
|
segments:
|
28
28
|
- 0
|
29
29
|
version: "0"
|
30
|
-
type: :
|
30
|
+
type: :runtime
|
31
31
|
prerelease: false
|
32
32
|
version_requirements: *id001
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
34
|
+
name: shoulda
|
35
35
|
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 0
|
42
|
+
version: "0"
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
36
49
|
none: false
|
37
50
|
requirements:
|
38
51
|
- - ~>
|
@@ -44,10 +57,10 @@ dependencies:
|
|
44
57
|
version: 1.0.0
|
45
58
|
type: :development
|
46
59
|
prerelease: false
|
47
|
-
version_requirements: *
|
60
|
+
version_requirements: *id003
|
48
61
|
- !ruby/object:Gem::Dependency
|
49
62
|
name: jeweler
|
50
|
-
requirement: &
|
63
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
64
|
none: false
|
52
65
|
requirements:
|
53
66
|
- - ~>
|
@@ -59,10 +72,10 @@ dependencies:
|
|
59
72
|
version: 1.5.2
|
60
73
|
type: :development
|
61
74
|
prerelease: false
|
62
|
-
version_requirements: *
|
75
|
+
version_requirements: *id004
|
63
76
|
- !ruby/object:Gem::Dependency
|
64
77
|
name: rcov
|
65
|
-
requirement: &
|
78
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
66
79
|
none: false
|
67
80
|
requirements:
|
68
81
|
- - ">="
|
@@ -72,10 +85,10 @@ dependencies:
|
|
72
85
|
version: "0"
|
73
86
|
type: :development
|
74
87
|
prerelease: false
|
75
|
-
version_requirements: *
|
88
|
+
version_requirements: *id005
|
76
89
|
- !ruby/object:Gem::Dependency
|
77
90
|
name: httparty
|
78
|
-
requirement: &
|
91
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
79
92
|
none: false
|
80
93
|
requirements:
|
81
94
|
- - ">="
|
@@ -87,7 +100,7 @@ dependencies:
|
|
87
100
|
version: 0.6.1
|
88
101
|
type: :runtime
|
89
102
|
prerelease: false
|
90
|
-
version_requirements: *
|
103
|
+
version_requirements: *id006
|
91
104
|
description: A very simple ruby wrapper for the goo.gl URL Shortening service
|
92
105
|
email: john@threedogconsulting.com
|
93
106
|
executables: []
|
@@ -126,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
139
|
requirements:
|
127
140
|
- - ">="
|
128
141
|
- !ruby/object:Gem::Version
|
129
|
-
hash: -
|
142
|
+
hash: -930700543394285233
|
130
143
|
segments:
|
131
144
|
- 0
|
132
145
|
version: "0"
|