google_url_shortener 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/google_url_shortener.gemspec +1 -0
- data/lib/google/url_shortener/base.rb +9 -0
- data/lib/google/url_shortener/request.rb +10 -2
- data/lib/google/url_shortener/version.rb +1 -1
- data/spec/lib/google/url_spec.rb +18 -0
- data/spec/spec_helper.rb +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9bec00dccb61bd1d1d9efcc91d4850402906fa8
|
4
|
+
data.tar.gz: ed9858ceeca4165a92761f1227de7cdfb0228cdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70e83728d24df02058e8f23009940d36de3adf495b0b16f5e76af198114f5d9547a70fc7154aafb355c7330b23a764b8303e32fa883f5fbe3b807c285c3c9be0
|
7
|
+
data.tar.gz: 02e3a8b1a43567fab5cd6a3947d8ea0d21254133e5e0078dc2e373b46bfb1cbe1ee2c42a8a7c87fd1db64ea43e258197f1e816492aa224971700b911ae724aa9
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
23
23
|
s.add_development_dependency "rspec", "2.8.0"
|
24
|
+
s.add_development_dependency "rspec-mocks", "2.8.0"
|
24
25
|
s.add_development_dependency "fakeweb"
|
25
26
|
|
26
27
|
s.files = `git ls-files`.split("\n")
|
@@ -2,6 +2,7 @@ module Google
|
|
2
2
|
module UrlShortener
|
3
3
|
class Base
|
4
4
|
class << self
|
5
|
+
@@raise_exceptions = false
|
5
6
|
|
6
7
|
def log=(logger)
|
7
8
|
RestClient.log = logger
|
@@ -18,6 +19,14 @@ module Google
|
|
18
19
|
raise MissingApiKey, "No API key has been set!"
|
19
20
|
end
|
20
21
|
end
|
22
|
+
|
23
|
+
def raise_exceptions=(bool)
|
24
|
+
@@raise_exceptions = !!bool
|
25
|
+
end
|
26
|
+
|
27
|
+
def raise_exceptions
|
28
|
+
@@raise_exceptions
|
29
|
+
end
|
21
30
|
end
|
22
31
|
end
|
23
32
|
end
|
@@ -8,7 +8,11 @@ module Google
|
|
8
8
|
response = RestClient.post(format_url, format_post_params(params), REQUEST_HEADERS)
|
9
9
|
parse(response)
|
10
10
|
rescue => e
|
11
|
-
|
11
|
+
if self.class.raise_exceptions
|
12
|
+
raise e
|
13
|
+
else
|
14
|
+
puts e.inspect
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
def get(params={})
|
@@ -16,7 +20,11 @@ module Google
|
|
16
20
|
response = RestClient.get(full_url)
|
17
21
|
parse(response)
|
18
22
|
rescue => e
|
19
|
-
|
23
|
+
if self.class.raise_exceptions
|
24
|
+
raise e
|
25
|
+
else
|
26
|
+
puts e.inspect
|
27
|
+
end
|
20
28
|
end
|
21
29
|
|
22
30
|
private
|
data/spec/lib/google/url_spec.rb
CHANGED
@@ -26,6 +26,24 @@ module Google
|
|
26
26
|
url.created_at.month.should == 01
|
27
27
|
url.created_at.day.should == 11
|
28
28
|
end
|
29
|
+
|
30
|
+
it "should permit exceptions if raise_exceptions is true" do
|
31
|
+
RestClient.stub(:post) { raise RestClient::Request::RequestFailed }
|
32
|
+
prev_val = Base.raise_exceptions
|
33
|
+
Base.raise_exceptions = true
|
34
|
+
|
35
|
+
url = Google::UrlShortener::Url.new(:long_url => @long_url)
|
36
|
+
expect { url.shorten! }.to raise_error(RestClient::Request::RequestFailed)
|
37
|
+
|
38
|
+
Base.raise_exceptions = prev_val
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not raise exceptions if raise_exceptions is false" do
|
42
|
+
RestClient.stub(:post) { raise RestClient::Request::RequestFailed }
|
43
|
+
|
44
|
+
url = Google::UrlShortener::Url.new(:long_url => @long_url)
|
45
|
+
expect { url.shorten! }.to_not raise_error(RestClient::Request::RequestFailed)
|
46
|
+
end
|
29
47
|
end
|
30
48
|
end
|
31
49
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_url_shortener
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Nesbitt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 2.8.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-mocks
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.8.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.8.0
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: fakeweb
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|