circuit_client 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/circuit_client/client.rb +3 -1
- data/lib/circuit_client/error_middleware.rb +23 -0
- data/lib/circuit_client/errors.rb +19 -0
- data/lib/circuit_client/send_message_cli.rb +6 -1
- metadata +20 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07c5becef6eac99b973f2e39351fc53e4d9633a9
|
4
|
+
data.tar.gz: 4208a620334d4645e5e54ba0ff1d3614fa518387
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68b9c6b6d0a09117bdc9937528cbb2d234f0d9ec587b8ff17a0e5342c7f7a8d3d9590508407e803cd997af9453a19baedc7727aa136a8c5629e3f529463a2a9a
|
7
|
+
data.tar.gz: 7a0d273864893ddb6fb698f8ff18bc069bb386b41cfe35ba682af0b5cc8bd720663f65983cdd7dbacaeea119e8042b26363d25b2067e8321666e6998b27936d0
|
data/README.md
CHANGED
@@ -4,6 +4,8 @@ require 'typhoeus/adapters/faraday'
|
|
4
4
|
require 'uri'
|
5
5
|
require 'json'
|
6
6
|
|
7
|
+
require 'circuit_client/error_middleware'
|
8
|
+
|
7
9
|
module CircuitClient
|
8
10
|
class Client
|
9
11
|
# Set the hostname of the circuit system
|
@@ -54,7 +56,7 @@ module CircuitClient
|
|
54
56
|
def connection
|
55
57
|
@connection ||= Faraday.new(url: base_uri.to_s) do |faraday|
|
56
58
|
faraday.response :logger if @trace
|
57
|
-
faraday.use
|
59
|
+
faraday.use CircuitClient::ErrorMiddleware
|
58
60
|
faraday.adapter :typhoeus
|
59
61
|
end
|
60
62
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'circuit_client/errors'
|
2
|
+
|
3
|
+
module CircuitClient
|
4
|
+
class ErrorMiddleware < Faraday::Response::Middleware
|
5
|
+
ClientErrorStatuses = 400...600
|
6
|
+
|
7
|
+
def on_complete(env)
|
8
|
+
case env[:status]
|
9
|
+
when 404
|
10
|
+
raise Faraday::Error::ResourceNotFound, response_values(env)
|
11
|
+
when 407
|
12
|
+
# mimic the behavior that we get with proxy requests with HTTPS
|
13
|
+
raise Faraday::Error::ConnectionFailed, %{407 "Proxy Authentication Required "}
|
14
|
+
when ClientErrorStatuses
|
15
|
+
raise CircuitClient::ClientError, response_values(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def response_values(env)
|
20
|
+
{:status => env.status, :headers => env.response_headers, :body => env.body}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module CircuitClient
|
4
|
+
class ClientError < Faraday::Error::ClientError
|
5
|
+
def initialize(ex, response = nil)
|
6
|
+
content_type = ex[:headers]['Content-Type']
|
7
|
+
if !content_type.nil? && content_type.match(/application\/json/)
|
8
|
+
begin
|
9
|
+
error = JSON.parse(ex[:body])
|
10
|
+
super("server response: #{error['errorDescription']} (status: #{ex[:status]})")
|
11
|
+
rescue JSON::ParserError
|
12
|
+
super("server response with status #{ex[:status]} and malformed JSON")
|
13
|
+
end
|
14
|
+
else
|
15
|
+
super(ex, response)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -118,7 +118,12 @@ END_USAGE
|
|
118
118
|
options = {}
|
119
119
|
options[:subject] = @subject unless @subject.nil?
|
120
120
|
puts "sending message to #{conv}..."
|
121
|
-
|
121
|
+
begin
|
122
|
+
client.create_message( conv, body, **options )
|
123
|
+
rescue CircuitClient::ClientError => e
|
124
|
+
puts "Could not send message: #{e.message}"
|
125
|
+
exit 1
|
126
|
+
end
|
122
127
|
end
|
123
128
|
|
124
129
|
def client
|
metadata
CHANGED
@@ -1,85 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: circuit_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Benning
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '12'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '12'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rdoc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '6'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: aruba
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: faraday
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: typhoeus
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '1'
|
83
83
|
description:
|
84
84
|
email: ich@markusbenning.de
|
85
85
|
executables:
|
@@ -94,6 +94,8 @@ files:
|
|
94
94
|
- bin/send-circuit
|
95
95
|
- lib/circuit_client.rb
|
96
96
|
- lib/circuit_client/client.rb
|
97
|
+
- lib/circuit_client/error_middleware.rb
|
98
|
+
- lib/circuit_client/errors.rb
|
97
99
|
- lib/circuit_client/send_message_cli.rb
|
98
100
|
homepage: https://github.com/benningm/circuit_client
|
99
101
|
licenses:
|