lhs 10.0.0 → 10.1.0

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: 728cf6034afb426a4b3fb40dd3a8dcdbffd3d004
4
- data.tar.gz: 18872dbdb2fe63ea9b4dc1db69fd370f1499fce3
3
+ metadata.gz: 60b6bf77d4c64a170300990ecc6d783a3a63ddae
4
+ data.tar.gz: 84dbd1de5a4ce2010b04db5af5e75412d34e6823
5
5
  SHA512:
6
- metadata.gz: 5d2733b6ee17ed421ab06af04d65c5bfd09f2cdee35f7fbd82bc04ea59152fb9977100b60a6143fa872a90039b589af19b187da48e2d80d5ccf20202278aa8ce
7
- data.tar.gz: 11e83155ac46883623f321bf12da0357f709fddf3343feb225f2e1af1fadfb4847668f299f921c2a0900ac506c6c1040191f636269c261c3a76ef04acf49927a
6
+ metadata.gz: 2a793212e6532c238884005e278bf02e3c996ea78e3d72cdc007494af88d726e20f007d95e4b0d6f52199833d4e5878543c5eda0210dbae73ba92e5c39441352
7
+ data.tar.gz: e4afed4db96bf107f4a76cb2003679ac2fd27b2c34f11541cfd381ad884f53e4f487b4770d6e0b640c614a2bf27a57c6bb22f120998cb5edbad3579d9e6b7539
data/README.md CHANGED
@@ -77,12 +77,12 @@ Some endpoints could respond a plain list of links without any expanded data. Li
77
77
  If you want to have LHS expand those items, use `expanded` as part of a Query-Chain:
78
78
 
79
79
  ```json
80
- {
80
+ {
81
81
  "items" : [
82
82
  {"href": "http://local.ch/customer/1/accounts/1"},
83
83
  {"href": "http://local.ch/customer/1/accounts/2"},
84
84
  {"href": "http://local.ch/customer/1/accounts/3"}
85
- ]
85
+ ]
86
86
  }
87
87
  end
88
88
  ```
@@ -99,7 +99,7 @@ You can also apply options to `expanded` in order to apply anything on the reque
99
99
 
100
100
  ## Chaining where statements
101
101
 
102
- LHS supports chaining where statements.
102
+ LHS supports chaining where statements.
103
103
  That allows you to chain multiple where-queries:
104
104
 
105
105
  ```ruby
@@ -170,7 +170,12 @@ record = Record.where(color: 'blue')
170
170
 
171
171
  ## Find single records
172
172
 
173
- `find` finds a unique record by uniqe identifier (usualy id).
173
+ `find` finds a unique record by unique identifier (usualy id or href).
174
+
175
+ ```ruby
176
+ Record.find(123)
177
+ Record.find('https://api.example.com/records/123')
178
+ ```
174
179
 
175
180
  If no record is found an error is raised.
176
181
 
@@ -237,14 +242,14 @@ You can apply options to the request chain. Those options will be forwarded to t
237
242
  ```ruby
238
243
  # Authenticate with OAuth
239
244
  options = { auth: { bearer: '123456' } }
240
-
245
+
241
246
  AuthenticatedRecord = Record.options(options)
242
-
247
+
243
248
  blue_records = AuthenticatedRecord.where(color: 'blue')
244
249
  active_records = AuthenticatedRecord.where(active: true)
245
250
 
246
251
  AuthenticatedRecord.create(color: 'red')
247
-
252
+
248
253
  record = AuthenticatedRecord.find(123)
249
254
  # Find resolves the current query and applies all options from the chain
250
255
  # All further requests are made from scratch and not based on the previous options
@@ -316,7 +321,7 @@ See [Validation](#Validation) for handling validation errors when creating recor
316
321
  ```ruby
317
322
  class Review < LHS::Record
318
323
  endpoint ':service/reviews'
319
- end
324
+ end
320
325
 
321
326
  class Comment < LHS::Record
322
327
  endpoint ':service/reviews/:review_id/comments'
@@ -396,7 +401,7 @@ Build and persist new items from scratch are done either with `new` or it's alia
396
401
 
397
402
  ## Custom setters and getters
398
403
 
399
- Sometimes it is the case that you want to have your custom getters and setters and convert the data to a processable format behind the scenes.
404
+ Sometimes it is the case that you want to have your custom getters and setters and convert the data to a processable format behind the scenes.
400
405
  The initializer will now use custom setter if one is defined:
401
406
 
402
407
  ```ruby
@@ -889,9 +894,9 @@ Example.find(1) # GET records/1
889
894
 
890
895
  ## Testing: How to write tests when using LHS
891
896
 
892
- [WebMock](https://github.com/bblimke/webmock)!
897
+ [WebMock](https://github.com/bblimke/webmock)!
893
898
 
894
- Best practice is to let LHS fetch your records and Webmock to stub/mock endpoints responses.
899
+ Best practice is to let LHS fetch your records and Webmock to stub/mock endpoints responses.
895
900
  This follows the [Black Box Testing](https://en.wikipedia.org/wiki/Black-box_testing) approach and prevents you from building up constraints to LHS' internal structures/mechanisms, which will break when we change internal things.
896
901
  LHS provides interfaces that result in HTTP requests, this is what you should test.
897
902
 
@@ -60,12 +60,19 @@ class LHS::Record
60
60
  end
61
61
 
62
62
  def request_options(args, options)
63
+ options ||= {}
63
64
  if args.is_a? Hash
64
- (options || {}).merge(params: args)
65
+ options.merge(params: args)
66
+ elsif href?(args)
67
+ options.merge(url: args)
65
68
  else
66
- (options || {}).merge(params: { id: args })
69
+ options.merge(params: { id: args })
67
70
  end
68
71
  end
72
+
73
+ def href?(str)
74
+ str.is_a?(String) && %r{^https?://}.match(str)
75
+ end
69
76
  end
70
77
  end
71
78
  end
data/lib/lhs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "10.0.0"
2
+ VERSION = "10.1.0"
3
3
  end
@@ -14,12 +14,23 @@ describe LHS::Record do
14
14
  end
15
15
 
16
16
  context 'find' do
17
- it 'finds a single unique record' do
18
- stub_request(:get, "#{datastore}/feedbacks/z12f-3asm3ngals")
19
- .to_return(status: 200, body: load_json(:feedback))
20
- record = Record.find('z12f-3asm3ngals')
21
- expect(record).to be_kind_of Record
22
- expect(record.source_id).to be_kind_of String
17
+ context 'finds a single unique record' do
18
+ before(:each) do
19
+ stub_request(:get, "#{datastore}/feedbacks/z12f-3asm3ngals")
20
+ .to_return(status: 200, body: load_json(:feedback))
21
+ end
22
+
23
+ it 'by id' do
24
+ record = Record.find('z12f-3asm3ngals')
25
+ expect(record).to be_kind_of Record
26
+ expect(record.source_id).to be_kind_of String
27
+ end
28
+
29
+ it 'by href' do
30
+ record = Record.find("#{datastore}/feedbacks/z12f-3asm3ngals")
31
+ expect(record).to be_kind_of Record
32
+ expect(record.source_id).to be_kind_of String
33
+ end
23
34
  end
24
35
 
25
36
  it 'raises if nothing was found' do
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: 10.0.0
4
+ version: 10.1.0
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: 2017-03-06 00:00:00.000000000 Z
11
+ date: 2017-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc
@@ -387,7 +387,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
387
387
  requirements:
388
388
  - Ruby >= 2.0.0
389
389
  rubyforge_project:
390
- rubygems_version: 2.6.8
390
+ rubygems_version: 2.5.1
391
391
  signing_key:
392
392
  specification_version: 4
393
393
  summary: Rails gem providing an easy, active-record-like interface for http json services