lhs 5.6.2 → 5.6.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 +4 -4
- data/README.md +12 -0
- data/lib/lhs/concerns/item/validation.rb +14 -3
- data/lib/lhs/version.rb +1 -1
- data/spec/item/validation_spec.rb +18 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34f496f9c15ded84fe153a6c53a61a726046e070
|
4
|
+
data.tar.gz: 241dbdff9b5b737d9476816e07de14da3a32050a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75566527a546a2891143b5c1c5caf21f78a0f85e87aab6568bbd8600c4ed799c022cb964436a885158384f1533cb20e1e79cc27c43948164e504e05ec95db519
|
7
|
+
data.tar.gz: a380b71d2751fb01a0a5fe7ec1364b11409a6ad7dc4df102a3f969902d69ab5015057030ca62f0873b5d151449d6b873f3e1b6c4b504ef9a330696bb01224ff3
|
data/README.md
CHANGED
@@ -38,6 +38,9 @@ class Feedback < LHS::Record
|
|
38
38
|
end
|
39
39
|
```
|
40
40
|
|
41
|
+
Please use placeholders when configuring endpoints also for hosts. Otherwise LHS will match them strictly, which can result in problems when mixing URLs containing `http`, `https` or no protocol at all.
|
42
|
+
[https://github.com/local-ch/lhc/blob/master/docs/configuration.md#placeholders](LHC Placeholder Configuration)
|
43
|
+
|
41
44
|
If you try to setup a LHS::Record with clashing endpoints it will immediately raise an exception.
|
42
45
|
|
43
46
|
```ruby
|
@@ -479,6 +482,15 @@ unless user.valid?
|
|
479
482
|
end
|
480
483
|
```
|
481
484
|
|
485
|
+
In case endpoints define other parameter names for validation like `publish` you can configure those with passing a string to `validates`:
|
486
|
+
|
487
|
+
```ruby
|
488
|
+
class User < LHS::Record
|
489
|
+
endpoint ':datastore/v2/users', validates: 'publish'
|
490
|
+
end
|
491
|
+
```
|
492
|
+
|
493
|
+
|
482
494
|
## Pagination
|
483
495
|
|
484
496
|
LHS supports paginated APIs and it also supports various pagination strategies and by providing configuration possibilities.
|
@@ -11,7 +11,9 @@ class LHS::Item < LHS::Proxy
|
|
11
11
|
fail 'No validation endpoint found!' unless validation_endpoint
|
12
12
|
record = LHS::Record.for_url(validation_endpoint.url)
|
13
13
|
validation_params = validation_endpoint.options[:validates] == true ? { persist: false } : { validation_endpoint.options[:validates] => false }
|
14
|
-
params = validation_endpoint.options.fetch(:params, {})
|
14
|
+
params = validation_endpoint.options.fetch(:params, {})
|
15
|
+
.merge(params_from_embeded_href)
|
16
|
+
.merge(validation_params)
|
15
17
|
begin
|
16
18
|
record.request(
|
17
19
|
options.merge(
|
@@ -33,11 +35,20 @@ class LHS::Item < LHS::Proxy
|
|
33
35
|
private
|
34
36
|
|
35
37
|
def validation_endpoint
|
36
|
-
endpoint = _data.
|
37
|
-
endpoint ||=
|
38
|
+
endpoint = embeded_endpoint if _data.href # take embeded first
|
39
|
+
endpoint ||= _data._record.find_endpoint(_data._raw)
|
38
40
|
validates = endpoint.options && endpoint.options.fetch(:validates, false)
|
39
41
|
fail 'Endpoint does not support validations!' unless validates
|
40
42
|
endpoint
|
41
43
|
end
|
44
|
+
|
45
|
+
def embeded_endpoint
|
46
|
+
LHS::Endpoint.for_url(_data.href)
|
47
|
+
end
|
48
|
+
|
49
|
+
def params_from_embeded_href
|
50
|
+
return {} if !_data.href || !embeded_endpoint
|
51
|
+
LHC::Endpoint.values_as_params(embeded_endpoint.url, _data.href)
|
52
|
+
end
|
42
53
|
end
|
43
54
|
end
|
data/lib/lhs/version.rb
CHANGED
@@ -108,4 +108,22 @@ describe LHS::Item do
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
111
|
+
|
112
|
+
context 'pick right endpoint' do
|
113
|
+
before(:each) do
|
114
|
+
class Record < LHS::Record
|
115
|
+
endpoint 'http://datastore/v2/records'
|
116
|
+
endpoint 'http://datastore/v2/records/:id', validates: true
|
117
|
+
end
|
118
|
+
stub_request(:get, "http://datastore/v2/records/1")
|
119
|
+
.to_return(body: { href: 'http://datastore/v2/records/1' }.to_json)
|
120
|
+
stub_request(:post, "http://datastore/v2/records/1?persist=false")
|
121
|
+
.to_return(body: {}.to_json)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'takes the right endpoint for validation' do
|
125
|
+
record = Record.find(1)
|
126
|
+
record.valid?
|
127
|
+
end
|
128
|
+
end
|
111
129
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.6.
|
4
|
+
version: 5.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -344,7 +344,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
344
344
|
requirements:
|
345
345
|
- Ruby >= 1.9.2
|
346
346
|
rubyforge_project:
|
347
|
-
rubygems_version: 2.2.
|
347
|
+
rubygems_version: 2.2.2
|
348
348
|
signing_key:
|
349
349
|
specification_version: 4
|
350
350
|
summary: Rails gem providing an easy, active-record-like interface for http json services
|