lhc 9.4.4 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/lib/lhc/concerns/lhc/request/user_agent_concern.rb +17 -0
- data/lib/lhc/request.rb +4 -2
- data/lib/lhc/version.rb +1 -1
- data/spec/request/url_patterns_spec.rb +0 -29
- data/spec/request/user_agent_spec.rb +24 -0
- data/spec/request/user_agent_without_rails_spec.rb +25 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97fdf362698642e8dccbd9263ee7253563d3dfa2cbcde0daea331fee79c6ad58
|
4
|
+
data.tar.gz: 62dba156d28e3d12ab4d4d73ff686088ae4752f11e67c8df5e74e9df2bd0eea1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91745336ea808eb5a51f6a476bec8a36f017ccb65a4f2fda9fdda1c904f0b6f28e00f668947963acc207ab608bfbc8b2444548f55b5236a6fcb266d55a7a7687
|
7
|
+
data.tar.gz: 2591ed19fb8e34de1e423d58ed119faa0048c33a1300b8cceb569d94e377d63ea4981e220251434429cc13d14fdeed1a8897d5b943af5c2bc1b56b92bd9546be
|
data/README.md
CHANGED
@@ -44,6 +44,7 @@ use it like:
|
|
44
44
|
* [Request URL encoding](#request-url-encoding)
|
45
45
|
* [Request URL-Templates](#request-url-templates)
|
46
46
|
* [Request timeout](#request-timeout)
|
47
|
+
* [Request Agent](#request-agent)
|
47
48
|
* [Response](#response)
|
48
49
|
* [Accessing response data](#accessing-response-data)
|
49
50
|
* [Exceptions](#exceptions)
|
@@ -255,6 +256,20 @@ LHC.get('http://local.ch', timeout: 5, connecttimeout: 1)
|
|
255
256
|
|
256
257
|
LHC provides a [timeout interceptor](#default-timeout-interceptor) that lets you apply default timeout values to all the requests that you are performig in your application.
|
257
258
|
|
259
|
+
### Request Agent
|
260
|
+
|
261
|
+
LHC identifies itself towards outher services, using the `User-Agent` header.
|
262
|
+
|
263
|
+
```
|
264
|
+
User-Agent LHC (9.4.2) [https://github.com/local-ch/lhc]
|
265
|
+
```
|
266
|
+
|
267
|
+
If LHC is used in an Rails Application context, also the application name is added to the `User-Agent` header.
|
268
|
+
|
269
|
+
```
|
270
|
+
User-Agent LHC (9.4.2; MyRailsApplicationName) [https://github.com/local-ch/lhc]
|
271
|
+
```
|
272
|
+
|
258
273
|
## Response
|
259
274
|
|
260
275
|
```ruby
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module LHC
|
4
|
+
class Request
|
5
|
+
module UserAgentConcern
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
Typhoeus::Config.user_agent = begin
|
10
|
+
version = LHC::VERSION
|
11
|
+
application = defined?(Rails) ? Rails.application.class.parent_name : nil
|
12
|
+
"LHC (#{[version, application].compact.join('; ')}) [https://github.com/local-ch/lhc]"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/lhc/request.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'uri'
|
2
2
|
require 'active_support/core_ext/object/deep_dup'
|
3
|
+
require 'lhc/concerns/lhc/request/user_agent_concern'
|
3
4
|
|
4
5
|
# The request is doing an http-request using typhoeus.
|
5
6
|
# It provides functionalities to access and alter request data
|
6
7
|
# and it communicates with interceptors.
|
7
8
|
class LHC::Request
|
9
|
+
include UserAgentConcern
|
8
10
|
|
9
11
|
TYPHOEUS_OPTIONS ||= [:params, :method, :body, :headers, :follow_location, :params_encoding]
|
10
12
|
|
@@ -109,8 +111,8 @@ class LHC::Request
|
|
109
111
|
def generate_url_from_template!
|
110
112
|
endpoint = LHC::Endpoint.new(options[:url])
|
111
113
|
params =
|
112
|
-
if format && options[:body]
|
113
|
-
options[:body].
|
114
|
+
if format && options[:body]&.length && options[:body].is_a?(Hash)
|
115
|
+
options[:body].merge(options[:params] || {}).deep_symbolize_keys
|
114
116
|
else
|
115
117
|
options[:params]
|
116
118
|
end
|
data/lib/lhc/version.rb
CHANGED
@@ -20,33 +20,4 @@ describe LHC::Request do
|
|
20
20
|
stub_request(:post, "http://datastore:8080/v2/places/123")
|
21
21
|
LHC.json.post('http://datastore:8080/v2/places/{id}', body: { id: 123 })
|
22
22
|
end
|
23
|
-
|
24
|
-
context 'custom data structures that respond to as_json (like LHS data or record)' do
|
25
|
-
before do
|
26
|
-
class CustomStructure
|
27
|
-
|
28
|
-
def initialize(data)
|
29
|
-
@data = data
|
30
|
-
end
|
31
|
-
|
32
|
-
def as_json
|
33
|
-
@data.as_json
|
34
|
-
end
|
35
|
-
|
36
|
-
def to_json
|
37
|
-
as_json.to_json
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
let(:data) do
|
43
|
-
CustomStructure.new(id: '12345')
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'compiles url from body params when body object respond_to(:as_json)' do
|
47
|
-
stub_request(:post, "http://datastore/places/12345")
|
48
|
-
.to_return(status: 200)
|
49
|
-
LHC.post('http://datastore/places/{id}', body: data)
|
50
|
-
end
|
51
|
-
end
|
52
23
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHC::Request do
|
4
|
+
before do
|
5
|
+
LHC.send(:remove_const, :Request)
|
6
|
+
load('lhc/concerns/lhc/request/user_agent_concern.rb')
|
7
|
+
load('lhc/request.rb')
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'default headers' do
|
11
|
+
context 'agent' do
|
12
|
+
it 'sets header agent information to be LHC' do
|
13
|
+
stub_request(:get, "http://local.ch/")
|
14
|
+
.with(
|
15
|
+
headers: {
|
16
|
+
'User-Agent' => "LHC (#{LHC::VERSION}; Dummy) [https://github.com/local-ch/lhc]"
|
17
|
+
}
|
18
|
+
)
|
19
|
+
.to_return(status: 200)
|
20
|
+
LHC.get('http://local.ch')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LHC::Request do
|
4
|
+
before do
|
5
|
+
Object.send(:remove_const, :Rails)
|
6
|
+
LHC.send(:remove_const, :Request)
|
7
|
+
load('lhc/concerns/lhc/request/user_agent_concern.rb')
|
8
|
+
load('lhc/request.rb')
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'default headers' do
|
12
|
+
context 'agent' do
|
13
|
+
it 'sets header agent information to be LHC' do
|
14
|
+
stub_request(:get, "http://local.ch/")
|
15
|
+
.with(
|
16
|
+
headers: {
|
17
|
+
'User-Agent' => "LHC (#{LHC::VERSION}) [https://github.com/local-ch/lhc]"
|
18
|
+
}
|
19
|
+
)
|
20
|
+
.to_return(status: 200)
|
21
|
+
LHC.get('http://local.ch')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 10.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhc/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -196,6 +196,7 @@ files:
|
|
196
196
|
- lib/lhc/concerns/lhc/basic_methods_concern.rb
|
197
197
|
- lib/lhc/concerns/lhc/configuration_concern.rb
|
198
198
|
- lib/lhc/concerns/lhc/formats_concern.rb
|
199
|
+
- lib/lhc/concerns/lhc/request/user_agent_concern.rb
|
199
200
|
- lib/lhc/config.rb
|
200
201
|
- lib/lhc/endpoint.rb
|
201
202
|
- lib/lhc/error.rb
|
@@ -324,6 +325,8 @@ files:
|
|
324
325
|
- spec/request/params_encoding_spec.rb
|
325
326
|
- spec/request/request_without_rails_spec.rb
|
326
327
|
- spec/request/url_patterns_spec.rb
|
328
|
+
- spec/request/user_agent_spec.rb
|
329
|
+
- spec/request/user_agent_without_rails_spec.rb
|
327
330
|
- spec/response/body_spec.rb
|
328
331
|
- spec/response/code_spec.rb
|
329
332
|
- spec/response/data_accessor_spec.rb
|
@@ -465,6 +468,8 @@ test_files:
|
|
465
468
|
- spec/request/params_encoding_spec.rb
|
466
469
|
- spec/request/request_without_rails_spec.rb
|
467
470
|
- spec/request/url_patterns_spec.rb
|
471
|
+
- spec/request/user_agent_spec.rb
|
472
|
+
- spec/request/user_agent_without_rails_spec.rb
|
468
473
|
- spec/response/body_spec.rb
|
469
474
|
- spec/response/code_spec.rb
|
470
475
|
- spec/response/data_accessor_spec.rb
|