lhc 3.5.4 → 3.5.5

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: 8b55a6d77b6a16bb202a4babfc914427d70f092e
4
- data.tar.gz: c618090650536a4f7fbff41c8b83a59b91108e3f
3
+ metadata.gz: 5bd96d437b05df955ff37aed6c1bea4c6c3a68ff
4
+ data.tar.gz: 6fa74559274820bf6cecca05fc6deb4620483529
5
5
  SHA512:
6
- metadata.gz: 036f5aa745a97701ef069a902b9ba7d6b6bb142d72ccfd028ebe91358d68ae23d98b6ea2f70d55c87ba7d064185f7c9b24b99b9a19107e8c00c802ff076fc0e7
7
- data.tar.gz: 74db7500de0d6a3638c5f96ec918984e4dc9624a2405679fb7936e54178e98d9faa638f41b2fb61ad5bf3fe2c07e7fa1d06c5240a46a1296128209eb03d9525d
6
+ metadata.gz: a46627d6d00ea9193860f8cab7e8beaace7c514992cccc803baa36ed050112667445c7cd683f9c95e1d19703dc2e0fd47feb969d09e1d770b9c5bcd4be7b9bb0
7
+ data.tar.gz: 1ea0e5bd2384dc033d38f93a20227160de7c6512b4ff9322c3f2800237ce9db354ea88489ee761938580295ddceab2e70a325852f4c5649670fdfd2fc71b958d
data/README.md CHANGED
@@ -124,3 +124,7 @@ To monitor and manipulate the http communication done with LHC, you can define i
124
124
  ```
125
125
 
126
126
  → [Read more about interceptors](docs/interceptors.md)
127
+
128
+ ## License
129
+
130
+ [GNU Affero General Public License Version 3.](https://www.gnu.org/licenses/agpl-3.0.en.html)
data/lhc.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.email = ['ws-operations@local.ch']
12
12
  s.homepage = 'https://github.com/local-ch/lhc'
13
13
  s.summary = 'LocalHttpServices'
14
- s.description = 'Rails gem wrapping typhoeus and providing additional features (like interceptors)'
14
+ s.description = 'Rails gem for HTTP wrapping typhoeus and providing additional features (like interceptors)'
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- spec/*`.split("\n") +
@@ -30,4 +30,6 @@ Gem::Specification.new do |s|
30
30
  s.add_development_dependency 'geminabox'
31
31
  s.add_development_dependency 'pry'
32
32
  s.add_development_dependency 'ciderizer'
33
+
34
+ s.license = 'GPL-3'
33
35
  end
data/lib/lhc/endpoint.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # The url can also be an url-template.
3
3
  class LHC::Endpoint
4
4
 
5
- PLACEHOLDER = %r{(?<=^):[^\/\.]+|(?<=\/):[^\/\.]+}
5
+ PLACEHOLDER = %r{:[^\/\.:;\d\&]+}
6
6
  ANYTHING_BUT_SINGLE_SLASH_AND_DOT = '([^\/\.]|\/\/)+'.freeze
7
7
 
8
8
  attr_accessor :url, :options
data/lib/lhc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LHC
2
- VERSION = "3.5.4"
2
+ VERSION = "3.5.5"
3
3
  end
@@ -2,12 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe LHC::Request do
4
4
  before do
5
- allow_any_instance_of(described_class).to receive(:use_configured_endpoint!)
6
- allow_any_instance_of(described_class).to receive(:generate_url_from_template!)
5
+ allow_any_instance_of(LHC::Request).to receive(:use_configured_endpoint!)
6
+ allow_any_instance_of(LHC::Request).to receive(:generate_url_from_template!)
7
7
  end
8
8
  context 'request without rails' do
9
9
  it 'does have deep_merge dependency met' do
10
- expect { described_class.new({}, false) }.not_to raise_error
10
+ expect { LHC::Request.new({}, false) }.not_to raise_error
11
11
  end
12
12
  end
13
13
  end
@@ -16,16 +16,16 @@ describe LHC do
16
16
  end
17
17
 
18
18
  it 'does a delete request when providing a complete url' do
19
- described_class.delete('http://datastore/v2/feedbacks/12121')
19
+ LHC.delete('http://datastore/v2/feedbacks/12121')
20
20
  end
21
21
 
22
22
  it 'it makes response data available in a rails way' do
23
- response = described_class.delete('http://datastore/v2/feedbacks/12121')
23
+ response = LHC.delete('http://datastore/v2/feedbacks/12121')
24
24
  expect(response.data.recommended).to eq true
25
25
  end
26
26
 
27
27
  it 'provides response headers' do
28
- response = described_class.delete('http://datastore/v2/feedbacks/12121')
28
+ response = LHC.delete('http://datastore/v2/feedbacks/12121')
29
29
  expect(response.headers).to be
30
30
  end
31
31
  end
@@ -17,23 +17,23 @@ describe LHC do
17
17
  end
18
18
 
19
19
  it 'does a post request when providing a complete url' do
20
- described_class.post('http://datastore/v2/feedbacks', body: feedback.to_json)
20
+ LHC.post('http://datastore/v2/feedbacks', body: feedback.to_json)
21
21
  end
22
22
 
23
23
  it 'does a post request when providing the name of a configured endpoint' do
24
24
  url = 'http://:datastore/v2/feedbacks'
25
25
  options = { params: { datastore: 'datastore' } }
26
- described_class.configure { |c| c.endpoint(:feedbacks, url, options) }
27
- described_class.post(:feedbacks, body: feedback.to_json)
26
+ LHC.configure { |c| c.endpoint(:feedbacks, url, options) }
27
+ LHC.post(:feedbacks, body: feedback.to_json)
28
28
  end
29
29
 
30
30
  it 'it makes response data available in a rails way' do
31
- response = described_class.post('http://datastore/v2/feedbacks', body: feedback.to_json)
31
+ response = LHC.post('http://datastore/v2/feedbacks', body: feedback.to_json)
32
32
  expect(response.data.source_id).to eq 'aaa'
33
33
  end
34
34
 
35
35
  it 'provides response headers' do
36
- response = described_class.post('http://datastore/v2/feedbacks', body: feedback.to_json)
36
+ response = LHC.post('http://datastore/v2/feedbacks', body: feedback.to_json)
37
37
  expect(response.headers).to be
38
38
  end
39
39
  end
@@ -23,23 +23,23 @@ describe LHC do
23
23
  end
24
24
 
25
25
  it 'does a post request when providing a complete url' do
26
- described_class.put('http://datastore/v2/feedbacks', body: change.to_json)
26
+ LHC.put('http://datastore/v2/feedbacks', body: change.to_json)
27
27
  end
28
28
 
29
29
  it 'does a post request when providing the name of a configured endpoint' do
30
30
  url = 'http://:datastore/v2/feedbacks'
31
31
  options = { params: { datastore: 'datastore' } }
32
- described_class.configure { |c| c.endpoint(:feedbacks, url, options) }
33
- described_class.put(:feedbacks, body: change.to_json)
32
+ LHC.configure { |c| c.endpoint(:feedbacks, url, options) }
33
+ LHC.put(:feedbacks, body: change.to_json)
34
34
  end
35
35
 
36
36
  it 'it makes response data available in a rails way' do
37
- response = described_class.put('http://datastore/v2/feedbacks', body: change.to_json)
37
+ response = LHC.put('http://datastore/v2/feedbacks', body: change.to_json)
38
38
  expect(response.data.recommended).to eq false
39
39
  end
40
40
 
41
41
  it 'provides response headers' do
42
- response = described_class.put('http://datastore/v2/feedbacks', body: change.to_json)
42
+ response = LHC.put('http://datastore/v2/feedbacks', body: change.to_json)
43
43
  expect(response.headers).to be
44
44
  end
45
45
  end
@@ -10,7 +10,7 @@ describe LHC do
10
10
  end
11
11
 
12
12
  it 'does a request returning a response' do
13
- response = described_class.request(url: 'http://datastore/v2/feedbacks', params: { has_reviews: true }, method: :get)
13
+ response = LHC.request(url: 'http://datastore/v2/feedbacks', params: { has_reviews: true }, method: :get)
14
14
  expect(response.data.total).to eq total
15
15
  end
16
16
  end
@@ -12,50 +12,50 @@ describe LHC do
12
12
  end
13
13
 
14
14
  before(:each) do
15
- described_class.configure do |c|
15
+ LHC.configure do |c|
16
16
  c.endpoint(:kpi_tracker, url, options)
17
17
  end
18
18
  end
19
19
 
20
20
  it 'configures urls to be able to access them by name later' do
21
- expect(described_class.config.endpoints[:kpi_tracker].url).to eq url
22
- expect(described_class.config.endpoints[:kpi_tracker].options).to eq options
21
+ expect(LHC.config.endpoints[:kpi_tracker].url).to eq url
22
+ expect(LHC.config.endpoints[:kpi_tracker].options).to eq options
23
23
  end
24
24
 
25
25
  it 'compile url' do
26
26
  stub_request(:get, 'http://analytics/track/123/w/request?env=PROD')
27
- response = described_class.get(:kpi_tracker, params: { entity_id: 123, type: 'request' })
27
+ response = LHC.get(:kpi_tracker, params: { entity_id: 123, type: 'request' })
28
28
  expect(response.request.options[:followlocation]).to eq false
29
29
  end
30
30
 
31
31
  it 'gets overwritten by explicit request options' do
32
32
  stub_request(:get, 'http://analytics/track/123/w/request?env=STG')
33
- described_class.get(:kpi_tracker, params: { entity_id: 123, type: 'request', env: 'STG' })
33
+ LHC.get(:kpi_tracker, params: { entity_id: 123, type: 'request', env: 'STG' })
34
34
  end
35
35
 
36
36
  it 'raises in case of claching endpoint names' do
37
37
  expect(lambda {
38
- described_class.config.endpoint(:kpi_tracker, 'http://kpi-tracker')
38
+ LHC.config.endpoint(:kpi_tracker, 'http://kpi-tracker')
39
39
  }).to raise_error 'Endpoint already exists for that name'
40
40
  end
41
41
 
42
42
  it 'enforces endpoint name to be a symbol' do
43
- described_class.configure { |c| c.endpoint('datastore', 'http://datastore') }
44
- expect(described_class.config.endpoints[:datastore].url).to eq 'http://datastore'
43
+ LHC.configure { |c| c.endpoint('datastore', 'http://datastore') }
44
+ expect(LHC.config.endpoints[:datastore].url).to eq 'http://datastore'
45
45
  end
46
46
  end
47
47
 
48
48
  context 'configured enpoints with default params' do
49
49
  before(:each) do
50
- described_class.config.endpoint(:telemarketers, 'http://datastore/v2/spamnumbers?order_by=-user_frequency&swiss_number=true&offset=0&limit=:limit', params: { limit: 200 })
50
+ LHC.config.endpoint(:telemarketers, 'http://datastore/v2/spamnumbers?order_by=-user_frequency&swiss_number=true&offset=0&limit=:limit', params: { limit: 200 })
51
51
  stub_request(:get, 'http://datastore/v2/spamnumbers?limit=200&offset=0&order_by=-user_frequency&swiss_number=true')
52
52
  .to_return(status: 200)
53
53
  end
54
54
 
55
55
  it 'is possible to call them multiple times with default params' do
56
- described_class.get(:telemarketers)
57
- described_class.get(:telemarketers)
58
- described_class.get(:telemarketers)
56
+ LHC.get(:telemarketers)
57
+ LHC.get(:telemarketers)
58
+ LHC.get(:telemarketers)
59
59
  end
60
60
  end
61
61
  end
@@ -3,28 +3,28 @@ require 'rails_helper'
3
3
  describe LHC do
4
4
  context 'configuration of placeholders' do
5
5
  it 'uses values for placeholders defined globally' do
6
- described_class.configure { |c| c.placeholder(:datastore, 'http://datastore/v2') }
6
+ LHC.configure { |c| c.placeholder(:datastore, 'http://datastore/v2') }
7
7
  stub_request(:get, "http://datastore/v2/feedbacks")
8
- described_class.get(':datastore/feedbacks')
8
+ LHC.get(':datastore/feedbacks')
9
9
  end
10
10
 
11
11
  it 'uses explicit values first' do
12
- described_class.configure { |c| c.placeholder(:campaign_id, '123') }
12
+ LHC.configure { |c| c.placeholder(:campaign_id, '123') }
13
13
  stub_request(:get, 'http://datastore/v2/campaign/456/feedbacks')
14
14
  url = 'http://datastore/v2/campaign/:campaign_id/feedbacks'
15
- described_class.get(url, params: { campaign_id: '456' })
15
+ LHC.get(url, params: { campaign_id: '456' })
16
16
  end
17
17
 
18
18
  it 'raises in case of claching placeholder name' do
19
- described_class.configure { |c| c.placeholder(:datastore, 'http://datastore') }
19
+ LHC.configure { |c| c.placeholder(:datastore, 'http://datastore') }
20
20
  expect(lambda {
21
- described_class.config.placeholder(:datastore, 'http://datastore')
21
+ LHC.config.placeholder(:datastore, 'http://datastore')
22
22
  }).to raise_error 'Placeholder already exists for that name'
23
23
  end
24
24
 
25
25
  it 'enforces placeholder name to be a symbol' do
26
- described_class.configure { |c| c.placeholder('datatore', 'http://datastore') }
27
- expect(described_class.config.placeholders[:datatore]).to eq 'http://datastore'
26
+ LHC.configure { |c| c.placeholder('datatore', 'http://datastore') }
27
+ expect(LHC.config.placeholders[:datatore]).to eq 'http://datastore'
28
28
  end
29
29
  end
30
30
  end
@@ -3,14 +3,14 @@ require 'rails_helper'
3
3
  describe LHC::Endpoint do
4
4
  context 'compile' do
5
5
  it 'uses parameters for interpolation' do
6
- endpoint = described_class.new(':datastore/v2/:campaign_id/feedbacks')
6
+ endpoint = LHC::Endpoint.new(':datastore/v2/:campaign_id/feedbacks')
7
7
  expect(
8
8
  endpoint.compile(datastore: 'http://datastore', campaign_id: 'abc')
9
9
  ).to eq "http://datastore/v2/abc/feedbacks"
10
10
  end
11
11
 
12
12
  it 'uses provided proc to find values' do
13
- endpoint = described_class.new(':datastore/v2')
13
+ endpoint = LHC::Endpoint.new(':datastore/v2')
14
14
  config = { datastore: 'http://datastore' }
15
15
  find_value = lambda { |match|
16
16
  config[match.gsub(':', '').to_sym]
@@ -21,10 +21,24 @@ describe LHC::Endpoint do
21
21
  end
22
22
 
23
23
  it 'compiles when templates contain dots' do
24
- endpoint = described_class.new(':datastore/entries/:id.json')
24
+ endpoint = LHC::Endpoint.new(':datastore/entries/:id.json')
25
25
  expect(
26
26
  endpoint.compile(datastore: 'http://datastore', id: 123)
27
27
  ).to eq "http://datastore/entries/123.json"
28
28
  end
29
+
30
+ it 'compiles complex urls containing all sort of characters' do
31
+ endpoint = LHC::Endpoint.new(':ads/?adrawdata/3.0/1108.1/2844859/0/0/header=yes;cookie=no;adct=204;alias=:region_id:lang:product_type:product;key=cat=:category_id')
32
+ expect(
33
+ endpoint.compile(ads: 'http://ads', region_id: 291, lang: 'de', product_type: 'ABC', product: 'xyz', category_id: 312)
34
+ ).to eq 'http://ads/?adrawdata/3.0/1108.1/2844859/0/0/header=yes;cookie=no;adct=204;alias=291deABCxyz;key=cat=312'
35
+ end
36
+
37
+ it 'compiles complex urls containing &' do
38
+ endpoint = LHC::Endpoint.new('http://:weather_search_host/forecast?format=json&period=hour&limit=:limit&areas=:zipcodes&when=:when')
39
+ expect(
40
+ endpoint.compile(weather_search_host: 'weather', limit: 5, zipcodes: [8005, 8004].join(','), when: 'today')
41
+ ).to eq 'http://weather/forecast?format=json&period=hour&limit=5&areas=8005,8004&when=today'
42
+ end
29
43
  end
30
44
  end
@@ -14,7 +14,7 @@ describe LHC::Endpoint do
14
14
  ':datastore/entries/:id.json' => 'http://local.ch/entries/123.json'
15
15
  }.each do |template, url|
16
16
  expect(
17
- described_class.match?(url, template)
17
+ LHC::Endpoint.match?(url, template)
18
18
  ).to be, "#{url} should match #{template}!"
19
19
  end
20
20
  end
@@ -29,7 +29,7 @@ describe LHC::Endpoint do
29
29
  ':datastore/entries/:id' => 'http://local.ch/entries/123.json'
30
30
  }.each do |template, url|
31
31
  expect(
32
- described_class.match?(url, template)
32
+ LHC::Endpoint.match?(url, template)
33
33
  ).not_to be, "#{url} should not match #{template}!"
34
34
  end
35
35
  end
@@ -3,7 +3,7 @@ require 'rails_helper'
3
3
  describe LHC::Endpoint do
4
4
  context 'placeholders' do
5
5
  it 'returns all placeholders alphabetically sorted' do
6
- endpoint = described_class.new(':datastore/v2/:campaign_id/feedbacks')
6
+ endpoint = LHC::Endpoint.new(':datastore/v2/:campaign_id/feedbacks')
7
7
  expect(
8
8
  endpoint.placeholders
9
9
  ).to eq [':campaign_id', ':datastore']
@@ -7,7 +7,7 @@ describe LHC::Endpoint do
7
7
  campaign_id: 'abc',
8
8
  has_reviews: true
9
9
  }
10
- endpoint = described_class.new(':datastore/v2/:campaign_id/feedbacks')
10
+ endpoint = LHC::Endpoint.new(':datastore/v2/:campaign_id/feedbacks')
11
11
  removed = endpoint.remove_interpolated_params!(params)
12
12
  expect(params).to eq(has_reviews: true)
13
13
  expect(removed).to eq(datastore: 'http://datastore', campaign_id: 'abc')
@@ -17,7 +17,7 @@ describe LHC::Endpoint do
17
17
  id: 'ZW9OJyrbt'
18
18
  }]
19
19
  ].each do |example|
20
- params = described_class.values_as_params(example[0], example[1])
20
+ params = LHC::Endpoint.values_as_params(example[0], example[1])
21
21
  expect(params).to eq example[2]
22
22
  end
23
23
  end
@@ -7,48 +7,48 @@ describe LHC::Error do
7
7
 
8
8
  context 'find' do
9
9
  it 'finds error class by status code' do
10
- expect(described_class.find(response('400'))).to eq LHC::BadRequest
11
- expect(described_class.find(response('401'))).to eq LHC::Unauthorized
12
- expect(described_class.find(response('402'))).to eq LHC::PaymentRequired
13
- expect(described_class.find(response('403'))).to eq LHC::Forbidden
14
- expect(described_class.find(response('403'))).to eq LHC::Forbidden
15
- expect(described_class.find(response('404'))).to eq LHC::NotFound
16
- expect(described_class.find(response('405'))).to eq LHC::MethodNotAllowed
17
- expect(described_class.find(response('406'))).to eq LHC::NotAcceptable
18
- expect(described_class.find(response('407'))).to eq LHC::ProxyAuthenticationRequired
19
- expect(described_class.find(response('408'))).to eq LHC::RequestTimeout
20
- expect(described_class.find(response('409'))).to eq LHC::Conflict
21
- expect(described_class.find(response('410'))).to eq LHC::Gone
22
- expect(described_class.find(response('411'))).to eq LHC::LengthRequired
23
- expect(described_class.find(response('412'))).to eq LHC::PreconditionFailed
24
- expect(described_class.find(response('413'))).to eq LHC::RequestEntityTooLarge
25
- expect(described_class.find(response('414'))).to eq LHC::RequestUriToLong
26
- expect(described_class.find(response('415'))).to eq LHC::UnsupportedMediaType
27
- expect(described_class.find(response('416'))).to eq LHC::RequestedRangeNotSatisfiable
28
- expect(described_class.find(response('417'))).to eq LHC::ExpectationFailed
29
- expect(described_class.find(response('422'))).to eq LHC::UnprocessableEntity
30
- expect(described_class.find(response('423'))).to eq LHC::Locked
31
- expect(described_class.find(response('424'))).to eq LHC::FailedDependency
32
- expect(described_class.find(response('426'))).to eq LHC::UpgradeRequired
33
- expect(described_class.find(response('500'))).to eq LHC::InternalServerError
34
- expect(described_class.find(response('501'))).to eq LHC::NotImplemented
35
- expect(described_class.find(response('502'))).to eq LHC::BadGateway
36
- expect(described_class.find(response('503'))).to eq LHC::ServiceUnavailable
37
- expect(described_class.find(response('504'))).to eq LHC::GatewayTimeout
38
- expect(described_class.find(response('505'))).to eq LHC::HttpVersionNotSupported
39
- expect(described_class.find(response('507'))).to eq LHC::InsufficientStorage
40
- expect(described_class.find(response('510'))).to eq LHC::NotExtended
10
+ expect(LHC::Error.find(response('400'))).to eq LHC::BadRequest
11
+ expect(LHC::Error.find(response('401'))).to eq LHC::Unauthorized
12
+ expect(LHC::Error.find(response('402'))).to eq LHC::PaymentRequired
13
+ expect(LHC::Error.find(response('403'))).to eq LHC::Forbidden
14
+ expect(LHC::Error.find(response('403'))).to eq LHC::Forbidden
15
+ expect(LHC::Error.find(response('404'))).to eq LHC::NotFound
16
+ expect(LHC::Error.find(response('405'))).to eq LHC::MethodNotAllowed
17
+ expect(LHC::Error.find(response('406'))).to eq LHC::NotAcceptable
18
+ expect(LHC::Error.find(response('407'))).to eq LHC::ProxyAuthenticationRequired
19
+ expect(LHC::Error.find(response('408'))).to eq LHC::RequestTimeout
20
+ expect(LHC::Error.find(response('409'))).to eq LHC::Conflict
21
+ expect(LHC::Error.find(response('410'))).to eq LHC::Gone
22
+ expect(LHC::Error.find(response('411'))).to eq LHC::LengthRequired
23
+ expect(LHC::Error.find(response('412'))).to eq LHC::PreconditionFailed
24
+ expect(LHC::Error.find(response('413'))).to eq LHC::RequestEntityTooLarge
25
+ expect(LHC::Error.find(response('414'))).to eq LHC::RequestUriToLong
26
+ expect(LHC::Error.find(response('415'))).to eq LHC::UnsupportedMediaType
27
+ expect(LHC::Error.find(response('416'))).to eq LHC::RequestedRangeNotSatisfiable
28
+ expect(LHC::Error.find(response('417'))).to eq LHC::ExpectationFailed
29
+ expect(LHC::Error.find(response('422'))).to eq LHC::UnprocessableEntity
30
+ expect(LHC::Error.find(response('423'))).to eq LHC::Locked
31
+ expect(LHC::Error.find(response('424'))).to eq LHC::FailedDependency
32
+ expect(LHC::Error.find(response('426'))).to eq LHC::UpgradeRequired
33
+ expect(LHC::Error.find(response('500'))).to eq LHC::InternalServerError
34
+ expect(LHC::Error.find(response('501'))).to eq LHC::NotImplemented
35
+ expect(LHC::Error.find(response('502'))).to eq LHC::BadGateway
36
+ expect(LHC::Error.find(response('503'))).to eq LHC::ServiceUnavailable
37
+ expect(LHC::Error.find(response('504'))).to eq LHC::GatewayTimeout
38
+ expect(LHC::Error.find(response('505'))).to eq LHC::HttpVersionNotSupported
39
+ expect(LHC::Error.find(response('507'))).to eq LHC::InsufficientStorage
40
+ expect(LHC::Error.find(response('510'))).to eq LHC::NotExtended
41
41
  end
42
42
 
43
43
  it 'finds error class also by extended status codes' do
44
- expect(described_class.find(response('40001'))).to eq LHC::BadRequest
45
- expect(described_class.find(response('50002'))).to eq LHC::InternalServerError
44
+ expect(LHC::Error.find(response('40001'))).to eq LHC::BadRequest
45
+ expect(LHC::Error.find(response('50002'))).to eq LHC::InternalServerError
46
46
  end
47
47
 
48
48
  it 'returns UnknownError if no specific error was found' do
49
- expect(described_class.find(response('0'))).to eq LHC::UnknownError
50
- expect(described_class.find(response(''))).to eq LHC::UnknownError
51
- expect(described_class.find(response('600'))).to eq LHC::UnknownError
49
+ expect(LHC::Error.find(response('0'))).to eq LHC::UnknownError
50
+ expect(LHC::Error.find(response(''))).to eq LHC::UnknownError
51
+ expect(LHC::Error.find(response('600'))).to eq LHC::UnknownError
52
52
  end
53
53
  end
54
54
  end
@@ -7,13 +7,13 @@ describe LHC do
7
7
  def after_request(request)
8
8
  end
9
9
  end
10
- described_class.configure { |c| c.interceptors = [SomeInterceptor] }
10
+ LHC.configure { |c| c.interceptors = [SomeInterceptor] }
11
11
  end
12
12
 
13
13
  it 'can perform some actions after a request was fired' do
14
14
  expect_any_instance_of(SomeInterceptor).to receive(:after_request)
15
15
  stub_request(:get, 'http://local.ch')
16
- described_class.get('http://local.ch')
16
+ LHC.get('http://local.ch')
17
17
  end
18
18
  end
19
19
  end
@@ -25,7 +25,7 @@ describe LHC do
25
25
  Services.timing(path.downcase, response.time)
26
26
  end
27
27
  end
28
- described_class.configure { |c| c.interceptors = [StatsTimingInterceptor] }
28
+ LHC.configure { |c| c.interceptors = [StatsTimingInterceptor] }
29
29
  end
30
30
 
31
31
  let(:url) { "http://local.ch/v2/feedbacks/-Sc4_pYNpqfsudzhtivfkA" }
@@ -33,7 +33,7 @@ describe LHC do
33
33
  it 'can take action after a response was received' do
34
34
  allow(Services).to receive(:timing).with('web.dummy.test.get.http.local.ch.200', 0)
35
35
  stub_request(:get, url)
36
- described_class.get(url)
36
+ LHC.get(url)
37
37
  expect(Services).to have_received(:timing)
38
38
  end
39
39
  end
@@ -8,12 +8,12 @@ describe LHC do
8
8
  request.params[:tid] = 123
9
9
  end
10
10
  end
11
- described_class.configure { |c| c.interceptors = [TrackingIdInterceptor] }
11
+ LHC.configure { |c| c.interceptors = [TrackingIdInterceptor] }
12
12
  end
13
13
 
14
14
  it 'can modify requests before they are send' do
15
15
  stub_request(:get, "http://local.ch/?tid=123")
16
- described_class.get('http://local.ch')
16
+ LHC.get('http://local.ch')
17
17
  end
18
18
  end
19
19
  end
@@ -7,13 +7,13 @@ describe LHC do
7
7
  def before_response(request)
8
8
  end
9
9
  end
10
- described_class.configure { |c| c.interceptors = [SomeInterceptor] }
10
+ LHC.configure { |c| c.interceptors = [SomeInterceptor] }
11
11
  end
12
12
 
13
13
  it 'can perform some actions before a reponse is received' do
14
14
  expect_any_instance_of(SomeInterceptor).to receive(:before_response)
15
15
  stub_request(:get, 'http://local.ch')
16
- described_class.get('http://local.ch')
16
+ LHC.get('http://local.ch')
17
17
  end
18
18
  end
19
19
  end
@@ -3,11 +3,11 @@ require 'rails_helper'
3
3
  describe LHC do
4
4
  context 'default interceptors' do
5
5
  before(:each) do
6
- described_class.configure {}
6
+ LHC.configure {}
7
7
  end
8
8
 
9
9
  it 'alwayses return a list for default interceptors' do
10
- expect(described_class.config.interceptors).to eq []
10
+ expect(LHC.config.interceptors).to eq []
11
11
  end
12
12
  end
13
13
  end
@@ -10,18 +10,18 @@ describe LHC do
10
10
  end
11
11
 
12
12
  it 'performs interceptor when they are set globally' do
13
- described_class.configure { |c| c.interceptors = [SomeInterceptor] }
13
+ LHC.configure { |c| c.interceptors = [SomeInterceptor] }
14
14
  expect_any_instance_of(SomeInterceptor).to receive(:before_request)
15
15
  stub_request(:get, 'http://local.ch')
16
- described_class.get('http://local.ch')
16
+ LHC.get('http://local.ch')
17
17
  end
18
18
 
19
19
  it 'overrides interceptors on request level' do
20
- described_class.configure { |c| c.interceptors = [SomeInterceptor] }
20
+ LHC.configure { |c| c.interceptors = [SomeInterceptor] }
21
21
  expect_any_instance_of(AnotherInterceptor).to receive(:before_request)
22
22
  expect_any_instance_of(SomeInterceptor).not_to receive(:before_request)
23
23
  stub_request(:get, 'http://local.ch')
24
- described_class.get('http://local.ch', interceptors: [AnotherInterceptor])
24
+ LHC.get('http://local.ch', interceptors: [AnotherInterceptor])
25
25
  end
26
26
  end
27
27
  end
@@ -25,14 +25,14 @@ describe LHC do
25
25
  end
26
26
  end
27
27
 
28
- described_class.configure { |c| c.interceptors = [LocalCacheInterceptor, RemoteCacheInterceptor] }
28
+ LHC.configure { |c| c.interceptors = [LocalCacheInterceptor, RemoteCacheInterceptor] }
29
29
  end
30
30
 
31
31
  it 'can handle multiple interceptors that compete for returning the response' do
32
- response = described_class.get('http://local.ch')
32
+ response = LHC.get('http://local.ch')
33
33
  expect(response.body).to eq 'Im served from remote cache'
34
34
  LocalCacheInterceptor.cached = true
35
- response = described_class.get('http://local.ch')
35
+ response = LHC.get('http://local.ch')
36
36
  expect(response.body).to eq 'Im served from local cache'
37
37
  end
38
38
  end
@@ -9,11 +9,11 @@ describe LHC do
9
9
  LHC::Response.new(Typhoeus::Response.new(response_body: 'Im served from cache'), nil)
10
10
  end
11
11
  end
12
- described_class.configure { |c| c.interceptors = [CacheInterceptor] }
12
+ LHC.configure { |c| c.interceptors = [CacheInterceptor] }
13
13
  end
14
14
 
15
15
  it 'can return a response rather then doing a real request' do
16
- response = described_class.get('http://local.ch')
16
+ response = LHC.get('http://local.ch')
17
17
  expect(response.body).to eq 'Im served from cache'
18
18
  end
19
19
 
@@ -28,7 +28,7 @@ describe LHC do
28
28
 
29
29
  it 'raises an exception when two interceptors try to return a response' do
30
30
  expect(lambda {
31
- described_class.get('http://local.ch', interceptors: [CacheInterceptor, AnotherInterceptor])
31
+ LHC.get('http://local.ch', interceptors: [CacheInterceptor, AnotherInterceptor])
32
32
  }).to raise_error 'Response already set from another interceptor'
33
33
  end
34
34
  end
@@ -7,7 +7,7 @@ describe LHC::Response do
7
7
  let(:raw_response) { OpenStruct.new(body: body) }
8
8
 
9
9
  it 'provides response body' do
10
- response = described_class.new(raw_response, nil)
10
+ response = LHC::Response.new(raw_response, nil)
11
11
  expect(response.body).to eq body
12
12
  end
13
13
  end
@@ -7,7 +7,7 @@ describe LHC::Response do
7
7
  let(:raw_response) { OpenStruct.new(code: code) }
8
8
 
9
9
  it 'provides response code' do
10
- response = described_class.new(raw_response, nil)
10
+ response = LHC::Response.new(raw_response, nil)
11
11
  expect(response.code).to eq code
12
12
  end
13
13
  end
@@ -7,7 +7,7 @@ describe LHC::Response do
7
7
  let(:raw_response) { OpenStruct.new(effective_url: effective_url) }
8
8
 
9
9
  it 'provides effective_url' do
10
- response = described_class.new(raw_response, nil)
10
+ response = LHC::Response.new(raw_response, nil)
11
11
  expect(response.effective_url).to eq effective_url
12
12
  end
13
13
  end
@@ -9,7 +9,7 @@ describe LHC::Response do
9
9
  let(:raw_response) { OpenStruct.new(headers: headers) }
10
10
 
11
11
  it 'provides headers' do
12
- response = described_class.new(raw_response, nil)
12
+ response = LHC::Response.new(raw_response, nil)
13
13
  expect(response.headers).to eq headers
14
14
  end
15
15
  end
@@ -9,7 +9,7 @@ describe LHC::Response do
9
9
  let(:raw_response) { OpenStruct.new(options: options) }
10
10
 
11
11
  it 'provides headers' do
12
- response = described_class.new(raw_response, nil)
12
+ response = LHC::Response.new(raw_response, nil)
13
13
  expect(response.options).to eq options
14
14
  end
15
15
  end
@@ -2,8 +2,8 @@ require 'rails_helper'
2
2
 
3
3
  describe LHC::Response do
4
4
  context 'success?' do
5
- let(:response_success) { described_class.new(Typhoeus::Response.new(response_code: 200, mock: true), nil) }
6
- let(:response_error) { described_class.new(Typhoeus::Response.new(response_code: 404, mock: true), nil) }
5
+ let(:response_success) { LHC::Response.new(Typhoeus::Response.new(response_code: 200, mock: true), nil) }
6
+ let(:response_error) { LHC::Response.new(Typhoeus::Response.new(response_code: 404, mock: true), nil) }
7
7
 
8
8
  it { expect(response_success.success?).to be_truthy }
9
9
  it { expect(response_error.success?).to be_falsy }
@@ -7,7 +7,7 @@ describe LHC::Response do
7
7
  let(:raw_response) { OpenStruct.new(time: time) }
8
8
 
9
9
  it 'provides response time in milliseconds' do
10
- response = described_class.new(raw_response, nil)
10
+ response = LHC::Response.new(raw_response, nil)
11
11
  expect(response.time).to eq time * 1000
12
12
  end
13
13
  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: 3.5.4
4
+ version: 3.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - local.ch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-13 00:00:00.000000000 Z
11
+ date: 2016-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -122,7 +122,8 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description: Rails gem wrapping typhoeus and providing additional features (like interceptors)
125
+ description: Rails gem for HTTP wrapping typhoeus and providing additional features
126
+ (like interceptors)
126
127
  email:
127
128
  - ws-operations@local.ch
128
129
  executables: []
@@ -256,7 +257,8 @@ files:
256
257
  - spec/timeouts/no_signal_spec.rb
257
258
  - spec/timeouts/timings_spec.rb
258
259
  homepage: https://github.com/local-ch/lhc
259
- licenses: []
260
+ licenses:
261
+ - GPL-3
260
262
  metadata: {}
261
263
  post_install_message:
262
264
  rdoc_options: []