ddy_remote_resource 0.4.7 → 0.4.8

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: ee1e160b0d79e1f23df3b5f2005f26440bd443c5
4
- data.tar.gz: 85fb186045fd88dadeccd07f349c7695c4338df9
3
+ metadata.gz: 7ce5cc7ceb2e97f6d89d729d698a9aeeea910a00
4
+ data.tar.gz: ab72610052c96c506e621036a9b0a0a95c79123b
5
5
  SHA512:
6
- metadata.gz: 6e50af7d6a5c7049e2067ea0521c8f74030eedbf74644ff254d831b797c923c87c6e2f74c7e968cf2706ac65d86036a9e5ad212eed20d32e79b916cb34e8681a
7
- data.tar.gz: 88f99d3f9c0d5b136095d0baf364017b821b8e8108019d642e8d73c24bc80b5188e5fe470b0236b3e63750a794b2a0b50cf82001c2026f74fda31a029e71b84a
6
+ metadata.gz: ef3676f7fbedebb4b8837ce1eb75460fd308554b342f2948be204a68a9bfdca4660495e6f7bb2c9d52da04456780cc4ac7655b0085d61ec01886020d568813ad
7
+ data.tar.gz: 3591412c2147fa17d98d7ac4b5a5f249cbc4395f9010e4656fa2c1dc324e460e1986446374a504be7a28ed42960014e2b0da7fcb469af8efc55db512a696ddab
@@ -24,6 +24,10 @@ require 'remote_resource/request'
24
24
  module RemoteResource
25
25
  RemoteResourceError = Class.new StandardError
26
26
 
27
+ IdMissingError = Class.new(RemoteResourceError)
28
+
29
+ CollectionOptionKeyError = Class.new(RemoteResourceError)
30
+
27
31
  RESTActionUnknown = Class.new RemoteResourceError # REST action
28
32
 
29
33
  class HTTPError < RemoteResourceError # HTTP errors
@@ -10,6 +10,12 @@ module RemoteResource
10
10
  response = RemoteResource::Request.new(self, :post, attributes, connection_options).perform
11
11
  resource.handle_response response
12
12
  end
13
+
14
+ def destroy(id, connection_options = {})
15
+ resource = new
16
+ response = RemoteResource::Request.new(self, :delete, { id: id }, connection_options).perform
17
+ resource.handle_response(response)
18
+ end
13
19
  end
14
20
 
15
21
  def update_attributes(attributes = {}, connection_options = {})
@@ -33,6 +39,13 @@ module RemoteResource
33
39
  handle_response response
34
40
  end
35
41
 
42
+ def destroy(connection_options = {})
43
+ id.present? || raise(RemoteResource::IdMissingError.new("`id` is missing from resource"))
44
+ response = RemoteResource::Request.new(self, :delete, { id: id }, connection_options).perform
45
+ handle_response(response)
46
+ success? ? self : false
47
+ end
48
+
36
49
  end
37
50
  end
38
- end
51
+ end
@@ -31,6 +31,8 @@ module RemoteResource
31
31
  response = connection.public_send rest_action, determined_request_url, params: determined_params, headers: determined_headers
32
32
  when :put, :patch, :post
33
33
  response = connection.public_send rest_action, determined_request_url, body: determined_attributes, headers: determined_headers
34
+ when :delete
35
+ response = connection.public_send rest_action, determined_request_url, body: determined_attributes, headers: determined_headers
34
36
  else
35
37
  raise RemoteResource::RESTActionUnknown, "for action: '#{rest_action}'"
36
38
  end
@@ -2,7 +2,7 @@ module RemoteResource
2
2
  module REST
3
3
  extend ActiveSupport::Concern
4
4
 
5
- ACTIONS = [:get, :put, :patch, :post]
5
+ ACTIONS = [:get, :put, :patch, :post, :delete]
6
6
 
7
7
  module ClassMethods
8
8
 
@@ -26,4 +26,4 @@ module RemoteResource
26
26
  end
27
27
 
28
28
  end
29
- end
29
+ end
@@ -1,6 +1,5 @@
1
1
  module RemoteResource
2
2
  class UrlNamingDetermination
3
- CollectionOptionKeyError = Class.new(StandardError)
4
3
 
5
4
  attr_reader :resource_klass, :connection_options
6
5
 
@@ -30,7 +29,7 @@ module RemoteResource
30
29
  prefix.gsub(/:\w+/) do |key|
31
30
  value = collection_options.fetch(key[1..-1], nil)
32
31
  if value.nil?
33
- raise(CollectionOptionKeyError, "`collection_prefix` variable `#{key}` is missing from `collection_options`") if check_collection_options
32
+ raise(RemoteResource::CollectionOptionKeyError, "`collection_prefix` variable `#{key}` is missing from `collection_options`") if check_collection_options
34
33
  value = key
35
34
  end
36
35
  URI.parser.escape(value.to_s)
@@ -1,3 +1,3 @@
1
1
  module RemoteResource
2
- VERSION = '0.4.7'
2
+ VERSION = '0.4.8'
3
3
  end
@@ -19,14 +19,14 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.6'
22
- spec.add_development_dependency 'rake'
23
- spec.add_development_dependency 'rspec'
24
- spec.add_development_dependency 'pry'
22
+ spec.add_development_dependency 'rake', '~> 10.4'
23
+ spec.add_development_dependency 'rspec', '~> 3.1'
24
+ spec.add_development_dependency 'pry', '~> 0.10'
25
25
 
26
- spec.add_runtime_dependency 'activesupport'
27
- spec.add_runtime_dependency 'activemodel'
28
- spec.add_runtime_dependency 'virtus'
29
- spec.add_runtime_dependency 'mime-types', '>= 1.16'
30
- spec.add_runtime_dependency 'ethon', '~> 0.7.1'
31
- spec.add_runtime_dependency 'typhoeus'
26
+ spec.add_runtime_dependency 'activesupport', '~> 4.1'
27
+ spec.add_runtime_dependency 'activemodel', '~> 4.1'
28
+ spec.add_runtime_dependency 'virtus', '~> 1.0', '>= 1.0.4'
29
+ spec.add_runtime_dependency 'mime-types', '~> 2.0'
30
+ spec.add_runtime_dependency 'ethon', '~> 0.7', '>= 0.7.1'
31
+ spec.add_runtime_dependency 'typhoeus', '~> 0.7', '>= 0.7.0'
32
32
  end
@@ -46,6 +46,31 @@ describe RemoteResource::Querying::PersistenceMethods do
46
46
  end
47
47
  end
48
48
 
49
+ describe '.destroy' do
50
+ let(:response) { instance_double(RemoteResource::Response) }
51
+
52
+ before do
53
+ allow_any_instance_of(dummy_class).to receive(:handle_response)
54
+ allow_any_instance_of(RemoteResource::Request).to receive(:perform) { response }
55
+ end
56
+
57
+ it 'instantiates the resource without attributes' do
58
+ expect(dummy_class).to receive(:new).with(no_args()).and_call_original
59
+ dummy_class.destroy('15')
60
+ end
61
+
62
+ it 'performs a RemoteResource::Request' do
63
+ expect(RemoteResource::Request).to receive(:new).with(dummy_class, :delete, { id: '15' }, {}).and_call_original
64
+ expect_any_instance_of(RemoteResource::Request).to receive(:perform)
65
+ dummy_class.destroy('15')
66
+ end
67
+
68
+ it 'handles the RemoteResource::Response' do
69
+ expect_any_instance_of(dummy_class).to receive(:handle_response).with response
70
+ dummy_class.destroy('15')
71
+ end
72
+ end
73
+
49
74
  describe '#update_attributes' do
50
75
  let(:dummy) { dummy_class.new id: 10 }
51
76
 
@@ -171,4 +196,51 @@ describe RemoteResource::Querying::PersistenceMethods do
171
196
  end
172
197
  end
173
198
 
174
- end
199
+ describe '#destroy' do
200
+ let(:dummy) { dummy_class.new(id: 18) }
201
+
202
+ let(:response) { instance_double(RemoteResource::Response) }
203
+
204
+ before do
205
+ allow(dummy).to receive(:handle_response) { dummy }
206
+ allow_any_instance_of(RemoteResource::Request).to receive(:perform) { response }
207
+ allow(dummy).to receive(:success?)
208
+ end
209
+
210
+ it 'performs a RemoteResource::Request with rest_action :delete' do
211
+ expect(RemoteResource::Request).to receive(:new).with(dummy, :delete, { id: dummy.id }, {}).and_call_original
212
+ expect_any_instance_of(RemoteResource::Request).to receive(:perform)
213
+ dummy.destroy
214
+ end
215
+
216
+ it 'handles the RemoteResource::Response' do
217
+ expect(dummy).to receive(:handle_response).with response
218
+ dummy.destroy
219
+ end
220
+
221
+ context 'when the destroy was successful' do
222
+ it 'returns the resource' do
223
+ allow(dummy).to receive(:success?) { true }
224
+
225
+ expect(dummy.destroy).to eql dummy
226
+ end
227
+ end
228
+
229
+ context 'when the destroy was NOT successful' do
230
+ it 'returns false' do
231
+ allow(dummy).to receive(:success?) { false }
232
+
233
+ expect(dummy.destroy).to eql false
234
+ end
235
+ end
236
+
237
+ context 'when the id is NOT present' do
238
+ let(:dummy) { dummy_class.new }
239
+
240
+ it 'raises the RemoteResource::IdMissingError error' do
241
+ expect { dummy.destroy }.to raise_error(RemoteResource::IdMissingError, "`id` is missing from resource")
242
+ end
243
+ end
244
+ end
245
+
246
+ end
@@ -271,6 +271,17 @@ describe RemoteResource::Request do
271
271
  it_behaves_like 'a conditional construct for the response'
272
272
  end
273
273
 
274
+ context 'when the rest_action is :delete' do
275
+ let(:rest_action) { 'delete' }
276
+
277
+ it 'makes a DELETE request with the attributes as body' do
278
+ expect(connection).to receive(:delete).with(determined_request_url, body: determined_attributes, headers: determined_headers).and_call_original
279
+ request.perform
280
+ end
281
+
282
+ it_behaves_like 'a conditional construct for the response'
283
+ end
284
+
274
285
  context 'when the rest_action is unknown' do
275
286
  let(:rest_action) { 'foo' }
276
287
 
@@ -352,7 +363,7 @@ describe RemoteResource::Request do
352
363
 
353
364
  context 'when connection_options does NOT include collection_options' do
354
365
  it 'raises error' do
355
- expect{ request.determined_request_url }.to raise_error(RemoteResource::UrlNamingDetermination::CollectionOptionKeyError)
366
+ expect{ request.determined_request_url }.to raise_error(RemoteResource::CollectionOptionKeyError)
356
367
  end
357
368
  end
358
369
  end
@@ -63,6 +63,14 @@ describe RemoteResource::REST do
63
63
  end
64
64
  end
65
65
 
66
+ describe '.delete' do
67
+ it 'performs a RemoteResource::Request with the rest_action :delete' do
68
+ expect(RemoteResource::Request).to receive(:new).with(dummy_class, :delete, attributes, connection_options).and_call_original
69
+ expect_any_instance_of(RemoteResource::Request).to receive(:perform)
70
+ dummy_class.delete(attributes, connection_options)
71
+ end
72
+ end
73
+
66
74
  describe '#get' do
67
75
  it 'performs a RemoteResource::Request with the rest_action :get' do
68
76
  expect(RemoteResource::Request).to receive(:new).with(dummy, :get, params, connection_options).and_call_original
@@ -95,4 +103,12 @@ describe RemoteResource::REST do
95
103
  end
96
104
  end
97
105
 
106
+ describe '#delete' do
107
+ it 'performs a RemoteResource::Request with the rest_action :delete' do
108
+ expect(RemoteResource::Request).to receive(:new).with(dummy, :delete, attributes, connection_options).and_call_original
109
+ expect_any_instance_of(RemoteResource::Request).to receive(:perform)
110
+ dummy.delete(attributes, connection_options)
111
+ end
112
+ end
113
+
98
114
  end
@@ -116,7 +116,7 @@ describe RemoteResource::UrlNamingDetermination do
116
116
 
117
117
  context 'when check_collection_options is true' do
118
118
  it 'raises an exception' do
119
- expect { url_naming_determination.base_url(nil, check_collection_options: true) }.to raise_error(RemoteResource::UrlNamingDetermination::CollectionOptionKeyError)
119
+ expect { url_naming_determination.base_url(nil, check_collection_options: true) }.to raise_error(RemoteResource::CollectionOptionKeyError)
120
120
  end
121
121
  end
122
122
  end
@@ -132,7 +132,7 @@ describe RemoteResource::UrlNamingDetermination do
132
132
 
133
133
  context 'when check_collection_options is true' do
134
134
  it 'raises an exception' do
135
- expect { url_naming_determination.base_url(nil, check_collection_options: true) }.to raise_error(RemoteResource::UrlNamingDetermination::CollectionOptionKeyError)
135
+ expect { url_naming_determination.base_url(nil, check_collection_options: true) }.to raise_error(RemoteResource::CollectionOptionKeyError)
136
136
  end
137
137
  end
138
138
  end
@@ -160,7 +160,7 @@ describe RemoteResource::UrlNamingDetermination do
160
160
 
161
161
  context 'when check_collection_options is true' do
162
162
  it 'raises an exception' do
163
- expect { url_naming_determination.base_url(nil, check_collection_options: true) }.to raise_error(RemoteResource::UrlNamingDetermination::CollectionOptionKeyError)
163
+ expect { url_naming_determination.base_url(nil, check_collection_options: true) }.to raise_error(RemoteResource::CollectionOptionKeyError)
164
164
  end
165
165
  end
166
166
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe RemoteResource::VERSION do
4
4
 
5
- it { should eql '0.4.7' }
5
+ it { should eql '0.4.8' }
6
6
  end
7
7
 
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddy_remote_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan van der Pas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-14 00:00:00.000000000 Z
11
+ date: 2016-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,105 +28,114 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '10.4'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '10.4'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '3.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '0.10'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '0.10'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activesupport
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '4.1'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '4.1'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activemodel
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '4.1'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '4.1'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: virtus
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
101
104
  - - ">="
102
105
  - !ruby/object:Gem::Version
103
- version: '0'
106
+ version: 1.0.4
104
107
  type: :runtime
105
108
  prerelease: false
106
109
  version_requirements: !ruby/object:Gem::Requirement
107
110
  requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '1.0'
108
114
  - - ">="
109
115
  - !ruby/object:Gem::Version
110
- version: '0'
116
+ version: 1.0.4
111
117
  - !ruby/object:Gem::Dependency
112
118
  name: mime-types
113
119
  requirement: !ruby/object:Gem::Requirement
114
120
  requirements:
115
- - - ">="
121
+ - - "~>"
116
122
  - !ruby/object:Gem::Version
117
- version: '1.16'
123
+ version: '2.0'
118
124
  type: :runtime
119
125
  prerelease: false
120
126
  version_requirements: !ruby/object:Gem::Requirement
121
127
  requirements:
122
- - - ">="
128
+ - - "~>"
123
129
  - !ruby/object:Gem::Version
124
- version: '1.16'
130
+ version: '2.0'
125
131
  - !ruby/object:Gem::Dependency
126
132
  name: ethon
127
133
  requirement: !ruby/object:Gem::Requirement
128
134
  requirements:
129
135
  - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '0.7'
138
+ - - ">="
130
139
  - !ruby/object:Gem::Version
131
140
  version: 0.7.1
132
141
  type: :runtime
@@ -134,22 +143,31 @@ dependencies:
134
143
  version_requirements: !ruby/object:Gem::Requirement
135
144
  requirements:
136
145
  - - "~>"
146
+ - !ruby/object:Gem::Version
147
+ version: '0.7'
148
+ - - ">="
137
149
  - !ruby/object:Gem::Version
138
150
  version: 0.7.1
139
151
  - !ruby/object:Gem::Dependency
140
152
  name: typhoeus
141
153
  requirement: !ruby/object:Gem::Requirement
142
154
  requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: '0.7'
143
158
  - - ">="
144
159
  - !ruby/object:Gem::Version
145
- version: '0'
160
+ version: 0.7.0
146
161
  type: :runtime
147
162
  prerelease: false
148
163
  version_requirements: !ruby/object:Gem::Requirement
149
164
  requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '0.7'
150
168
  - - ">="
151
169
  - !ruby/object:Gem::Version
152
- version: '0'
170
+ version: 0.7.0
153
171
  description: RemoteResource, a gem to use resources with REST services. A replacement
154
172
  for ActiveResource gem.
155
173
  email: