google_shortener 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/google_shortener.gemspec +1 -1
- data/lib/google_shortener.rb +1 -1
- data/lib/google_shortener/version.rb +1 -1
- data/test/google_shortener_test.rb +47 -0
- metadata +7 -5
data/google_shortener.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ["me@chaitanyavellanki.com"]
|
11
11
|
gem.description = %q{Rubygem to shorten long url}
|
12
12
|
gem.summary = %q{Uses url shortener services from Google}
|
13
|
-
gem.homepage = ""
|
13
|
+
gem.homepage = "https://github.com/chaitanyav/google_shortener"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/lib/google_shortener.rb
CHANGED
@@ -55,7 +55,7 @@ class GoogleShortener
|
|
55
55
|
|
56
56
|
def get_from_google_url_shortener_api(short_url)
|
57
57
|
uri = URI(google_url_shortener_location)
|
58
|
-
params = {'shortUrl' => short_url}
|
58
|
+
params = {'shortUrl' => short_url, 'key' => @api_key}
|
59
59
|
uri.query = URI.encode_www_form(params)
|
60
60
|
req = Net::HTTP::Get.new(uri.request_uri)
|
61
61
|
req.content_type = 'application/json'
|
@@ -1 +1 @@
|
|
1
|
-
VERSION = "0.0.
|
1
|
+
VERSION = "0.0.2"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/pride'
|
3
|
+
require 'google_shortener'
|
4
|
+
|
5
|
+
class GoogleShortenerTest < MiniTest::Unit::TestCase
|
6
|
+
def test_default_api_key
|
7
|
+
google_shortener = GoogleShortener.new
|
8
|
+
assert 'AIzaSyDOY31us5qGR_MdMQKaTfGlhpOi8w3Ur7U', google_shortener.api_key
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_valid_api_key_with_correct_key
|
12
|
+
google_shortener = GoogleShortener.new
|
13
|
+
google_shortener.api_key = 'AIzaSyDOY31us5qGR_MdMQKaTfGlhpOi8w3Ur7U'
|
14
|
+
assert google_shortener.valid_api_key?
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_valid_api_key_with_incorrect_key
|
18
|
+
google_shortener = GoogleShortener.new
|
19
|
+
google_shortener.api_key = 'foo'
|
20
|
+
assert google_shortener.valid_api_key?
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_shorten_with_long_url
|
24
|
+
google_shortener = GoogleShortener.new
|
25
|
+
assert_equal 'http://goo.gl/fbsS', google_shortener.shorten('http://www.google.com/')
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_shorten_with_no_long_url
|
29
|
+
google_shortener = GoogleShortener.new
|
30
|
+
assert_raises ArgumentError do
|
31
|
+
google_shortener.shorten
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_expand_with_short_url
|
36
|
+
google_shortener = GoogleShortener.new
|
37
|
+
assert_equal 'http://www.google.com/', google_shortener.expand('http://goo.gl/fbsS')
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_expand_with_no_short_url
|
41
|
+
google_shortener = GoogleShortener.new
|
42
|
+
assert_raises ArgumentError do
|
43
|
+
google_shortener.expand
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_shortener
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -58,7 +58,8 @@ files:
|
|
58
58
|
- google_shortener.gemspec
|
59
59
|
- lib/google_shortener.rb
|
60
60
|
- lib/google_shortener/version.rb
|
61
|
-
|
61
|
+
- test/google_shortener_test.rb
|
62
|
+
homepage: https://github.com/chaitanyav/google_shortener
|
62
63
|
licenses: []
|
63
64
|
post_install_message:
|
64
65
|
rdoc_options: []
|
@@ -72,7 +73,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
73
|
version: '0'
|
73
74
|
segments:
|
74
75
|
- 0
|
75
|
-
hash:
|
76
|
+
hash: 2250692420382275581
|
76
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
78
|
none: false
|
78
79
|
requirements:
|
@@ -81,11 +82,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
82
|
version: '0'
|
82
83
|
segments:
|
83
84
|
- 0
|
84
|
-
hash:
|
85
|
+
hash: 2250692420382275581
|
85
86
|
requirements: []
|
86
87
|
rubyforge_project:
|
87
88
|
rubygems_version: 1.8.25
|
88
89
|
signing_key:
|
89
90
|
specification_version: 3
|
90
91
|
summary: Uses url shortener services from Google
|
91
|
-
test_files:
|
92
|
+
test_files:
|
93
|
+
- test/google_shortener_test.rb
|