restful_resource 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03a7e9a15a400320a4a636f9d010e65e34880b49
4
- data.tar.gz: ebcae394889e3a8dbe9193a8a43a07d6377aa911
3
+ metadata.gz: 3f0b710977f827bb7d5698d80989ce066d532dac
4
+ data.tar.gz: 036d21d808eaf17e83dc0c0dcaaa61e03f2b1005
5
5
  SHA512:
6
- metadata.gz: 3a22f16b829e19e92215c00cadf942b042026cba134aefc4f75bcdaeab66dfdc20b23a6608c639bdfb8faf4fdf07b067f56ff3f2836208f71d80f15410fffb09
7
- data.tar.gz: 5980a0c3537c0147a947c1470df0f7a79f9850b30377a03bae1dcf699049c9f6f01b74c5e97949d28b94c78fc6bbef2c07cb391aa68a470cce968d3fe79d1fe6
6
+ metadata.gz: 13aeb2fd10f632f1b7e99f2cf4ecb7bdfcc8d4856b719ad7cd1ef0a8ffb7640b7a057f2267e2fa03754f77ac56f97fbb349c6491407f6caed487c214a0c262e0
7
+ data.tar.gz: 4866c6e3d44c15591953ff9f7a096a902466e347d8c5505bb2f9d8a3b07f281a18d5027a85285d228b0796ca2f909ff64aa550916ad2ca4962e741fd1e42ec5e
@@ -96,6 +96,7 @@ module RestfulResource
96
96
  faraday_config: faraday_config)
97
97
 
98
98
  @connection.basic_auth(username, password) if username && password
99
+ @connection.headers[:user_agent] = build_user_agent(instrumentation[:app_name])
99
100
  @default_open_timeout = open_timeout
100
101
  @default_timeout = timeout
101
102
  end
@@ -197,6 +198,13 @@ module RestfulResource
197
198
  end
198
199
  end
199
200
 
201
+ def build_user_agent(app_name)
202
+ parts = ["RestfulResource/#{VERSION}"]
203
+ parts << "(#{app_name})" if app_name
204
+ parts << "Faraday/#{Faraday::VERSION}"
205
+ parts.join(' ')
206
+ end
207
+
200
208
  def http_request(request)
201
209
  response = @connection.send(request.method) do |req|
202
210
  req.options.open_timeout = request.open_timeout || default_open_timeout # seconds
@@ -1,3 +1,3 @@
1
1
  module RestfulResource
2
- VERSION = '2.2.2'
2
+ VERSION = '2.2.3'
3
3
  end
@@ -186,4 +186,32 @@ RSpec.describe RestfulResource::HttpClient do
186
186
  expect(response.status).to eq 200
187
187
  end
188
188
  end
189
+
190
+ describe 'User-Agent' do
191
+ def http_client(connection, app_name: nil)
192
+ described_class.new(connection: connection, instrumentation: { app_name: app_name })
193
+ end
194
+
195
+ it 'sets a default user-agent header' do
196
+ connection = faraday_connection do |stubs|
197
+ user_agent = "RestfulResource/#{RestfulResource::VERSION} Faraday/#{Faraday::VERSION}"
198
+ stubs.get('http://httpbin.org/get', { 'User-Agent' => user_agent }) { |env| [200, {}, nil] }
199
+ end
200
+
201
+ response = http_client(connection).get('http://httpbin.org/get')
202
+
203
+ expect(response.status).to eq 200
204
+ end
205
+
206
+ it 'sets a default user-agent header including app name' do
207
+ connection = faraday_connection do |stubs|
208
+ user_agent = "RestfulResource/#{RestfulResource::VERSION} (my-app) Faraday/#{Faraday::VERSION}"
209
+ stubs.get('http://httpbin.org/get', { 'User-Agent' => user_agent }) { |env| [200, {}, nil] }
210
+ end
211
+
212
+ response = http_client(connection, app_name: "my-app").get('http://httpbin.org/get')
213
+
214
+ expect(response.status).to eq 200
215
+ end
216
+ end
189
217
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Santoro
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-01-25 00:00:00.000000000 Z
12
+ date: 2018-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -258,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  version: '0'
259
259
  requirements: []
260
260
  rubyforge_project:
261
- rubygems_version: 2.6.13
261
+ rubygems_version: 2.6.14
262
262
  signing_key:
263
263
  specification_version: 4
264
264
  summary: A simple activerecord inspired rest resource base class implemented using