airbrake-api 4.5.1 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,5 @@
1
- require 'faraday_middleware'
2
1
  require 'parallel'
3
2
  require 'airbrake-api/core_ext/hash'
4
- require 'airbrake-api/middleware/scrub_response'
5
- require 'airbrake-api/middleware/raise_server_error'
6
- require 'airbrake-api/middleware/raise_response_error'
7
3
 
8
4
  module AirbrakeAPI
9
5
  class Client
@@ -171,12 +167,7 @@ module AirbrakeAPI
171
167
  :url => account_path,
172
168
  }
173
169
  @connection ||= Faraday.new(default_options.deep_merge(connection_options)) do |builder|
174
- builder.use Faraday::Request::UrlEncoded
175
- builder.use AirbrakeAPI::Middleware::RaiseResponseError
176
- builder.use FaradayMiddleware::Mashify
177
- builder.use FaradayMiddleware::ParseXml
178
- builder.use AirbrakeAPI::Middleware::ScrubResponse
179
- builder.use AirbrakeAPI::Middleware::RaiseServerError
170
+ middleware.each { |mw| builder.use *mw }
180
171
 
181
172
  builder.adapter adapter
182
173
  end
@@ -1,4 +1,8 @@
1
1
  require 'airbrake-api/version'
2
+ require 'faraday_middleware'
3
+ require 'airbrake-api/middleware/scrub_response'
4
+ require 'airbrake-api/middleware/raise_server_error'
5
+ require 'airbrake-api/middleware/raise_response_error'
2
6
 
3
7
  module AirbrakeAPI
4
8
  module Configuration
@@ -8,13 +12,21 @@ module AirbrakeAPI
8
12
  :secure,
9
13
  :connection_options,
10
14
  :adapter,
11
- :user_agent]
15
+ :user_agent,
16
+ :middleware]
12
17
 
13
18
  attr_accessor *VALID_OPTIONS_KEYS
14
19
 
15
20
  DEFAULT_ADAPTER = :net_http
16
21
  DEFAULT_USER_AGENT = "AirbrakeAPI Ruby Gem #{AirbrakeAPI::VERSION}"
17
22
  DEFAULT_CONNECTION_OPTIONS = {}
23
+ DEFAULT_MIDDLEWARE = [
24
+ Faraday::Request::UrlEncoded,
25
+ AirbrakeAPI::Middleware::RaiseResponseError,
26
+ FaradayMiddleware::Mashify,
27
+ FaradayMiddleware::ParseXml,
28
+ AirbrakeAPI::Middleware::ScrubResponse,
29
+ AirbrakeAPI::Middleware::RaiseServerError]
18
30
 
19
31
  def self.extended(base)
20
32
  base.reset
@@ -24,6 +36,7 @@ module AirbrakeAPI
24
36
  @account = options[:account] if options.has_key?(:account)
25
37
  @auth_token = options[:auth_token] if options.has_key?(:auth_token)
26
38
  @secure = options[:secure] if options.has_key?(:secure)
39
+ @middleware = options[:middleware] if options.has_key?(:middleware)
27
40
  yield self if block_given?
28
41
  self
29
42
  end
@@ -49,6 +62,7 @@ module AirbrakeAPI
49
62
  @adapter = DEFAULT_ADAPTER
50
63
  @user_agent = DEFAULT_USER_AGENT
51
64
  @connection_options = DEFAULT_CONNECTION_OPTIONS
65
+ @middleware = DEFAULT_MIDDLEWARE
52
66
  end
53
67
 
54
68
  end
@@ -1,3 +1,3 @@
1
1
  module AirbrakeAPI
2
- VERSION = '4.5.1'
2
+ VERSION = '4.6.0'
3
3
  end
@@ -35,7 +35,8 @@ describe AirbrakeAPI::Client do
35
35
  :secure => true,
36
36
  :connection_options => {},
37
37
  :adapter => :em_http,
38
- :user_agent => 'Airbrake API Tests'
38
+ :user_agent => 'Airbrake API Tests',
39
+ :middleware => AirbrakeAPI::Configuration::DEFAULT_MIDDLEWARE
39
40
  }
40
41
  end
41
42
 
@@ -61,6 +62,29 @@ describe AirbrakeAPI::Client do
61
62
  end
62
63
  end
63
64
  end
65
+
66
+ context 'with customized middleware' do
67
+ let(:logdev) { StringIO.new }
68
+ # Client#connection is a private method.
69
+ # Adding logger middleware component with an argument it should receive
70
+ # when a connection is initialized
71
+ let(:logger_middleware) { [Faraday::Response::Logger, Logger.new(logdev)] }
72
+ let(:options) do
73
+ {
74
+ :account => 'myapp', :auth_token => 'abcdefg123456', :secure => false,
75
+ :middleware => AirbrakeAPI::Configuration::DEFAULT_MIDDLEWARE + [logger_middleware]
76
+ }
77
+ end
78
+ let(:api) { AirbrakeAPI::Client.new(options) }
79
+
80
+ # request something to initialize @connection with middleware
81
+ before { api.projects }
82
+
83
+ it 'splats array to initialize middleware with arguments' do
84
+ # check that the logger added above did receive the argument
85
+ expect(logdev.string).to include(api.projects_path)
86
+ end
87
+ end
64
88
  end
65
89
 
66
90
  describe 'api requests'do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airbrake-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.1
4
+ version: 4.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-30 00:00:00.000000000 Z
12
+ date: 2013-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
@@ -148,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  segments:
150
150
  - 0
151
- hash: 2479754426924979897
151
+ hash: -3943639386550054679
152
152
  required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  none: false
154
154
  requirements:
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  segments:
159
159
  - 0
160
- hash: 2479754426924979897
160
+ hash: -3943639386550054679
161
161
  requirements: []
162
162
  rubyforge_project:
163
163
  rubygems_version: 1.8.23