growthforecast-client 0.80.1 → 0.80.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3006246bf805d5ea28559718454817fd471e552d
4
- data.tar.gz: 98da2066a4013b894af363388d5a2e52c243c9ce
3
+ metadata.gz: 389f477ae239f1c04bc4da5d4c666f8cd2c3caba
4
+ data.tar.gz: dbc01e7a72b731632b05b1b217e00ac1b2c1cf04
5
5
  SHA512:
6
- metadata.gz: 95d365a87b8c6e35917484b9e465ccbb6e1d3727ae40c60c6032268a59b86b86512a3b054ba8fd3ce6b045ed0dd9e94f3eb8c087ea294fdba3e440f8ad6c22c6
7
- data.tar.gz: ceacf17cb3e36e6453a060304521722642a69cdcbfd45fd338ec04b79dd0f4acc4d946466de2361a397c48c750b668d741cabc6e3a43250199163b736748a794
6
+ metadata.gz: cdfe3688ec02a66270f5e62001feb72d662180944b5e4db6e9599f11e357783ced44c776b565055820a262c0ff409ba9e66a4a995d90abd5a7ac8c8893af0589
7
+ data.tar.gz: 02bf8f6e2845a8b13fe7656fd125733925e3a8992fbb9ed4a4b967c0530cbb0aa6ed2b4beaf2bae7e1b7b9964f8e70e2ab25218aa4af3d6dc866f82357ad9c0f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.80.2 (2014/03/06)
2
+
3
+ Fixes:
4
+
5
+ - Fixed handle_error
6
+
1
7
  # 0.80.1 (2014/02/11)
2
8
 
3
9
  Fixes:
data/README.md CHANGED
@@ -36,6 +36,17 @@ See help for more:
36
36
  $ growthforecast-client help
37
37
  ```
38
38
 
39
+ ### Tips
40
+
41
+ #### Debug Print
42
+
43
+ Following codes prints the http requests and responses to STDOUT
44
+
45
+ ```
46
+ client = GrowthForecast::Client.new('http://localhost:5125')
47
+ client.debug_dev = STDOUT # IO object
48
+ ```
49
+
39
50
  ## Contributing
40
51
 
41
52
  1. Fork it
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.80.1
1
+ 0.80.2
@@ -78,7 +78,7 @@ module GrowthForecast
78
78
  @request_uri = "#{@base_uri}#{path}"
79
79
  req = get_request(path)
80
80
  @res = http_connection.start {|http| http.request(req) }
81
- handle_error(@res)
81
+ handle_error(@res, @request_uri)
82
82
  JSON.parse(@res.body)
83
83
  end
84
84
 
@@ -92,7 +92,7 @@ module GrowthForecast
92
92
  extheader = { 'Content-Type' => 'application/json' }
93
93
  req = post_request(path, body, extheader)
94
94
  @res = http_connection.start {|http| http.request(req) }
95
- handle_error(@res)
95
+ handle_error(@res, @request_uri)
96
96
  JSON.parse(@res.body)
97
97
  end
98
98
 
@@ -106,7 +106,7 @@ module GrowthForecast
106
106
  extheader = { 'Content-Type' => 'application/x-www-form-urlencoded' }
107
107
  req = post_request(path, body, extheader)
108
108
  @res = http_connection.start {|http| http.request(req) }
109
- handle_error(@res)
109
+ handle_error(@res, @request_uri)
110
110
  JSON.parse(@res.body)
111
111
  end
112
112
 
@@ -421,20 +421,20 @@ module GrowthForecast
421
421
  CGI.escape(str).gsub('+', '%20') if str
422
422
  end
423
423
 
424
- def handle_error(res)
424
+ def handle_error(res, request_uri)
425
425
  case res.code
426
426
  when '200'
427
427
  when '404'
428
- raise NotFound.new(error_message(res))
428
+ raise NotFound.new(error_message(res, request_uri))
429
429
  when '409'
430
- raise AlreadyExists.new(error_message(res))
430
+ raise AlreadyExists.new(error_message(res, request_uri))
431
431
  else
432
- raise Error.new(error_message(res))
432
+ raise Error.new(error_message(res, request_uri))
433
433
  end
434
434
  end
435
435
 
436
- def error_message(res)
437
- "status:#{res.status}\turi:#{res.http_header.request_uri.to_s}\tmessage:#{res.body}"
436
+ def error_message(res, request_uri)
437
+ "status:#{res.code}\turi:#{request_uri}\tmessage:#{res.body}"
438
438
  end
439
439
 
440
440
  # GrowthForecast's /json/edit/graph API requires all parameters to update, thus
@@ -31,10 +31,18 @@ describe GrowthForecast::Client do
31
31
  end
32
32
 
33
33
  context "#get_graph" do
34
- include_context "stub_get_graph" if ENV['MOCK'] == 'on'
35
- subject { client.get_graph(graph["service_name"], graph["section_name"], graph["graph_name"]) }
36
- id_keys.each {|key| it { subject[key].should == graph[key] } }
37
- graph_keys.each {|key| it { subject.should have_key(key) } }
34
+ context "200 OK" do
35
+ include_context "stub_get_graph" if ENV['MOCK'] == 'on'
36
+ subject { client.get_graph(graph["service_name"], graph["section_name"], graph["graph_name"]) }
37
+ id_keys.each {|key| it { subject[key].should == graph[key] } }
38
+ graph_keys.each {|key| it { subject.should have_key(key) } }
39
+ end
40
+
41
+ context "404 Not Found" do
42
+ include_context "stub_get_notfound_graph" if ENV['MOCK'] == 'on'
43
+ subject { client.get_graph(notfound_graph["service_name"], notfound_graph["section_name"], notfound_graph["graph_name"]) }
44
+ it { expect { subject }.to raise_error(GrowthForecast::NotFound) }
45
+ end
38
46
  end
39
47
 
40
48
  context "#get_graph_by_id" do
data/spec/support/mock.rb CHANGED
@@ -225,3 +225,17 @@ shared_context "stub_create_complex" do
225
225
  before(:each, &proc)
226
226
  end
227
227
 
228
+ shared_context "stub_get_notfound_graph" do
229
+ def notfound_graph
230
+ {
231
+ 'service_name' => 'not found',
232
+ 'section_name' => 'not found',
233
+ 'graph_name' => 'not found',
234
+ }
235
+ end
236
+ proc = Proc.new do
237
+ stub_request(:get, "#{base_uri}/api/#{e notfound_graph['service_name']}/#{e notfound_graph['section_name']}/#{e notfound_graph['graph_name']}").
238
+ to_return(:status => 404, :body => '<html><body><strong>404</strong> Not Found</body></html>')
239
+ end
240
+ before(:each, &proc)
241
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: growthforecast-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.80.1
4
+ version: 0.80.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-10 00:00:00.000000000 Z
11
+ date: 2014-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient