elementary-rpc 2.6.0.64 → 2.7.0.dev
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +0 -1
- data/Gemfile +11 -2
- data/Gemfile.lock +101 -0
- data/elementary-rpc.gemspec +2 -1
- data/lib/elementary/errors.rb +12 -1
- data/lib/elementary/middleware/raise_on_status.rb +33 -9
- data/lib/elementary/version.rb +1 -1
- data/spec/elementary_client_using_anti_pattern_spec.rb +1 -0
- data/spec/sample_elementary_client_spec.rb +6 -0
- metadata +26 -25
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NDczNTllODIwZDI5Y2Y4YWUyNWFkMGI4ZmNjYzdhZDU0M2I0YjJkYQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b598ea611587a7a887920939f2ed90cb57ca86ba
|
4
|
+
data.tar.gz: 70d8f2326b2bdb838b251235b8657cd83335de69
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZTEzZjU5NjdkYzE2YzgzYTlhYTNmYjk2M2RkYzg0M2U4MjJjNzBjMTQwOGUz
|
11
|
-
NTFjNTA0MTMzZWU3YWNkMjZjN2ZlMDhmZTkyNjY3YjBjNjhlYzc=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YWQ1ZjdkMTdjNmM1NTc5ZmE3OGM3MTJjMWFmMmNkMzg3NDAwZmE0ODNlN2Ix
|
14
|
-
MWE0NjZjNzgzMzU4N2QxZjkxM2I4N2NlY2Y0OGQ3MGU0YmQ1NTFlNTdhZTlk
|
15
|
-
YzE5YzQwM2YyMDA0M2EwZGE5ZWQzNDU1MTFjMzRkODZmZGJkOGY=
|
6
|
+
metadata.gz: 4323cfe597d637b220c5d6e683e09e5515025c7c48df75764f0c9145f2d81783457b8ffa1fb98f7e253ceee88f1ddde4f56ddaa9f291b9c738b5ef28daa38b20
|
7
|
+
data.tar.gz: 6956f2f07bfef96eb01a9b88d69bbb1ff1cfc99291a9939f29776f9f2eb92436826eac9b026b9100bb1a77dda2f6e96fc909c10e9ed32761fa3234c0676625ec
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in elementary-rpc.gemspec
|
4
|
-
gemspec
|
4
|
+
gemspec :name => 'elementary-rpc'
|
5
5
|
|
6
|
-
gem 'rack'
|
7
6
|
gem 'protobuffy', :github => 'lookout/protobuffy'
|
8
7
|
|
9
8
|
group :test do
|
@@ -16,3 +15,13 @@ group :development do
|
|
16
15
|
gem 'debugger-pry', :platform => :mri_19
|
17
16
|
gem 'byebug', :platform => [:mri_20, :mri_21]
|
18
17
|
end
|
18
|
+
|
19
|
+
# added to make travis ci happy
|
20
|
+
gem "bundler", "~> 1.6"
|
21
|
+
gem "rake", "10.5.0"
|
22
|
+
gem 'concurrent-ruby', '>= 0.7'
|
23
|
+
gem 'faraday', '~> 0.9.0'
|
24
|
+
gem 'net-http-persistent', '~> 2.9.4'
|
25
|
+
gem 'lookout-statsd', '~> 2.0.0'
|
26
|
+
gem 'hashie'
|
27
|
+
gem 'activesupport', '4.2.4'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/lookout/protobuffy.git
|
3
|
+
revision: 08a10a3324157363d0f4fc2123ca00b73487c625
|
4
|
+
specs:
|
5
|
+
protobuffy (3.5.1)
|
6
|
+
activesupport (>= 3.2)
|
7
|
+
middleware
|
8
|
+
multi_json
|
9
|
+
thor
|
10
|
+
|
11
|
+
PATH
|
12
|
+
remote: .
|
13
|
+
specs:
|
14
|
+
elementary-rpc (2.7.0.dev)
|
15
|
+
concurrent-ruby (>= 0.7)
|
16
|
+
faraday (~> 0.9.0)
|
17
|
+
hashie
|
18
|
+
lookout-statsd (~> 2.0.0)
|
19
|
+
net-http-persistent (~> 2.9.4)
|
20
|
+
|
21
|
+
GEM
|
22
|
+
remote: https://rubygems.org/
|
23
|
+
specs:
|
24
|
+
activesupport (4.2.4)
|
25
|
+
i18n (~> 0.7)
|
26
|
+
json (~> 1.7, >= 1.7.7)
|
27
|
+
minitest (~> 5.1)
|
28
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
29
|
+
tzinfo (~> 1.1)
|
30
|
+
byebug (9.0.5)
|
31
|
+
coderay (1.1.1)
|
32
|
+
columnize (0.9.0)
|
33
|
+
concurrent-ruby (1.0.2)
|
34
|
+
debugger (1.6.8)
|
35
|
+
columnize (>= 0.3.1)
|
36
|
+
debugger-linecache (~> 1.2.0)
|
37
|
+
debugger-ruby_core_source (~> 1.3.5)
|
38
|
+
debugger-linecache (1.2.0)
|
39
|
+
debugger-pry (0.1.1)
|
40
|
+
debugger (~> 1)
|
41
|
+
pry (>= 0.9.9)
|
42
|
+
debugger-ruby_core_source (1.3.8)
|
43
|
+
diff-lcs (1.2.5)
|
44
|
+
faraday (0.9.2)
|
45
|
+
multipart-post (>= 1.2, < 3)
|
46
|
+
hashie (3.4.4)
|
47
|
+
i18n (0.7.0)
|
48
|
+
json (1.8.3)
|
49
|
+
lookout-statsd (2.0.3)
|
50
|
+
method_source (0.8.2)
|
51
|
+
middleware (0.1.0)
|
52
|
+
minitest (5.9.0)
|
53
|
+
multi_json (1.12.1)
|
54
|
+
multipart-post (2.0.0)
|
55
|
+
net-http-persistent (2.9.4)
|
56
|
+
pry (0.10.4)
|
57
|
+
coderay (~> 1.1.0)
|
58
|
+
method_source (~> 0.8.1)
|
59
|
+
slop (~> 3.4)
|
60
|
+
rake (10.5.0)
|
61
|
+
rspec (3.5.0)
|
62
|
+
rspec-core (~> 3.5.0)
|
63
|
+
rspec-expectations (~> 3.5.0)
|
64
|
+
rspec-mocks (~> 3.5.0)
|
65
|
+
rspec-core (3.5.1)
|
66
|
+
rspec-support (~> 3.5.0)
|
67
|
+
rspec-expectations (3.5.0)
|
68
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
69
|
+
rspec-support (~> 3.5.0)
|
70
|
+
rspec-mocks (3.5.0)
|
71
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
72
|
+
rspec-support (~> 3.5.0)
|
73
|
+
rspec-support (3.5.0)
|
74
|
+
slop (3.6.0)
|
75
|
+
thor (0.19.1)
|
76
|
+
thread_safe (0.3.5)
|
77
|
+
tzinfo (1.2.2)
|
78
|
+
thread_safe (~> 0.1)
|
79
|
+
|
80
|
+
PLATFORMS
|
81
|
+
ruby
|
82
|
+
|
83
|
+
DEPENDENCIES
|
84
|
+
activesupport (= 4.2.4)
|
85
|
+
bundler (~> 1.6)
|
86
|
+
byebug
|
87
|
+
concurrent-ruby (>= 0.7)
|
88
|
+
debugger
|
89
|
+
debugger-pry
|
90
|
+
elementary-rpc!
|
91
|
+
faraday (~> 0.9.0)
|
92
|
+
hashie
|
93
|
+
lookout-statsd (~> 2.0.0)
|
94
|
+
net-http-persistent (~> 2.9.4)
|
95
|
+
protobuffy!
|
96
|
+
pry
|
97
|
+
rake (= 10.5.0)
|
98
|
+
rspec
|
99
|
+
|
100
|
+
BUNDLED WITH
|
101
|
+
1.12.5
|
data/elementary-rpc.gemspec
CHANGED
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
-
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rake", "10.5.0"
|
23
|
+
|
23
24
|
|
24
25
|
spec.add_dependency 'concurrent-ruby', '>= 0.7'
|
25
26
|
spec.add_dependency 'faraday', '~> 0.9.0'
|
data/lib/elementary/errors.rb
CHANGED
@@ -2,6 +2,17 @@ module Elementary
|
|
2
2
|
module Errors
|
3
3
|
# A simple root class to signify an failure on the RPC server side (see
|
4
4
|
# "rpc_failed 'message'")
|
5
|
-
class RPCFailure < StandardError
|
5
|
+
class RPCFailure < StandardError
|
6
|
+
attr_reader :status_code, :method, :url, :header_message, :header_code
|
7
|
+
|
8
|
+
def initialize(opts = {})
|
9
|
+
@status_code = opts.fetch(:status_code, nil)
|
10
|
+
@method = opts.fetch(:method, "<Unknown Method>")
|
11
|
+
@url = opts.fetch(:url, "<Unknown URL>")
|
12
|
+
@header_code = opts.fetch(:header_code, "<Unknown Header Code>")
|
13
|
+
@header_message = opts.fetch(:header_message, "<Unknown Header Message>")
|
14
|
+
super "Error #{@header_code}: #{@header_message}"
|
15
|
+
end
|
16
|
+
end
|
6
17
|
end
|
7
18
|
end
|
@@ -2,7 +2,27 @@ require 'faraday'
|
|
2
2
|
|
3
3
|
module Elementary
|
4
4
|
module Middleware
|
5
|
-
class HttpStatusError < StandardError
|
5
|
+
class HttpStatusError < StandardError
|
6
|
+
attr_reader :status_code, :method, :url, :parent_message
|
7
|
+
def initialize(opts = {})
|
8
|
+
@status_code = opts.fetch(:status_code, nil)
|
9
|
+
@method = opts.fetch(:method, "<Unknown Method>")
|
10
|
+
@url = opts.fetch(:method, "<Unknown URL>")
|
11
|
+
|
12
|
+
message = if connection_refused?
|
13
|
+
"#{method} #{url} returned a connection refused: #{opts.fetch(:parent_message, '<Unknown Message>')}"
|
14
|
+
else
|
15
|
+
"#{method} #{url} returned an HTTP response status of #{status_code}, so an exception was raised."
|
16
|
+
end
|
17
|
+
super message
|
18
|
+
end
|
19
|
+
|
20
|
+
# We assume that the connection was refused if no status code was set.
|
21
|
+
# @return [Boolean]
|
22
|
+
def connection_refused?
|
23
|
+
@status_code.nil?
|
24
|
+
end
|
25
|
+
end
|
6
26
|
##
|
7
27
|
# Raise an exception for certain HTTP response status codes
|
8
28
|
#
|
@@ -54,19 +74,23 @@ module Elementary
|
|
54
74
|
@app.call(request_env).on_complete do |response_env|
|
55
75
|
status = response_env[:status]
|
56
76
|
if @status_set.include? status
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
77
|
+
error_opts = {
|
78
|
+
:status_code => status,
|
79
|
+
:method => response_env.method.to_s.upcase,
|
80
|
+
:url => response_env.url.to_s
|
81
|
+
}
|
82
|
+
headers = response_env[:response_headers]
|
83
|
+
if headers.include?(ERROR_HEADER_CODE) && headers.include?(ERROR_HEADER_MSG)
|
84
|
+
error_opts[:header_message] = headers[ERROR_HEADER_MSG]
|
85
|
+
error_opts[:header_code] = headers[ERROR_HEADER_CODE]
|
86
|
+
raise Elementary::Errors::RPCFailure, error_opts
|
61
87
|
else
|
62
|
-
|
63
|
-
url = response_env.url.to_s
|
64
|
-
raise HttpStatusError, "#{method} #{url} returned an HTTP response status of #{status}, so an exception was raised."
|
88
|
+
raise HttpStatusError, error_opts
|
65
89
|
end
|
66
90
|
end
|
67
91
|
end
|
68
92
|
rescue Faraday::ClientError => e
|
69
|
-
raise HttpStatusError,
|
93
|
+
raise HttpStatusError, :parent_message => e.message
|
70
94
|
end
|
71
95
|
end
|
72
96
|
|
data/lib/elementary/version.rb
CHANGED
@@ -6,6 +6,7 @@ def sendAndVerify(msg)
|
|
6
6
|
response = client.invoke_echo_service(Elementary::Rspec::String.new(:data => msg))
|
7
7
|
expect(response).to be_rejected
|
8
8
|
expect(response.reason.class).to be Elementary::Middleware::HttpStatusError
|
9
|
+
expect(response.reason.connection_refused?).to be true
|
9
10
|
expect(response.reason.message).to include("connection refused: localhost:8090")
|
10
11
|
end
|
11
12
|
|
@@ -7,6 +7,7 @@ def send_and_verify_http_error_503(msg)
|
|
7
7
|
expect(response).to be_rejected
|
8
8
|
expect(response.reason.class).to be Elementary::Middleware::HttpStatusError
|
9
9
|
expect(response.reason.message).to include("returned an HTTP response status of 503, so an exception was raised.")
|
10
|
+
expect(response.reason.status_code).to eql 503
|
10
11
|
expect(response.reason.message).to include("Elementary::Rspec::Simple#error")
|
11
12
|
end
|
12
13
|
|
@@ -14,6 +15,7 @@ def send_and_verify_http_error_500(msg)
|
|
14
15
|
response = client.invoke_error_service(Elementary::Rspec::String.new(:data => msg))
|
15
16
|
expect(response).to be_rejected
|
16
17
|
expect(response.reason.class).to be Elementary::Errors::RPCFailure
|
18
|
+
expect(response.reason.status_code).to eql 500
|
17
19
|
expect(response.reason.message).to include("sample failure")
|
18
20
|
expect(response.reason.message).to include("Elementary::Rspec::Simple#error")
|
19
21
|
end
|
@@ -22,6 +24,7 @@ def send_and_verify_http_error_400(msg)
|
|
22
24
|
response = client.invoke_bad_request_data_service(Elementary::Rspec::String.new(:data => msg))
|
23
25
|
expect(response).to be_rejected
|
24
26
|
expect(response.reason.class).to be Elementary::Errors::RPCFailure
|
27
|
+
expect(response.reason.status_code).to eql 400
|
25
28
|
expect(response.reason.message).to include("sample bad request data failure")
|
26
29
|
expect(response.reason.message).to include("Elementary::Rspec::Simple#bad_request_data_method")
|
27
30
|
end
|
@@ -30,6 +33,7 @@ def send_and_verify_http_error_404(msg)
|
|
30
33
|
response = client.invoke_service_not_found_service(Elementary::Rspec::String.new(:data => msg))
|
31
34
|
expect(response).to be_rejected
|
32
35
|
expect(response.reason.class).to be Elementary::Errors::RPCFailure
|
36
|
+
expect(response.reason.status_code).to eql 404
|
33
37
|
expect(response.reason.message).to include("sample service not found failure")
|
34
38
|
expect(response.reason.message).to include("Elementary::Rspec::Simple#service_not_found_method")
|
35
39
|
end
|
@@ -38,6 +42,8 @@ def send_and_verify_connection_refused(msg)
|
|
38
42
|
response = client.invoke_error_service(Elementary::Rspec::String.new(:data => msg))
|
39
43
|
expect(response).to be_rejected
|
40
44
|
expect(response.reason.class).to be Elementary::Middleware::HttpStatusError
|
45
|
+
expect(response.reason.status_code).to be nil
|
46
|
+
expect(response.reason.connection_refused?).to be true
|
41
47
|
expect(response.reason.message).to include("connection refused: localhost:8090")
|
42
48
|
expect(response.reason.message).to include("Elementary::Rspec::Simple#error")
|
43
49
|
end
|
metadata
CHANGED
@@ -1,111 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elementary-rpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.0.dev
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- R. Tyler Croy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.6'
|
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
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 10.5.0
|
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: 10.5.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: concurrent-ruby
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0.7'
|
48
48
|
type: :runtime
|
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.7'
|
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.9.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.9.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: net-http-persistent
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 2.9.4
|
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
82
|
version: 2.9.4
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: lookout-statsd
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: 2.0.0
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 2.0.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: hashie
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
description: Gem supporting Protobuf RPC over HTTP with futures and fun
|
@@ -115,10 +115,11 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- .gitignore
|
119
|
-
- .rspec
|
120
|
-
- .travis.yml
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
121
|
- Gemfile
|
122
|
+
- Gemfile.lock
|
122
123
|
- LICENSE.txt
|
123
124
|
- README.md
|
124
125
|
- Rakefile
|
@@ -161,17 +162,17 @@ require_paths:
|
|
161
162
|
- lib
|
162
163
|
required_ruby_version: !ruby/object:Gem::Requirement
|
163
164
|
requirements:
|
164
|
-
- -
|
165
|
+
- - ">="
|
165
166
|
- !ruby/object:Gem::Version
|
166
167
|
version: '0'
|
167
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
169
|
requirements:
|
169
|
-
- -
|
170
|
+
- - ">"
|
170
171
|
- !ruby/object:Gem::Version
|
171
|
-
version:
|
172
|
+
version: 1.3.1
|
172
173
|
requirements: []
|
173
174
|
rubyforge_project:
|
174
|
-
rubygems_version: 2.
|
175
|
+
rubygems_version: 2.4.3
|
175
176
|
signing_key:
|
176
177
|
specification_version: 4
|
177
178
|
summary: Gem supporting Protobuf RPC in a simple way
|