libgss 0.7.3 → 0.7.4

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: d53665633c09d8a6f5ca84777c9de59b69f26ca0
4
- data.tar.gz: 099b87fa95d54caac1aadb658a9aed566073d185
3
+ metadata.gz: 7dd3ebf42ffbb2444212e81cedbe2612ce5c441d
4
+ data.tar.gz: 2044b93d9d1f33020093e5e6275687fc97724855
5
5
  SHA512:
6
- metadata.gz: 48963d4fe7b7a7f02629fa5a0a92cef7030f6c9ebd8651624b0efa7203aba63f798417f91cebe0003cde45a4d7a1537bf73a317593564ec82dfcb1ffda1047cb
7
- data.tar.gz: cf7df2a141e586bf514a485cc1a2e135572067e1413ce86b1fcd6a1c1bd5dd32983ae3924cda5bc58fb1db87c7f81e6efac33a45007d9d6ee5b7f9c8d76676d8
6
+ metadata.gz: d10d914ee9d3658a984be8519b4c5f1cfad52392560a356ffbdf03195380858d7e001284866aa6c285445bc2533b21381e7ed84864135be82f9927e69ccae2be
7
+ data.tar.gz: 0a5f7be36db3014e69908f70628134afb054c56acab954d69c3310c1bb8d72fa785c926d2b4056715ca65a33c312a1cb8c2e02810fccb970ea32739ff6d63f0a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- libgss (0.7.3)
4
+ libgss (0.7.4)
5
5
  httpclient
6
6
  json
7
7
  oauth
@@ -55,17 +55,26 @@ module Libgss
55
55
  res = Libgss.with_retry("action_request") do
56
56
  @httpclient.post(action_url, {"inputs" => @actions.map(&:to_hash)}.to_json, req_headers)
57
57
  end
58
+ r = process_response(res, :async_request)
59
+ @outputs = Outputs.new(r["outputs"])
60
+ callback.call(@outputs) if callback
61
+ @outputs
62
+ end
63
+
64
+ def process_response(res, req_type)
58
65
  case res.code.to_i
59
66
  when 200..299 then # OK
60
67
  else
61
- raise Error, "failed to send action request: [#{res.code}] #{res.body}"
68
+ raise Error, "failed to send #{req_type}: [#{res.code}] #{res.content}"
69
+ end
70
+ begin
71
+ return JSON.parse(res.content)
72
+ rescue JSON::ParserError => e
73
+ $stderr.puts("\e[31m[#{e.class}] #{e.message}\e[0m\n#{res.content}")
74
+ raise e
62
75
  end
63
- r = JSON.parse(res.body)
64
- # puts res.body
65
- @outputs = Outputs.new(r["outputs"])
66
- callback.call(@outputs) if callback
67
- @outputs
68
76
  end
77
+ private :process_response
69
78
 
70
79
  # 条件に該当するデータを取得
71
80
  # @param [String] name 対象となるコレクション名
@@ -22,13 +22,7 @@ module Libgss
22
22
  # アクション群を実行するために実際にHTTPリクエストを送信します。
23
23
  def send_request(&callback)
24
24
  res = @httpclient.post(action_url, {"inputs" => @actions.map(&:to_hash)}.to_json, req_headers)
25
- case res.code.to_i
26
- when 200..299 then # OK
27
- else
28
- raise Error, "failed to send action request: [#{res.code}] #{res.body}"
29
- end
30
- r = JSON.parse(res.body)
31
- # puts res.body
25
+ r = process_response(res, :async_request)
32
26
  @outputs = Outputs.new(r["outputs"])
33
27
  callback.call(@outputs) if callback
34
28
 
@@ -43,12 +37,7 @@ module Libgss
43
37
  raise Error, "failed to get response. please exec send_request before call." unless @ids
44
38
 
45
39
  res = @httpclient.get(result_url, {input_ids: @ids.join(',')}, req_headers)
46
- case res.code.to_i
47
- when 200..299 then # OK
48
- else
49
- raise Error, "failed to send action request: [#{res.code}] #{res.body}"
50
- end
51
- r = JSON.parse(res.body)
40
+ r = process_response(res, :aync_status)
52
41
  end
53
42
  end
54
43
  end
@@ -236,6 +236,7 @@ module Libgss
236
236
  obj = JSON.parse(res.content)
237
237
  return yield(obj)
238
238
  rescue JSON::ParserError => e
239
+ $stderr.puts("\e[31m[#{e.class}] #{e.message}\n#{res.content}")
239
240
  return false
240
241
  end
241
242
  end
@@ -1,3 +1,3 @@
1
1
  module Libgss
2
- VERSION = "0.7.3"
2
+ VERSION = "0.7.4"
3
3
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'spec_helper'
2
3
 
3
4
  require 'uuid'
@@ -116,9 +117,10 @@ describe Libgss::Network do
116
117
 
117
118
  context "JSON parse Error" do
118
119
  before do
120
+ $stderr.stub(:puts).with(an_instance_of(String)) # $stderrにメッセージが出力されます
119
121
  res = double(:reponse)
120
122
  res.stub(:status).and_return(200)
121
- res.should_receive(:content).and_return("invalid JSON format string")
123
+ res.should_receive(:content).twice.and_return("invalid JSON format string")
122
124
  HTTPClient.any_instance.should_receive(:post).and_return(res)
123
125
  end
124
126
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libgss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - akima
@@ -209,3 +209,4 @@ test_files:
209
209
  - spec/protected_assets/Icon.png
210
210
  - spec/public_assets/Default.png
211
211
  - spec/spec_helper.rb
212
+ has_rdoc: