http_api_client 0.1.2 → 0.1.3
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 +8 -8
- data/README.md +4 -0
- data/lib/http_api_client/client.rb +5 -1
- data/lib/http_api_client/version.rb +1 -1
- data/spec/http_client/client_spec.rb +21 -6
- data/spec/http_client/timed_result_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjA1Zjg1OWU2ZWRiNmI3MWFmOGFhOGUwODk3ZTM1ZWZlOWJkZGVjNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzZiMTgxMWEyZjc0NjczMmFiMjdhZDQzMWU4ZDNiZDA1MzIzZmZiNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmVlZjMwNTVjMGJmNjEwNDg2YzM1Nzc1ZjUyNGVkZjQ5NDYxMzlhZTJhMDRk
|
10
|
+
NDI3M2I2MDBkZmU2NWFlYjY3NDBhNzRlYjA0NWVmODNhMGZlYzlhYTJiNmFl
|
11
|
+
MTY2N2U1N2IzM2MyMDM4ZjgyNzAwMzA1YzE2NmRjNWFkYmMwNWE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzY4OWMxYjQzNzRmZmNlM2FlNGIzZTgxNzcwNmUxZWM1MDNlZWYyNDhhZjU5
|
14
|
+
YTNlM2FmNGY2MmNiY2VlNTNjYTFjZTQ5ODU3MzJhYmQ0OWQzMDMyNWI5ODEw
|
15
|
+
ZDI2NTJjMDcxZjIzZTIxOGRkZmUzMzQ0Njc0YmM2NmYzMDc1MWE=
|
data/README.md
CHANGED
@@ -128,10 +128,14 @@ module HttpApiClient
|
|
128
128
|
|
129
129
|
def request_headers(base_headers, custom_headers = {})
|
130
130
|
all_headers = base_headers.merge(custom_headers)
|
131
|
-
all_headers.merge!({'X-Request-Id' => Thread.current[:request_id]}) if
|
131
|
+
all_headers.merge!({'X-Request-Id' => Thread.current[:request_id]}) if include_request_id_header?
|
132
132
|
all_headers
|
133
133
|
end
|
134
134
|
|
135
|
+
def include_request_id_header?
|
136
|
+
config.include_request_id_header && Thread.current[:request_id] != nil
|
137
|
+
end
|
138
|
+
|
135
139
|
def get_headers
|
136
140
|
{
|
137
141
|
'Accept' => 'application/json'
|
@@ -140,15 +140,30 @@ module HttpApiClient
|
|
140
140
|
|
141
141
|
let(:client) { Client.new(:my_client, 'spec/config/http_api_clients_with_request_id.yml') }
|
142
142
|
|
143
|
-
|
143
|
+
context "with a request id in current thread" do
|
144
144
|
|
145
|
-
|
146
|
-
|
145
|
+
let(:request_id) { 'abc-123' }
|
146
|
+
|
147
|
+
before do
|
148
|
+
Thread.current[:request_id] = request_id
|
149
|
+
end
|
150
|
+
|
151
|
+
it "adds the Request-Id header to the request" do
|
152
|
+
connection.should_receive(:get).with('/test-base-uri/path/1', {}, base_get_headers.merge('X-Request-Id' => request_id))
|
153
|
+
client.find('/path', 1)
|
154
|
+
end
|
147
155
|
end
|
148
156
|
|
149
|
-
|
150
|
-
|
151
|
-
|
157
|
+
context "without a request id in current thread" do
|
158
|
+
|
159
|
+
before do
|
160
|
+
Thread.current[:request_id] = nil
|
161
|
+
end
|
162
|
+
|
163
|
+
it "does not add the Request-Id header to the request" do
|
164
|
+
connection.should_receive(:get).with('/test-base-uri/path/1', {}, base_get_headers)
|
165
|
+
client.find('/path', 1)
|
166
|
+
end
|
152
167
|
end
|
153
168
|
end
|
154
169
|
|
@@ -17,12 +17,12 @@ module HttpApiClient
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'logs event with base data' do
|
20
|
-
logger.should_receive(:info).with("
|
20
|
+
logger.should_receive(:info).with("event_name=my_event, request_id=#{request_id}, timing=#{1000}")
|
21
21
|
TimedResult.time('my_event') { }
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'logs event with extra data' do
|
25
|
-
logger.should_receive(:info).with("
|
25
|
+
logger.should_receive(:info).with("event_name=my_event, request_id=#{request_id}, timing=#{1000}, foo=bar")
|
26
26
|
TimedResult.time('my_event', { foo: 'bar' }) { }
|
27
27
|
end
|
28
28
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Monie
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-04-
|
14
|
+
date: 2014-04-07 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|