gmaps_tz 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c398c099a44c91d5f33955f3a21b0030f1a7fca
4
- data.tar.gz: 82895c6d72cd11bce737f9b966145c056a1eb9ea
3
+ metadata.gz: bad89fe2a86197be5e794a2e2ce3385255beeffa
4
+ data.tar.gz: 975f16e7effb3b3459c530e3dec858e59661546a
5
5
  SHA512:
6
- metadata.gz: c5ba752eee35398941adfaa8f15ad240ba860116b232c5148d583c4ce420d0c128a72e00bc61d63e0e185e38b003e7bf430dfc9ca7154243000ca8aaffd46d05
7
- data.tar.gz: cdb5977af5c59a5f87c39808d0d441db79f2f916d470b756105aba5f68c0832e50f422788ccad52ea2346a9852c738dbcbd6b91e0630bafe50dce3f27efed6a4
6
+ metadata.gz: c14993d5e5b240e465180640f4e8aa99f26e5b837073ed358d99dd5f6bffa1d3bece6fbd9d7517b25fc18bcd3665700350d90b430450dc607f7eda32638466cc
7
+ data.tar.gz: 110e3579ce6a4a0d52ed36feee400e37cc812c4c38a02fe1c3d2ad4fef020d82b74e46ee301e44a14f249d1e8ea1e7676fd9833b1ce02acec4957336b5678aba
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ coverage/
@@ -19,13 +19,8 @@ module GmapsTz
19
19
 
20
20
  def get(path, query_params)
21
21
  uri = generate_uri(path, query_params)
22
-
23
22
  response = Net::HTTP.get_response(uri)
24
- if JSON.parse(response.body)["status"] == "OK"
25
- response
26
- else
27
- raise Error.from_response(uri, response)
28
- end
23
+ ResponseParser.new(uri, response).execute
29
24
  end
30
25
 
31
26
  private
@@ -1,8 +1,6 @@
1
1
  module GmapsTz
2
2
  class Error < StandardError
3
- def self.from_response(uri, response)
4
- json = JSON.parse(response.body)
5
-
3
+ def self.from_json(uri, json)
6
4
  klass = case json["status"]
7
5
  when "INVALID_REQUEST"
8
6
  InvalidRequestError
@@ -17,14 +15,14 @@ module GmapsTz
17
15
  else
18
16
  UnexpectedResponseError
19
17
  end
20
- klass.new(uri, response)
18
+ klass.new(uri, json)
21
19
  end
22
20
 
23
- attr_accessor :uri, :result
21
+ attr_accessor :uri, :body
24
22
 
25
- def initialize(uri, result)
23
+ def initialize(uri, body)
26
24
  @uri = uri
27
- @result = result
25
+ @body = body
28
26
  end
29
27
  end
30
28
 
@@ -38,5 +36,7 @@ module GmapsTz
38
36
 
39
37
  class ZeroResultsError < Error; end
40
38
 
39
+ class InvalidResponseBodyError < Error; end
40
+
41
41
  class UnexpectedResponseError < Error; end
42
42
  end
@@ -0,0 +1,29 @@
1
+ module GmapsTz
2
+ class ResponseParser
3
+ def initialize(uri, response)
4
+ @uri
5
+ @response = response
6
+ end
7
+
8
+ def execute
9
+ json = parse_json
10
+
11
+ if json["status"] == "OK"
12
+ json
13
+ else
14
+ raise Error.from_json(@uri, json)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def parse_json
21
+ begin
22
+ JSON.parse(@response.body)
23
+ rescue JSON::ParserError
24
+ raise InvalidResponseBodyError.new(@uri, @response)
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module GmapsTz
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/gmaps_tz.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "gmaps_tz/version"
2
2
  require "gmaps_tz/error"
3
+ require "gmaps_tz/response_parser"
3
4
  require "gmaps_tz/client/time_zone"
4
5
  require "gmaps_tz/client"
5
6
 
data/spec/client_spec.rb CHANGED
@@ -46,7 +46,14 @@ describe "Client" do
46
46
  it "returns a hash with the result when success" do
47
47
  Net::HTTP.stub(:get_response).and_return(mocked_response_ok)
48
48
  response = client.time_zone_in("1.0", "2.0", time)
49
- response.should == mocked_response_ok
49
+ response.should == JSON.parse(mocked_response_ok.body)
50
+ end
51
+
52
+ it "raises the corresponding exception when it errors parsing response" do
53
+ Net::HTTP.stub(:get_response).and_return(FakeResponse.new(""))
54
+ expect {
55
+ client.time_zone_in("1.0", "2.0", time)
56
+ }.to raise_error(GmapsTz::InvalidResponseBodyError)
50
57
  end
51
58
 
52
59
  it "raises the corresponding exception when it fails" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmaps_tz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pol Miro
@@ -87,24 +87,23 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - .gitignore
90
91
  - .rspec
91
92
  - Gemfile
92
93
  - Gemfile.lock
93
94
  - LICENSE.txt
94
95
  - README.md
95
96
  - Rakefile
96
- - coverage/.last_run.json
97
- - coverage/.resultset.json
98
97
  - gmaps_tz.gemspec
99
98
  - lib/gmaps_tz.rb
100
99
  - lib/gmaps_tz/client.rb
101
100
  - lib/gmaps_tz/client/time_zone.rb
102
101
  - lib/gmaps_tz/error.rb
102
+ - lib/gmaps_tz/response_parser.rb
103
103
  - lib/gmaps_tz/version.rb
104
104
  - spec/client_spec.rb
105
105
  - spec/error_spec.rb
106
106
  - spec/spec_helper.rb
107
- - version.rb
108
107
  homepage: http://github.com/polmiro/gmaps_tz
109
108
  licenses:
110
109
  - MIT
@@ -1,5 +0,0 @@
1
- {
2
- "result": {
3
- "covered_percent": 94.19
4
- }
5
- }
@@ -1,190 +0,0 @@
1
- {
2
- "RSpec": {
3
- "coverage": {
4
- "/Users/polmiro/Development/gmaps_tz/lib/gmaps_tz.rb": [
5
- 1,
6
- 1,
7
- 1,
8
- 1,
9
- null,
10
- 1,
11
- null,
12
- null
13
- ],
14
- "/Users/polmiro/Development/gmaps_tz/lib/gmaps_tz/error.rb": [
15
- 1,
16
- 1,
17
- 1,
18
- 1,
19
- null,
20
- 1,
21
- null,
22
- 0,
23
- null,
24
- 1,
25
- null,
26
- 0,
27
- null,
28
- 0,
29
- null,
30
- 0,
31
- null,
32
- 0,
33
- null,
34
- 1,
35
- null,
36
- null,
37
- 1,
38
- null,
39
- 1,
40
- 1,
41
- 1,
42
- null,
43
- null,
44
- null,
45
- 1,
46
- null,
47
- 1,
48
- null,
49
- 1,
50
- null,
51
- 1,
52
- null,
53
- 1,
54
- null,
55
- 1,
56
- null
57
- ],
58
- "/Users/polmiro/Development/gmaps_tz/lib/gmaps_tz/client/time_zone.rb": [
59
- 1,
60
- 1,
61
- 1,
62
- null,
63
- 1,
64
- 4,
65
- null,
66
- null,
67
- null,
68
- null,
69
- null
70
- ],
71
- "/Users/polmiro/Development/gmaps_tz/lib/gmaps_tz/client.rb": [
72
- 1,
73
- 1,
74
- null,
75
- 1,
76
- 1,
77
- 1,
78
- null,
79
- 1,
80
- 1,
81
- 1,
82
- null,
83
- 1,
84
- null,
85
- 1,
86
- 4,
87
- 4,
88
- 4,
89
- null,
90
- null,
91
- 1,
92
- 4,
93
- null,
94
- 4,
95
- 4,
96
- 3,
97
- null,
98
- 1,
99
- null,
100
- null,
101
- null,
102
- 1,
103
- null,
104
- 1,
105
- 4,
106
- null,
107
- null,
108
- null,
109
- null,
110
- null,
111
- null,
112
- 1,
113
- null,
114
- 15,
115
- null,
116
- 4,
117
- null,
118
- null,
119
- null,
120
- null
121
- ],
122
- "/Users/polmiro/Development/gmaps_tz/spec/client_spec.rb": [
123
- 1,
124
- 4,
125
- null,
126
- 1,
127
- 1,
128
- null,
129
- 1,
130
- 4,
131
- null,
132
- null,
133
- null,
134
- 1,
135
- 1,
136
- 3,
137
- null,
138
- null,
139
- null,
140
- null,
141
- null,
142
- null,
143
- 3,
144
- null,
145
- null,
146
- 1,
147
- 1,
148
- 1,
149
- null,
150
- null,
151
- 5,
152
- null,
153
- 1,
154
- null,
155
- null,
156
- 1,
157
- 1,
158
- null,
159
- null,
160
- 1,
161
- 1,
162
- null,
163
- null,
164
- 1,
165
- 1,
166
- null,
167
- null,
168
- 1,
169
- 1,
170
- 1,
171
- 1,
172
- null,
173
- null,
174
- 1,
175
- 1,
176
- 1,
177
- 1,
178
- null,
179
- null,
180
- null,
181
- null,
182
- null
183
- ],
184
- "/Users/polmiro/Development/gmaps_tz/spec/error_spec.rb": [
185
-
186
- ]
187
- },
188
- "timestamp": 1393978034
189
- }
190
- }
data/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module GmapsTz
2
- VERSION = "0.0.1"
3
- end