restful_resource 2.2.6 → 2.2.7

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: b0958e356e2525fc286894548cc434ff68486f4c
4
- data.tar.gz: e7ca6b8704b648c7d55482d988fa59ee8ab648a0
3
+ metadata.gz: 9faff51b36ab1690640882d31329a7737aa68f4e
4
+ data.tar.gz: f850d5a2afc9f32bbc18f9673dc82ed9d520ca33
5
5
  SHA512:
6
- metadata.gz: c6bde5bde53b14d936f6afbe2e483fc1a99502f6d6b9f58a19f4e4b2b1e50c532d2aae7367b626a8797355ba1439c69d69bc8789d0ca816c19033e9ee8b78fa4
7
- data.tar.gz: 7ef2459add247da55d390c2c7dc2caac34f6473d9bd53e23f4be19f455daf054d973c0df27651a5713da024ba4edfb775757a7548be3b8b96dfa9271748d2746
6
+ metadata.gz: 137d0b430d88db910b9e6ed5de1c6f00c50e509a94cfc46c51ffd819245cf9103d5bf4e6063e3da7473518927adda7958f056727a2c7c635772e84b5879aa2e9
7
+ data.tar.gz: c03523b7ae7a3763185d484cf0a49f2491cac3cec1862271d7bd5bc1801367ddb8e7a01f3418da3a467b3a5ac19ceac6194afeb57537688b6d99493372c20c03
@@ -8,11 +8,9 @@ module RestfulResource
8
8
  logger: nil,
9
9
  cache_store: nil,
10
10
  instrumentation: {},
11
- context_lambda: nil,
12
11
  faraday_config: nil)
13
12
 
14
13
  @base_url = URI.parse(base_url)
15
- @context_lambda = context_lambda
16
14
 
17
15
  @http = RestfulResource::HttpClient.new(username: username,
18
16
  password: password,
@@ -56,7 +54,7 @@ module RestfulResource
56
54
 
57
55
  def self.put(id, data: {}, headers: {}, **params)
58
56
  params_without_options, options = format_params(params)
59
- headers.merge! options.delete(:headers)
57
+ options.delete(:headers)
60
58
 
61
59
  url = member_url(id, params_without_options)
62
60
 
@@ -66,7 +64,7 @@ module RestfulResource
66
64
 
67
65
  def self.post(data: {}, headers: {}, **params)
68
66
  params_without_options, options = format_params(params)
69
- headers.merge! options.delete(:headers)
67
+ options.delete(:headers)
70
68
 
71
69
  url = collection_url(params_without_options)
72
70
 
@@ -121,18 +119,12 @@ module RestfulResource
121
119
  replace_parameters(url, params)
122
120
  end
123
121
 
124
- def self.context_lambda
125
- superclass.instance_variable_get :@context_lambda
126
- end
127
-
128
122
  private
129
123
 
130
124
  def self.format_params(params = {})
131
125
  headers = params.delete(:headers) || {}
132
126
 
133
127
  headers.merge!(cache_control: 'no-cache') if params.delete(:no_cache)
134
- headers.merge!(context_headers) if self.context_lambda
135
-
136
128
  open_timeout = params.delete(:open_timeout)
137
129
  timeout = params.delete(:timeout)
138
130
 
@@ -192,12 +184,5 @@ module RestfulResource
192
184
  array = parse_json(response.body).map { |attributes| self.new(attributes) }
193
185
  PaginatedArray.new(array, previous_page_url: prev_url, next_page_url: next_url, total_count: response.headers[:x_total_count])
194
186
  end
195
-
196
- def self.context_headers
197
- self
198
- .context_lambda
199
- .call
200
- .select { |k,_| k.to_s.start_with?('source_') }
201
- end
202
187
  end
203
188
  end
@@ -1,3 +1,3 @@
1
1
  module RestfulResource
2
- VERSION = '2.2.6'
2
+ VERSION = '2.2.7'
3
3
  end
@@ -65,32 +65,6 @@ RSpec.describe RestfulResource::Base do
65
65
 
66
66
  Make.find(12, no_cache: true)
67
67
  end
68
-
69
- it 'skips context headers when context_lambda is not set' do
70
- expect_get("http://api.carwow.co.uk/makes/12",
71
- RestfulResource::Response.new,
72
- headers: { cache_control: 'no-cache' })
73
-
74
- expect(RestfulResource::Base).to receive(:context_lambda).and_return(nil)
75
-
76
- Make.find(12, no_cache: true)
77
- end
78
-
79
- it 'adds context headers when context_lambda is set' do
80
- expect_get("http://api.carwow.co.uk/makes/12",
81
- RestfulResource::Response.new,
82
- headers: {
83
- cache_control: 'no-cache',
84
- source_type: 'controller',
85
- source_class: 'SomeController',
86
- source_identifier: 'index',
87
- }
88
- )
89
-
90
- expect(RestfulResource::Base).to receive(:context_lambda).and_return(context_lambda).twice
91
-
92
- Make.find(12, no_cache: true)
93
- end
94
68
  end
95
69
 
96
70
  describe "#where" do
@@ -132,32 +106,6 @@ RSpec.describe RestfulResource::Base do
132
106
 
133
107
  Model.where(make_slug: 'Volkswagen', on_sale: true, group_id: 15, no_cache: true)
134
108
  end
135
-
136
- it 'skips context headers when context_lambda is not set' do
137
- expect_get("http://api.carwow.co.uk/groups/15/makes/Volkswagen/models?on_sale=true",
138
- RestfulResource::Response.new,
139
- headers: { cache_control: 'no-cache' })
140
-
141
- expect(RestfulResource::Base).to receive(:context_lambda).and_return(nil)
142
-
143
- Model.where(make_slug: 'Volkswagen', on_sale: true, group_id: 15, no_cache: true)
144
- end
145
-
146
- it 'adds context headers when context_lambda is set' do
147
- expect_get("http://api.carwow.co.uk/groups/15/makes/Volkswagen/models?on_sale=true",
148
- RestfulResource::Response.new,
149
- headers: {
150
- cache_control: 'no-cache',
151
- source_type: 'controller',
152
- source_class: 'SomeController',
153
- source_identifier: 'index',
154
- }
155
- )
156
-
157
- expect(RestfulResource::Base).to receive(:context_lambda).and_return(context_lambda).twice
158
-
159
- Model.where(make_slug: 'Volkswagen', on_sale: true, group_id: 15, no_cache: true)
160
- end
161
109
  end
162
110
 
163
111
  describe "#all" do
@@ -186,32 +134,6 @@ RSpec.describe RestfulResource::Base do
186
134
 
187
135
  Make.all(no_cache: true)
188
136
  end
189
-
190
- it 'skips context headers when context_lambda is not set' do
191
- expect_get("http://api.carwow.co.uk/makes",
192
- RestfulResource::Response.new,
193
- headers: { cache_control: 'no-cache' })
194
-
195
- expect(RestfulResource::Base).to receive(:context_lambda).and_return(nil)
196
-
197
- Make.all(no_cache: true)
198
- end
199
-
200
- it 'adds context headers when context_lambda is set' do
201
- expect_get("http://api.carwow.co.uk/makes",
202
- RestfulResource::Response.new,
203
- headers: {
204
- cache_control: 'no-cache',
205
- source_type: 'controller',
206
- source_class: 'SomeController',
207
- source_identifier: 'index',
208
- }
209
- )
210
-
211
- expect(RestfulResource::Base).to receive(:context_lambda).and_return(context_lambda).twice
212
-
213
- Make.all(no_cache: true)
214
- end
215
137
  end
216
138
 
217
139
  describe "#base_url" do
@@ -272,32 +194,6 @@ RSpec.describe RestfulResource::Base do
272
194
 
273
195
  Make.action(:average_score).get(no_cache: true)
274
196
  end
275
-
276
- it 'skips context headers when context_lambda is not set' do
277
- expect_get("http://api.carwow.co.uk/makes/average_score",
278
- RestfulResource::Response.new,
279
- headers: { cache_control: 'no-cache' })
280
-
281
- expect(RestfulResource::Base).to receive(:context_lambda).and_return(nil)
282
-
283
- Make.action(:average_score).get(no_cache: true)
284
- end
285
-
286
- it 'adds context headers when context_lambda is set' do
287
- expect_get("http://api.carwow.co.uk/makes/average_score",
288
- RestfulResource::Response.new,
289
- headers: {
290
- cache_control: 'no-cache',
291
- source_type: 'controller',
292
- source_class: 'SomeController',
293
- source_identifier: 'index',
294
- }
295
- )
296
-
297
- expect(RestfulResource::Base).to receive(:context_lambda).and_return(context_lambda).twice
298
-
299
- Make.action(:average_score).get(no_cache: true)
300
- end
301
197
  end
302
198
 
303
199
  describe "#put" do
@@ -348,32 +244,6 @@ RSpec.describe RestfulResource::Base do
348
244
 
349
245
  Make.put(1, data: {}, headers: { accept: 'application/json' })
350
246
  end
351
-
352
- it 'skips context headers when context_lambda is not set' do
353
- expect_put("http://api.carwow.co.uk/makes/1",
354
- RestfulResource::Response.new,
355
- headers: { accept: 'application/json' })
356
-
357
- expect(RestfulResource::Base).to receive(:context_lambda).and_return(nil)
358
-
359
- Make.put(1, data: {}, headers: { accept: 'application/json' })
360
- end
361
-
362
- it 'adds context headers when context_lambda is set' do
363
- expect_put("http://api.carwow.co.uk/makes/1",
364
- RestfulResource::Response.new,
365
- headers: {
366
- accept: 'application/json',
367
- source_type: 'controller',
368
- source_class: 'SomeController',
369
- source_identifier: 'index',
370
- }
371
- )
372
-
373
- expect(RestfulResource::Base).to receive(:context_lambda).and_return(context_lambda).twice
374
-
375
- Make.put(1, data: {}, headers: { accept: 'application/json' })
376
- end
377
247
  end
378
248
 
379
249
  describe "#post" do
@@ -396,32 +266,6 @@ RSpec.describe RestfulResource::Base do
396
266
 
397
267
  Make.post(data: {}, headers: { accept: 'application/json' })
398
268
  end
399
-
400
- it 'skips context headers when context_lambda is not set' do
401
- expect_post("http://api.carwow.co.uk/makes",
402
- RestfulResource::Response.new,
403
- headers: { accept: 'application/json' })
404
-
405
- expect(RestfulResource::Base).to receive(:context_lambda).and_return(nil)
406
-
407
- Make.post(data: {}, headers: { accept: 'application/json' })
408
- end
409
-
410
- it 'adds context headers when context_lambda is set' do
411
- expect_post("http://api.carwow.co.uk/makes",
412
- RestfulResource::Response.new,
413
- headers: {
414
- accept: 'application/json',
415
- source_type: 'controller',
416
- source_class: 'SomeController',
417
- source_identifier: 'index',
418
- }
419
- )
420
-
421
- expect(RestfulResource::Base).to receive(:context_lambda).and_return(context_lambda).twice
422
-
423
- Make.post(data: {}, headers: { accept: 'application/json' })
424
- end
425
269
  end
426
270
 
427
271
  describe "#delete" do
@@ -441,32 +285,6 @@ RSpec.describe RestfulResource::Base do
441
285
 
442
286
  Make.delete(1, headers: { accept: 'application/json' })
443
287
  end
444
-
445
- it 'skips context headers when context_lambda is not set' do
446
- expect_delete("http://api.carwow.co.uk/makes/1",
447
- RestfulResource::Response.new,
448
- headers: { accept: 'application/json' })
449
-
450
- expect(RestfulResource::Base).to receive(:context_lambda).and_return(nil)
451
-
452
- Make.delete(1, headers: { accept: 'application/json' })
453
- end
454
-
455
- it 'adds context headers when context_lambda is set' do
456
- expect_delete("http://api.carwow.co.uk/makes/1",
457
- RestfulResource::Response.new,
458
- headers: {
459
- accept: 'application/json',
460
- source_type: 'controller',
461
- source_class: 'SomeController',
462
- source_identifier: 'index',
463
- }
464
- )
465
-
466
- expect(RestfulResource::Base).to receive(:context_lambda).and_return(context_lambda).twice
467
-
468
- Make.delete(1, headers: { accept: 'application/json' })
469
- end
470
288
  end
471
289
 
472
290
  describe ".as_json" do
@@ -516,43 +334,6 @@ RSpec.describe RestfulResource::Base do
516
334
  instrumentation: instrumentation,
517
335
  faraday_config: faraday_config)
518
336
  end
519
-
520
- it "stores a lambda when it is defined" do
521
- a_lambda = lambda { {context: 'info'} }
522
-
523
- RestfulResource::Base.configure(base_url: 'http://foo.bar',
524
- instrumentation: {context_lambda: a_lambda})
525
-
526
- RestfulResource::Base.instance_variable_get(:@context_lambda).equal?(a_lambda)
527
- end
528
- end
529
-
530
- describe ".context_headers" do
531
- it "builds headers from keys in context_lambda starting with 'source_' only" do
532
- a_lambda = context_lambda(
533
- source_present: 'value',
534
- random_key: 'should not be present'
535
- )
536
-
537
- expect(RestfulResource::Base).to receive(:context_lambda).and_return(a_lambda)
538
-
539
- expect(RestfulResource::Base.context_headers).to eq(
540
- source_type: 'controller',
541
- source_class: 'SomeController',
542
- source_identifier: 'index',
543
- source_present: 'value'
544
- )
545
- end
546
- end
547
-
548
- def context_lambda(args = {})
549
- lambda do
550
- {
551
- source_type: 'controller',
552
- source_class: 'SomeController',
553
- source_identifier: 'index',
554
- }.merge(args)
555
- end
556
337
  end
557
338
 
558
339
  def response_with_page_information
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.6
4
+ version: 2.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Santoro
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-05-21 00:00:00.000000000 Z
12
+ date: 2018-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -258,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  version: '0'
259
259
  requirements: []
260
260
  rubyforge_project:
261
- rubygems_version: 2.5.2
261
+ rubygems_version: 2.6.14.1
262
262
  signing_key:
263
263
  specification_version: 4
264
264
  summary: A simple activerecord inspired rest resource base class implemented using