dc_tunnel 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dc_tunnel.rb +15 -4
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ae87fc147d8f974581db286011e1cfa29a8efc548ea89ee200bea1a16f19bc4
4
- data.tar.gz: 22e14c328c6ba2cff433f97f821c4eea63839558aa921dcdc4bc10c49614dbfe
3
+ metadata.gz: 2733e282c05ee8565fd8f3ecc16885d3eb3a305efbec81dc6ca0585722bd62d0
4
+ data.tar.gz: c371902ff187c786ce7dccf6ba203b4ec74ddab472abf7165289ca7dacfbcd9f
5
5
  SHA512:
6
- metadata.gz: df51fc273700496490edee089bd8e787061c420c122cf2484c46b742ac1556dbce5c238e4dda0677e92d954d23d8de8ad3e525043b10415f5c2fd353eed58f62
7
- data.tar.gz: fa2f65f35d2016ba36f2c163269dee053a3240c7d7a52608e35fe32dc2f145306b689fc64deacda2629697464b82a0cbb45c4dd7c5f59a4f6b378f0dedf82f12
6
+ metadata.gz: ef172b66de5888943da6ffc8e6de7f1f2b6203846d52b111272caeda8886c20901a9404953324530d3dfddd95966ed0bcec95420589c45c3c408d9976c1ab108
7
+ data.tar.gz: 045580fecf869c8e40fad102c7bea4981c9faa5923fce00498177cd71315b331cea5d702814106139a61371c940b6c6183ebedeb2265b0999201471a0f52717e
data/lib/dc_tunnel.rb CHANGED
@@ -15,12 +15,22 @@ class DcTunnel
15
15
  puts content
16
16
  end
17
17
  end
18
-
18
+
19
+ def error_handler(res)
20
+ integer_code = res.code.to_i
21
+ unless integer_code >=200 && integer_code < 400
22
+ render json: {
23
+ message: JSON.parse(res.body)['message']
24
+ }, :status => integer_code
25
+ end
26
+ end
27
+
19
28
  def http_get(url)
20
- self.logger '0.9'
29
+ self.logger '0.10'
21
30
  self.logger "--- Tunnel : start get #{url} "
22
- res = Net::HTTP.get(URI(url))
23
- res = JSON.parse(res)
31
+ res = Net::HTTP.get_response(URI(url))
32
+ self.error_handler res
33
+ res = JSON.parse(res.body)
24
34
  self.logger "--- Tunnel : got parsed response #{res} "
25
35
  res = res.symbolize_keys(true)
26
36
  self.logger "--- Tunnel : got symbolize_keys! response #{res} "
@@ -30,6 +40,7 @@ class DcTunnel
30
40
  def http_post(url, postdata={})
31
41
  self.logger "--- Tunnel : start get #{url} "
32
42
  res = Net::HTTP.post_form(URI(url), postdata).body
43
+ self.error_handler res
33
44
  res = JSON.parse(res).symbolize_keys(true)
34
45
  self.logger "--- Tunnel : got response #{res} "
35
46
  res
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dc_tunnel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Qxchen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-07 00:00:00.000000000 Z
11
+ date: 2019-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: advanced_hash_keys