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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTY3ZmUyYjk3ZWUxYjZkMGI4ZjFkNDAxZjk3NjAwNWFkM2E0YzFmZQ==
4
+ MjA1Zjg1OWU2ZWRiNmI3MWFmOGFhOGUwODk3ZTM1ZWZlOWJkZGVjNQ==
5
5
  data.tar.gz: !binary |-
6
- YzBmMjIzZDc0Mjg2ZTk1NDQyMGYwMDI3MWExZDdjMjMyY2QzYWE4ZA==
6
+ MzZiMTgxMWEyZjc0NjczMmFiMjdhZDQzMWU4ZDNiZDA1MzIzZmZiNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWVjYzBiMmY4ZDExNzM4ZDIxMDFkMjdkNWQ3OWViODY0NGFlMjk0MGJiNDAz
10
- MjkyMmRhNmVkMDY5M2ZhNWE2MTg3ZGJkNjg4YTI0OGE4MzFmOTZjNjg3NDQx
11
- N2ZlZmIxYjEwOGIwYTg1YWZjYzlmZjI3NjFiZjRkMzlmZjY2ZGQ=
9
+ NmVlZjMwNTVjMGJmNjEwNDg2YzM1Nzc1ZjUyNGVkZjQ5NDYxMzlhZTJhMDRk
10
+ NDI3M2I2MDBkZmU2NWFlYjY3NDBhNzRlYjA0NWVmODNhMGZlYzlhYTJiNmFl
11
+ MTY2N2U1N2IzM2MyMDM4ZjgyNzAwMzA1YzE2NmRjNWFkYmMwNWE=
12
12
  data.tar.gz: !binary |-
13
- NTkwYmNhOTVhYjU4NjU1NjNmYjFkZGMwMWIwNmMyNjU4MGRlYWU2ZTE4ZTg3
14
- MjZjNjQ3ZGY4MDRlYmJiNzBjOTllMzcwNDhjYjAxMzRiOWMzOWMzMTQwOWEz
15
- ZjE2ZGI2ZDA2NWNiMzJjZGM4ZTBmMTkwYjZmNmQ4MmNlOWE3YjM=
13
+ MzY4OWMxYjQzNzRmZmNlM2FlNGIzZTgxNzcwNmUxZWM1MDNlZWYyNDhhZjU5
14
+ YTNlM2FmNGY2MmNiY2VlNTNjYTFjZTQ5ODU3MzJhYmQ0OWQzMDMyNWI5ODEw
15
+ ZDI2NTJjMDcxZjIzZTIxOGRkZmUzMzQ0Njc0YmM2NmYzMDc1MWE=
data/README.md CHANGED
@@ -149,3 +149,7 @@ This will install `/usr/local/opt/curl-ca-bundle/share/ca-bundle.crt`
149
149
 
150
150
  ### 0.1.1 - 2014-04-04
151
151
  * Allow logger to be injected
152
+
153
+ ### 0.1.2 - 2014-04-04
154
+ * Update logging to be less generic to avoid clash with other log fields
155
+
@@ -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 config.include_request_id_header
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'
@@ -1,3 +1,3 @@
1
1
  module HttpApiClient
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -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
- let(:request_id) { 'abc-123' }
143
+ context "with a request id in current thread" do
144
144
 
145
- before do
146
- Thread.current[:request_id] = request_id
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
- it "adds the Request-Id header to the request" do
150
- connection.should_receive(:get).with('/test-base-uri/path/1', {}, base_get_headers.merge('X-Request-Id' => request_id))
151
- client.find('/path', 1)
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("event=my_event, request_id=#{request_id}, timing=#{1000}")
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("event=my_event, request_id=#{request_id}, timing=#{1000}, foo=bar")
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.2
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-04 00:00:00.000000000 Z
14
+ date: 2014-04-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler