lhc 6.7.2 → 7.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/README.md +5 -4
- data/docs/configuration.md +5 -5
- data/docs/exceptions.md +1 -1
- data/docs/interceptors.md +1 -1
- data/docs/interceptors/caching.md +1 -1
- data/docs/interceptors/prometheus.md +2 -2
- data/docs/interceptors/retry.md +1 -1
- data/lhc.gemspec +1 -0
- data/lib/lhc/endpoint.rb +63 -73
- data/lib/lhc/version.rb +1 -1
- data/spec/basic_methods/get_spec.rb +1 -1
- data/spec/basic_methods/post_spec.rb +1 -1
- data/spec/basic_methods/put_spec.rb +1 -1
- data/spec/config/endpoints_spec.rb +1 -1
- data/spec/config/placeholders_spec.rb +2 -2
- data/spec/endpoint/compile_spec.rb +4 -15
- data/spec/endpoint/match_spec.rb +20 -22
- data/spec/endpoint/placeholders_spec.rb +2 -2
- data/spec/endpoint/remove_interpolated_params_spec.rb +1 -1
- data/spec/endpoint/values_as_params_spec.rb +21 -17
- data/spec/request/option_dup_spec.rb +1 -1
- data/spec/request/url_patterns_spec.rb +3 -3
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfdf5514e679a637e9e800e71d64394e922494ab
|
4
|
+
data.tar.gz: '09f38587235d31394bc9100cba4dde8e292592b8'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74a8a94d300802292148f4c590a924197f94f2e93e3909510f70537da5c740f6e5d10de3da5473b84f25b102822434f6709ec696986e46107789643cfc5fd2cf
|
7
|
+
data.tar.gz: 4dd2d4d39e7d9907366f6c132b676aca4167d219df0e2e7820f1e515a9c3bf79442016a547d16a5fe4d6fe8997234ffc50bffce821d6cbdb51c1c5999154568c
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.4.3
|
data/README.md
CHANGED
@@ -105,7 +105,7 @@ You can configure global endpoints, placeholders and interceptors.
|
|
105
105
|
```ruby
|
106
106
|
LHC.configure do |c|
|
107
107
|
c.placeholder :datastore, 'http://datastore/v2'
|
108
|
-
c.endpoint :feedbacks, '
|
108
|
+
c.endpoint :feedbacks, '{+datastore}/feedbacks', params: { has_reviews: true }
|
109
109
|
c.interceptors = [LHC::Caching]
|
110
110
|
end
|
111
111
|
```
|
@@ -116,9 +116,10 @@ You can configure global endpoints, placeholders and interceptors.
|
|
116
116
|
|
117
117
|
Instead of using concrete urls you can also use url-templates that contain placeholders.
|
118
118
|
This is especially handy for configuring an endpoint once and generate the url from the params when doing the request.
|
119
|
+
Since version `7.0` url templates follow the [RFC 6750](https://tools.ietf.org/html/rfc6570).
|
119
120
|
|
120
121
|
```ruby
|
121
|
-
url = 'http://datastore/v2/feedbacks
|
122
|
+
url = 'http://datastore/v2/feedbacks/{id}'
|
122
123
|
LHC.config.endpoint(:find_feedback, url, options)
|
123
124
|
LHC.get(:find_feedback, params:{ id: 123 })
|
124
125
|
# GET http://datastore/v2/feedbacks/123
|
@@ -127,7 +128,7 @@ This is especially handy for configuring an endpoint once and generate the url f
|
|
127
128
|
This also works in place without configuring an endpoint.
|
128
129
|
|
129
130
|
```ruby
|
130
|
-
LHC.get('http://datastore/v2/feedbacks
|
131
|
+
LHC.get('http://datastore/v2/feedbacks/{id}', params:{ id: 123 })
|
131
132
|
# GET http://datastore/v2/feedbacks/123
|
132
133
|
```
|
133
134
|
|
@@ -155,7 +156,7 @@ response.data.name # 'unknown'
|
|
155
156
|
|
156
157
|
### Ignore certain errors
|
157
158
|
|
158
|
-
As it's discouraged to rescue errors and then don't handle them (ruby styleguide),
|
159
|
+
As it's discouraged to rescue errors and then don't handle them (ruby styleguide)[https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions],
|
159
160
|
but you often want to continue working with `nil`, LHC provides the `ignored_errors` option.
|
160
161
|
|
161
162
|
Errors listed in this option will not be raised and will leave the `response.body` and `response.data` to stay `nil`.
|
data/docs/configuration.md
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
Configuration
|
2
2
|
===
|
3
3
|
|
4
|
-
## Configure LHC on
|
4
|
+
## Configure LHC on initialization
|
5
5
|
|
6
|
-
If you want to configure LHC on
|
7
|
-
You can use `LHC.configure` to prevent the
|
6
|
+
If you want to configure LHC on initialization (like in a Rails initializer, `environment.rb` or `application.rb`), you could run into the problem that certain configurations can only be set once.
|
7
|
+
You can use `LHC.configure` to prevent the initialization problem.
|
8
8
|
Take care that you only use `LHC.configure` once, because it is actually reseting previously made configurations and applies the new once.
|
9
9
|
|
10
10
|
```ruby
|
11
11
|
|
12
12
|
LHC.configure do |c|
|
13
13
|
c.placeholder :datastore, 'http://datastore/v2'
|
14
|
-
c.endpoint :feedbacks, '
|
14
|
+
c.endpoint :feedbacks, '{+datastore}/feedbacks'
|
15
15
|
c.interceptors = [CachingInterceptor, MonitorInterceptor, TrackingIdInterceptor]
|
16
16
|
end
|
17
17
|
|
@@ -41,7 +41,7 @@ You can configure global placeholders, that are used when generating urls from u
|
|
41
41
|
```ruby
|
42
42
|
LHC.config.placeholder(:datastore, 'http://datastore/v2')
|
43
43
|
options = { params: { has_reviews: true } }
|
44
|
-
LHC.config.endpoint(:feedbacks,
|
44
|
+
LHC.config.endpoint(:feedbacks, '{+datastore}/feedbacks', options)
|
45
45
|
LHC.get(:feedbacks)
|
46
46
|
```
|
47
47
|
|
data/docs/exceptions.md
CHANGED
@@ -26,7 +26,7 @@ rescue => e
|
|
26
26
|
```
|
27
27
|
|
28
28
|
All errors that are raise by LHC inherit from `LHC::Error`.
|
29
|
-
They are divided into `LHC::ClientError`, `LHC::ServerError`, `LHC::Timeout` and `LHC::UnkownError` and mapped
|
29
|
+
They are divided into `LHC::ClientError`, `LHC::ServerError`, `LHC::Timeout` and `LHC::UnkownError` and mapped according to the following status code.
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
400 => LHC::BadRequest
|
data/docs/interceptors.md
CHANGED
@@ -64,7 +64,7 @@ You can override the global default interceptors on request level:
|
|
64
64
|
## Provide Response
|
65
65
|
|
66
66
|
Inside an interceptor, you are able to provide a response, rather then doing a real request.
|
67
|
-
This is
|
67
|
+
This is useful for implementing an interceptor for caching.
|
68
68
|
|
69
69
|
```ruby
|
70
70
|
class LHC::Cache < LHC::Interceptor
|
@@ -13,6 +13,6 @@ Logs basic request/response information to prometheus.
|
|
13
13
|
LHC.get('http://local.ch')
|
14
14
|
```
|
15
15
|
|
16
|
-
- Creates a
|
16
|
+
- Creates a prometheus counter that receives additional meta information for: `:code`, `:success` and `:timeout`.
|
17
17
|
|
18
|
-
- Creates a
|
18
|
+
- Creates a prometheus histogram for response times in milliseconds.
|
data/docs/interceptors/retry.md
CHANGED
data/lhc.gemspec
CHANGED
data/lib/lhc/endpoint.rb
CHANGED
@@ -1,13 +1,8 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'addressable/template'
|
2
|
+
|
3
3
|
# An endpoint is an url that leads to a backend resource.
|
4
|
-
# The url can also be an url-template.
|
4
|
+
# The url can also be an url-template (https://tools.ietf.org/html/rfc6570).
|
5
5
|
class LHC::Endpoint
|
6
|
-
|
7
|
-
PLACEHOLDER ||= %r{:[^\/\.:;\d\&@]+}
|
8
|
-
ANYTHING_BUT_SINGLE_SLASH_AND_DOT ||= '([^\/\.]|\/\/)+'.freeze
|
9
|
-
URL_PARAMETERS ||= '(\\?.*)*'
|
10
|
-
|
11
6
|
attr_accessor :url, :options
|
12
7
|
|
13
8
|
def initialize(url, options = nil)
|
@@ -16,41 +11,19 @@ class LHC::Endpoint
|
|
16
11
|
end
|
17
12
|
|
18
13
|
def uri
|
19
|
-
@uri ||=
|
20
|
-
end
|
21
|
-
|
22
|
-
def parse_url_gracefully(url)
|
23
|
-
URI.parse(url)
|
24
|
-
rescue URI::InvalidURIError
|
25
|
-
url
|
14
|
+
@uri ||= Addressable::Template.new(url)
|
26
15
|
end
|
27
16
|
|
28
17
|
def compile(params)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
if params.is_a? Proc
|
33
|
-
params.call(match)
|
34
|
-
else
|
35
|
-
find_value(match, params)
|
36
|
-
end
|
37
|
-
replacement || fail("Compilation incomplete. Unable to find value for #{match.gsub(':', '')}.")
|
38
|
-
end
|
39
|
-
)
|
40
|
-
end
|
41
|
-
|
42
|
-
def add_basic_auth(url)
|
43
|
-
return url if !uri || !uri.is_a?(URI) || (uri.user.blank? && uri.password.blank?)
|
44
|
-
new_uri = parse_url_gracefully(url)
|
45
|
-
new_uri.user = uri.user
|
46
|
-
new_uri.password = uri.password
|
47
|
-
new_uri.to_s
|
48
|
-
end
|
18
|
+
context = LHC.config.placeholders.deep_dup
|
19
|
+
context.merge!(params) if params.is_a?(Hash)
|
20
|
+
expanded = uri.partial_expand(context)
|
49
21
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
22
|
+
if expanded.variables.empty?
|
23
|
+
expanded.pattern
|
24
|
+
else
|
25
|
+
fail("Compilation incomplete. Unable to find value for #{expanded.variables.join(', ')}.")
|
26
|
+
end
|
54
27
|
end
|
55
28
|
|
56
29
|
# Endpoint options are immutable
|
@@ -62,62 +35,79 @@ class LHC::Endpoint
|
|
62
35
|
# when they are used for interpolation.
|
63
36
|
def remove_interpolated_params!(params)
|
64
37
|
params ||= {}
|
65
|
-
removed =
|
66
|
-
|
67
|
-
|
68
|
-
value = find_value(match, params)
|
69
|
-
if value
|
70
|
-
removed[match.to_sym] = value
|
71
|
-
params.delete(match.to_sym)
|
72
|
-
end
|
73
|
-
end
|
38
|
+
removed = params.slice(*placeholders)
|
39
|
+
params.except!(*placeholders)
|
40
|
+
|
74
41
|
removed
|
75
42
|
end
|
76
43
|
|
77
44
|
# Returns all placeholders found in the url-template.
|
78
45
|
# They are alphabetically sorted.
|
79
46
|
def placeholders
|
80
|
-
|
47
|
+
uri.variables.sort.map(&:to_sym)
|
81
48
|
end
|
82
49
|
|
83
|
-
#
|
84
|
-
#
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
50
|
+
# Compares a concrete url with a template
|
51
|
+
# Returns true if concrete url is covered by the template
|
52
|
+
# Example: {+datastore}/contracts/{id} == http://local.ch/contracts/1
|
53
|
+
def match?(url)
|
54
|
+
return true if url == uri.pattern
|
55
|
+
match_data = match_data(url)
|
56
|
+
return false if match_data.nil?
|
57
|
+
|
58
|
+
match_data.values.all? { |value| valid_value?(value) }
|
59
|
+
end
|
60
|
+
|
61
|
+
# Extracts the values from url and
|
62
|
+
# creates params according to template
|
63
|
+
def values_as_params(url)
|
64
|
+
match_data = match_data(url)
|
65
|
+
return if match_data.nil?
|
66
|
+
Hash[match_data.variables.map(&:to_sym).zip(match_data.values)]
|
67
|
+
end
|
68
|
+
|
69
|
+
# Checks if the name has a match in the current context
|
70
|
+
def find_value(name, mapping)
|
71
|
+
context = LHC.config.placeholders.deep_dup
|
72
|
+
context.merge!(mapping)
|
73
|
+
|
74
|
+
context[name]
|
89
75
|
end
|
90
76
|
|
91
77
|
# Compares a concrete url with a template
|
92
78
|
# Returns true if concrete url is covered by the template
|
93
|
-
# Example:
|
79
|
+
# Example: {+datastore}/contracts/{id} == http://local.ch/contracts/1
|
94
80
|
def self.match?(url, template)
|
95
|
-
|
96
|
-
regexp += URL_PARAMETERS
|
97
|
-
url.match "#{regexp}$"
|
81
|
+
new(template).match?(url)
|
98
82
|
end
|
99
83
|
|
100
84
|
# Returns all placeholders found in the url-template.
|
101
85
|
# They are alphabetically sorted.
|
102
86
|
def self.placeholders(template)
|
103
|
-
template
|
87
|
+
new(template).placeholders
|
104
88
|
end
|
105
89
|
|
106
90
|
# Extracts the values from url and
|
107
91
|
# creates params according to template
|
108
92
|
def self.values_as_params(template, url)
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
93
|
+
fail("#{url} does not match the template: #{template}") if !match?(url, template)
|
94
|
+
new(template).values_as_params(url)
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
# Ensure there are no false positives in the template matching
|
100
|
+
def valid_value?(value)
|
101
|
+
value.match(%{https?:/$}).nil? &&
|
102
|
+
value.match(/.*\.json/).nil?
|
103
|
+
end
|
104
|
+
|
105
|
+
def match_data(url)
|
106
|
+
parsed = URI.parse(url)
|
107
|
+
parsed.query = parsed.fragment = nil
|
108
|
+
|
109
|
+
uri.match(parsed)
|
110
|
+
rescue URI::InvalidURIError
|
111
|
+
nil
|
122
112
|
end
|
123
113
|
end
|
data/lib/lhc/version.rb
CHANGED
@@ -16,7 +16,7 @@ describe LHC do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'does a get request when providing the name of a configured endpoint' do
|
19
|
-
url = 'http
|
19
|
+
url = 'http://{+datastore}/v2/feedbacks'
|
20
20
|
options = { params: { datastore: 'datastore' } }
|
21
21
|
LHC.configure { |c| c.endpoint(:feedbacks, url, options) }
|
22
22
|
LHC.get(:feedbacks, params: parameters)
|
@@ -21,7 +21,7 @@ describe LHC do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'does a post request when providing the name of a configured endpoint' do
|
24
|
-
url = 'http
|
24
|
+
url = 'http://{+datastore}/v2/feedbacks'
|
25
25
|
options = { params: { datastore: 'datastore' } }
|
26
26
|
LHC.configure { |c| c.endpoint(:feedbacks, url, options) }
|
27
27
|
LHC.post(:feedbacks, body: feedback.to_json)
|
@@ -27,7 +27,7 @@ describe LHC do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'does a post request when providing the name of a configured endpoint' do
|
30
|
-
url = 'http
|
30
|
+
url = 'http://{+datastore}/v2/feedbacks'
|
31
31
|
options = { params: { datastore: 'datastore' } }
|
32
32
|
LHC.configure { |c| c.endpoint(:feedbacks, url, options) }
|
33
33
|
LHC.put(:feedbacks, body: change.to_json)
|
@@ -5,13 +5,13 @@ describe LHC do
|
|
5
5
|
it 'uses values for placeholders defined globally' do
|
6
6
|
LHC.configure { |c| c.placeholder(:datastore, 'http://datastore/v2') }
|
7
7
|
stub_request(:get, "http://datastore/v2/feedbacks")
|
8
|
-
LHC.get('
|
8
|
+
LHC.get('{+datastore}/feedbacks')
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'uses explicit values first' do
|
12
12
|
LHC.configure { |c| c.placeholder(:campaign_id, '123') }
|
13
13
|
stub_request(:get, 'http://datastore/v2/campaign/456/feedbacks')
|
14
|
-
url = 'http://datastore/v2/campaign
|
14
|
+
url = 'http://datastore/v2/campaign/{campaign_id}/feedbacks'
|
15
15
|
LHC.get(url, params: { campaign_id: '456' })
|
16
16
|
end
|
17
17
|
|
@@ -3,39 +3,28 @@ require 'rails_helper'
|
|
3
3
|
describe LHC::Endpoint do
|
4
4
|
context 'compile' do
|
5
5
|
it 'uses parameters for interpolation' do
|
6
|
-
endpoint = LHC::Endpoint.new('
|
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
|
-
it 'uses provided proc to find values' do
|
13
|
-
endpoint = LHC::Endpoint.new(':datastore/v2')
|
14
|
-
config = { datastore: 'http://datastore' }
|
15
|
-
find_value = lambda { |match|
|
16
|
-
config[match.gsub(':', '').to_sym]
|
17
|
-
}
|
18
|
-
expect(
|
19
|
-
endpoint.compile(find_value)
|
20
|
-
).to eq "http://datastore/v2"
|
21
|
-
end
|
22
|
-
|
23
12
|
it 'compiles when templates contain dots' do
|
24
|
-
endpoint = LHC::Endpoint.new('
|
13
|
+
endpoint = LHC::Endpoint.new('{+datastore}/entries/{id}.json')
|
25
14
|
expect(
|
26
15
|
endpoint.compile(datastore: 'http://datastore', id: 123)
|
27
16
|
).to eq "http://datastore/entries/123.json"
|
28
17
|
end
|
29
18
|
|
30
19
|
it 'compiles complex urls containing all sort of characters' do
|
31
|
-
endpoint = LHC::Endpoint.new('
|
20
|
+
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
21
|
expect(
|
33
22
|
endpoint.compile(ads: 'http://ads', region_id: 291, lang: 'de', product_type: 'ABC', product: 'xyz', category_id: 312)
|
34
23
|
).to eq 'http://ads/?adrawdata/3.0/1108.1/2844859/0/0/header=yes;cookie=no;adct=204;alias=291deABCxyz;key=cat=312'
|
35
24
|
end
|
36
25
|
|
37
26
|
it 'compiles complex urls containing &' do
|
38
|
-
endpoint = LHC::Endpoint.new('http
|
27
|
+
endpoint = LHC::Endpoint.new('http://{+weather_search_host}/forecast?format=json&period=hour&limit={limit}&areas={+zipcodes}&when={when}')
|
39
28
|
expect(
|
40
29
|
endpoint.compile(weather_search_host: 'weather', limit: 5, zipcodes: [8005, 8004].join(','), when: 'today')
|
41
30
|
).to eq 'http://weather/forecast?format=json&period=hour&limit=5&areas=8005,8004&when=today'
|
data/spec/endpoint/match_spec.rb
CHANGED
@@ -3,35 +3,33 @@ require 'rails_helper'
|
|
3
3
|
describe LHC::Endpoint do
|
4
4
|
context 'match' do
|
5
5
|
context 'matching' do
|
6
|
-
|
7
|
-
{
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}
|
17
|
-
expect(
|
18
|
-
LHC::Endpoint.match?(url, template)
|
19
|
-
).to be, "#{url} should match #{template}!"
|
6
|
+
{
|
7
|
+
'{+datastore}/v2/places' => 'http://local.ch:8082/v2/places',
|
8
|
+
'{+datastore}/v2/places/{id}' => 'http://local.ch:8082/v2/places/ZW9OJyrbt4OZE9ueu80w-A',
|
9
|
+
'{+datastore}/v2/places/{namespace}/{id}' => 'http://local.ch:8082/v2/places/switzerland/ZW9OJyrbt',
|
10
|
+
'{+datastore}/addresses/{id}' => 'http://local.ch/addresses/123',
|
11
|
+
'http://local.ch/addresses/{id}' => 'http://local.ch/addresses/123',
|
12
|
+
'{+datastore}/customers/{id}/addresses' => 'http://local.ch:80/server/rest/v1/customers/123/addresses',
|
13
|
+
'{+datastore}/entries/{id}.json' => 'http://local.ch/entries/123.json',
|
14
|
+
'{+datastore}/places/{place_id}/feedbacks' => 'http://local.ch/places/1/feedbacks?limit=10&offset=0'
|
15
|
+
}.each do |template, url|
|
16
|
+
it "#{url} matches #{template}" do
|
17
|
+
expect(LHC::Endpoint.match?(url, template)).to be
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
22
|
context 'not matching' do
|
25
|
-
|
26
|
-
{
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
23
|
+
{
|
24
|
+
'{+datastore}/v2/places' => 'http://local.ch:8082/v2/places/ZW9OJyrbt4OZE9ueu80w-A',
|
25
|
+
'{+datastore}/{campaign_id}/feedbacks' => 'http://datastore.local.ch/feedbacks',
|
26
|
+
'{+datastore}/customers/{id}' => 'http://local.ch:80/server/rest/v1/customers/123/addresses',
|
27
|
+
'{+datastore}/entries/{id}' => 'http://local.ch/entries/123.json'
|
28
|
+
}.each do |template, url|
|
29
|
+
it "#{url} should not match #{template}" do
|
32
30
|
expect(
|
33
31
|
LHC::Endpoint.match?(url, template)
|
34
|
-
).not_to be
|
32
|
+
).not_to be
|
35
33
|
end
|
36
34
|
end
|
37
35
|
end
|
@@ -3,10 +3,10 @@ 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 = LHC::Endpoint.new('
|
6
|
+
endpoint = LHC::Endpoint.new('{+datastore}/v2/{campaign_id}/feedbacks')
|
7
7
|
expect(
|
8
8
|
endpoint.placeholders
|
9
|
-
).to eq [
|
9
|
+
).to eq [:campaign_id, :datastore]
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'allows basic auth token in url, like used on github' do
|
@@ -7,7 +7,7 @@ describe LHC::Endpoint do
|
|
7
7
|
campaign_id: 'abc',
|
8
8
|
has_reviews: true
|
9
9
|
}
|
10
|
-
endpoint = LHC::Endpoint.new('
|
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')
|
@@ -2,23 +2,27 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
describe LHC::Endpoint do
|
4
4
|
context 'values_as_params' do
|
5
|
-
|
6
|
-
[
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
5
|
+
[
|
6
|
+
['{+datastore}/v2/places', 'http://local.ch:8082/v2/places', {
|
7
|
+
datastore: 'http://local.ch:8082'
|
8
|
+
}],
|
9
|
+
['{+datastore}/v2/places/{id}', 'http://local.ch:8082/v2/places/ZW9OJyrbt4OZE9ueu80w-A', {
|
10
|
+
datastore: 'http://local.ch:8082',
|
11
|
+
id: 'ZW9OJyrbt4OZE9ueu80w-A'
|
12
|
+
}],
|
13
|
+
['{+datastore}/v2/places/{namespace}/{id}', 'http://local.ch:8082/v2/places/switzerland/ZW9OJyrbt', {
|
14
|
+
datastore: 'http://local.ch:8082',
|
15
|
+
namespace: 'switzerland',
|
16
|
+
id: 'ZW9OJyrbt'
|
17
|
+
}]
|
18
|
+
].each do |example|
|
19
|
+
template = example[0]
|
20
|
+
url = example[1]
|
21
|
+
params = example[2]
|
22
|
+
|
23
|
+
it "for the template #{template} it extracts #{params.keys.join(', ')} from the url" do
|
24
|
+
extracted = LHC::Endpoint.values_as_params(template, url)
|
25
|
+
expect(extracted).to eq(params)
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
@@ -2,7 +2,7 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
describe LHC::Request do
|
4
4
|
it 'does not alter the options that where passed' do
|
5
|
-
LHC.configure { |c| c.endpoint(:kpi_tracker, 'http://analytics/track
|
5
|
+
LHC.configure { |c| c.endpoint(:kpi_tracker, 'http://analytics/track/{entity_id}/w', params: { env: 'PROD' }) }
|
6
6
|
options = { params: { entity_id: '123' } }
|
7
7
|
stub_request(:get, "http://analytics/track/123/w?env=PROD")
|
8
8
|
LHC.get(:kpi_tracker, options)
|
@@ -5,7 +5,7 @@ describe LHC::Request do
|
|
5
5
|
options = { params: {
|
6
6
|
has_reviews: true
|
7
7
|
} }
|
8
|
-
url = 'http://datastore/v2/campaign
|
8
|
+
url = 'http://datastore/v2/campaign/{campaign_id}/feedbacks'
|
9
9
|
LHC.configure { |c| c.endpoint(:feedbacks, url, options) }
|
10
10
|
stub_request(:get, 'http://datastore/v2/campaign/123/feedbacks?has_reviews=true')
|
11
11
|
LHC.get(:feedbacks, params: { campaign_id: 123 })
|
@@ -13,11 +13,11 @@ describe LHC::Request do
|
|
13
13
|
|
14
14
|
it 'compiles url when doing a request' do
|
15
15
|
stub_request(:get, 'http://datastore:8080/v2/feedbacks/123')
|
16
|
-
LHC.get('http://datastore:8080/v2/feedbacks
|
16
|
+
LHC.get('http://datastore:8080/v2/feedbacks/{id}', params: { id: 123 })
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'considers body when compiling urls' do
|
20
20
|
stub_request(:post, "http://datastore:8080/v2/places/123")
|
21
|
-
LHC.json.post('http://datastore:8080/v2/places
|
21
|
+
LHC.json.post('http://datastore:8080/v2/places/{id}', body: { id: 123 }.to_json)
|
22
22
|
end
|
23
23
|
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: 7.0.0.beta1
|
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:
|
11
|
+
date: 2018-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '4.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: addressable
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec-rails
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -339,13 +353,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
339
353
|
version: 2.0.0
|
340
354
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
341
355
|
requirements:
|
342
|
-
- - "
|
356
|
+
- - ">"
|
343
357
|
- !ruby/object:Gem::Version
|
344
|
-
version:
|
358
|
+
version: 1.3.1
|
345
359
|
requirements:
|
346
360
|
- Ruby >= 2.0.0
|
347
361
|
rubyforge_project:
|
348
|
-
rubygems_version: 2.6.
|
362
|
+
rubygems_version: 2.6.14
|
349
363
|
signing_key:
|
350
364
|
specification_version: 4
|
351
365
|
summary: LocalHttpClient
|