elementary-rpc 2.1.1.35 → 2.1.1.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzI0MzJiODBlMmQzMjgyNTY3NGNkMzczNWVkNWZhNmIyMzU3YzRmNQ==
4
+ YTY3NTY0NGQwOTgxZmJlM2U2ZWMzMDg3NTY5OThhMmI0NTQzZjU3Mg==
5
5
  data.tar.gz: !binary |-
6
- ZjUxMzA2MGI2MzMxZWI1YTkwYTc0MDY3NzI2MWVkOThjZWQ2MGI1YQ==
6
+ YzlmMTdmMWM5ZDFhMzc4NWM2MDY5MTNkZDYyY2YzNGE4YmUzZjk4MQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODA3MGM4ZDVhNTcyYmMxNDA5ZmYxZjE2YmVhZmVhNjcxYzJlMDkwNjc0YWI2
10
- YWVjZTRhNmNhZmU3ZWY3YWY4YmNiNjhlZWJhMzc1MTk0YWM1MThhOTQyNmQ3
11
- YzNjMTQ1NjUwZDJkMTg2NGVhYzI3NWFiNTg5ODQ2Njk1OTUxYmI=
9
+ MDZiMTlhZTNjNzMxNjIxODViZjEzMmQ3MDZiZDRhNTMwZDcxNjdiNTYyYjJh
10
+ ZTllYWJmNzQ2MTVjY2YyYTQ2ODQwM2UxOTQ3N2Q1NTVjYzU5MjU1MGIyZmIw
11
+ Zjc3Zjc0YzA4MmQxMDNiMmRjZTI3NWIwYmE0MjgwNzdlNjU1MGM=
12
12
  data.tar.gz: !binary |-
13
- Zjc0N2JiNDllNDc4NzRlMTJjZjRjZmUwYWJiOTU4ZGIwYTM0NDBiODc3MmQy
14
- NzFmMmVjMDczMDlmMjNjNTQ2NGNiMGNhNDE4NjIxYWIyMTQxNWU1NjRjZTVm
15
- YzQ0NDZjMWU4NWYxZWI3NDNmNmViMTA5OGViZmVkOTY0ZDE4ZWQ=
13
+ MzkwMTc1MjJkNDZiMWJlNzVjNjZiOTMzYzJjZjE1NjU1MzFjZWE2MjNiMzg0
14
+ ZjU4NmU5YjA3ZWNhYTE2NTdhNWNkMzAyZTY5MjQwZDBlMDRjZTYzMTEwMzZi
15
+ OWFmMThmMWU1YmU0YjU0YTIxMDAzN2Y3MDY1ZDEyZmEyMDdjYWE=
data/README.md CHANGED
@@ -54,6 +54,18 @@ def connection
54
54
  @connection = Elementary::Connection.new(Echoserv::Simple,
55
55
  :hosts => hosts)
56
56
  end
57
+ # We can also use existing Faraday middleware, since our HTTP transport is built
58
+ # on Faraday:
59
+ c = Elementary::Connection.new(Echoserv::Simple,
60
+ :hosts => hosts,
61
+ :transport_options => {
62
+ :faraday_middleware => [
63
+ [ FaradayMiddleware::FollowRedirects, :limit => 2 ]
64
+ ]
65
+ })
66
+
67
+
68
+
57
69
  # Create a Protobuf message to send over RPC
58
70
  msg = Echoserv::String.new(:data => str)
59
71
 
@@ -48,14 +48,27 @@ module Elementary
48
48
  def client
49
49
  return @client if @client
50
50
 
51
+ faraday_middleware = @options.delete(:faraday_middleware) || []
51
52
  faraday_options = @options.merge({:url => host_url})
52
53
  logging = faraday_options.delete(:logging)
53
54
  logger = faraday_options.delete(:logger)
55
+
54
56
  @client = Faraday.new(faraday_options) do |f|
55
57
  f.request :raise_on_status
56
58
  f.response :logger, logger if logging
57
59
  f.adapter :net_http_persistent
58
60
  end
61
+
62
+ # Adapters aren't middleware, so we have to pop the adapter off before
63
+ # we insert new middleware. See:
64
+ # https://github.com/lostisland/faraday/issues/375,
65
+ # https://github.com/lostisland/faraday/issues/47
66
+ adapter = @client.builder.handlers.pop
67
+ faraday_middleware.each do |klass, *args|
68
+ @client.use klass, *args
69
+ end
70
+ @client.builder.handlers << adapter
71
+
59
72
  return @client
60
73
  end
61
74
  end
@@ -1,6 +1,9 @@
1
1
  require 'spec_helper'
2
2
  require 'elementary/transport/http'
3
3
 
4
+ class FakeMiddleware1 ; end
5
+ class FakeMiddleware2 ; end
6
+
4
7
  describe Elementary::Transport::HTTP do
5
8
  let(:hosts) { [] }
6
9
  let(:opts) { {} }
@@ -70,5 +73,28 @@ describe Elementary::Transport::HTTP do
70
73
  expect(client).to be_instance_of Faraday::Connection
71
74
  end
72
75
  end
76
+
77
+ context 'with faraday middleware passed to the initializer' do
78
+ let(:opts) do
79
+ {
80
+ :faraday_middleware => [
81
+ [ FakeMiddleware1, { :middleware_level => 1} ],
82
+ [ FakeMiddleware2, { :middleware_level => 2} ]
83
+ ]
84
+ }
85
+ end
86
+
87
+ it 'should use those middlewares' do
88
+ expect(client.builder.handlers).to include(FakeMiddleware1)
89
+ expect(client.builder.handlers).to include(FakeMiddleware2)
90
+ middleware_opts = client.builder.handlers.map do |h|
91
+ h.instance_variable_get(:@args)
92
+ end
93
+ expect(middleware_opts).to include([{ :middleware_level => 1 }])
94
+ expect(middleware_opts).to include([{ :middleware_level => 2 }])
95
+
96
+ expect(client).to be_instance_of Faraday::Connection
97
+ end
98
+ end
73
99
  end
74
100
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elementary-rpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1.35
4
+ version: 2.1.1.37
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: 2015-04-15 00:00:00.000000000 Z
11
+ date: 2015-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler