api_resource 0.6.20 → 0.6.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/api_resource/associations/association_proxy.rb +14 -1
- data/lib/api_resource/connection.rb +2 -2
- data/lib/api_resource/mocks.rb +38 -38
- data/lib/api_resource/version.rb +1 -1
- data/spec/lib/connection_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36c5282462a20c9ac625c83f0c8b0c4135c459de
|
4
|
+
data.tar.gz: cb4fc1a93be1e17ec2e7eaa78e4e4d9206c79211
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b051f1d5e8e30d08560ce740386431a8ce4afe39927e79e5b2a732fd562bf307f42d08589e86cdb7b32ed2850d2108965297cb657a7096f394042e45f814675e
|
7
|
+
data.tar.gz: a00eb0d1a846aa56090cae8ccbae5874051647dbcb45d71428d744a6270632b7aed705648dbc82cf253b00a01708fdacf76ddc7b3c89c187ce0aaa61f87220c0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
api_resource (0.6.
|
4
|
+
api_resource (0.6.20)
|
5
5
|
activemodel
|
6
6
|
colorize
|
7
7
|
differ
|
@@ -40,7 +40,7 @@ GEM
|
|
40
40
|
activesupport (3.2.10)
|
41
41
|
i18n (~> 0.6)
|
42
42
|
multi_json (~> 1.0)
|
43
|
-
arel (3.0.
|
43
|
+
arel (3.0.2)
|
44
44
|
builder (3.0.4)
|
45
45
|
byebug (2.3.0)
|
46
46
|
columnize (~> 0.3.6)
|
@@ -24,7 +24,13 @@ module ApiResource
|
|
24
24
|
|
25
25
|
id_method_name = self.foreign_key_name(assoc_name)
|
26
26
|
associated_class = opts[:class_name] || assoc_name.to_s.classify
|
27
|
+
remote_proxy = false
|
27
28
|
|
29
|
+
# This is a terrible hack to hold us over until
|
30
|
+
# we have a real association system
|
31
|
+
if self.name.demodulize =~ /RemoteObjectProxy$/
|
32
|
+
remote_proxy = true
|
33
|
+
end
|
28
34
|
# pass this along
|
29
35
|
opts[:name] = assoc_name
|
30
36
|
|
@@ -61,7 +67,14 @@ module ApiResource
|
|
61
67
|
end
|
62
68
|
@attributes_cache[:#{id_method_name}] = val
|
63
69
|
# write_attribute(:#{id_method_name}, val)
|
64
|
-
|
70
|
+
# Active record uses string attributes key
|
71
|
+
# Here's a terrible hack for the time being
|
72
|
+
if #{remote_proxy}
|
73
|
+
@attributes['#{id_method_name}'] = val
|
74
|
+
else
|
75
|
+
# and we use symbol attribute keys
|
76
|
+
@attributes[:#{id_method_name}] = val
|
77
|
+
end
|
65
78
|
end
|
66
79
|
|
67
80
|
EOE
|
@@ -67,12 +67,12 @@ module ApiResource
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def delete(path, headers = self.headers)
|
70
|
-
request(:delete, path, build_request_headers(headers, :delete, self.site.merge(path)))
|
70
|
+
request(:delete, path, {}, build_request_headers(headers, :delete, self.site.merge(path)))
|
71
71
|
return true
|
72
72
|
end
|
73
73
|
|
74
74
|
def head(path, headers = self.headers)
|
75
|
-
request(:head, path, build_request_headers(headers, :head, self.site.merge(path)))
|
75
|
+
request(:head, path, {}, build_request_headers(headers, :head, self.site.merge(path)))
|
76
76
|
end
|
77
77
|
|
78
78
|
# make a put request
|
data/lib/api_resource/mocks.rb
CHANGED
@@ -183,6 +183,10 @@ module ApiResource
|
|
183
183
|
@path, @query = path.split("?")
|
184
184
|
@path, @format = @path.split(".")
|
185
185
|
|
186
|
+
if opts[:body].present? && !opts[:body].is_a?(String)
|
187
|
+
raise "#{opts[:body]} must be passed as a String"
|
188
|
+
end
|
189
|
+
|
186
190
|
# if we have params, it is a MockRequest definition
|
187
191
|
if opts[:params]
|
188
192
|
@params = opts[:params]
|
@@ -245,46 +249,42 @@ module ApiResource
|
|
245
249
|
cattr_accessor :requests
|
246
250
|
self.requests = []
|
247
251
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
#
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
request.params
|
273
|
-
.with_indifferent_access
|
274
|
-
.merge(response[:params].with_indifferent_access)
|
275
|
-
)
|
276
|
-
}
|
277
|
-
else
|
278
|
-
raise ApiResource::ResourceNotFound.new(
|
279
|
-
MockResponse.new({}, {:headers => {"Content-type" => "application/json"}, :status_code => 404}),
|
280
|
-
:message => "\nCould not find a response recorded for \#{request.pretty_inspect}\n" +
|
281
|
-
"Potential Responses Are:\n" +
|
282
|
-
"\#{Array.wrap(Mocks.responses_for_path(request.path)[:responses]).collect(&:first).pretty_inspect}"
|
252
|
+
%w(delete get head post put).each do |method|
|
253
|
+
# def post(path, body, headers)
|
254
|
+
# request = ApiResource::Request.new(:post, path, body, headers)
|
255
|
+
# self.class.requests << request
|
256
|
+
# if response = LifebookerClient::Mocks.find_response(request)
|
257
|
+
# response
|
258
|
+
# else
|
259
|
+
# raise InvalidRequestError.new("Could not find a response
|
260
|
+
# recorded for #{request.to_s} - Responses recorded are: -
|
261
|
+
# #{inspect_responses}")
|
262
|
+
# end
|
263
|
+
# end
|
264
|
+
instance_eval <<-EOE, __FILE__, __LINE__ + 1
|
265
|
+
def #{method}(path, body, headers)
|
266
|
+
opts = {:headers => headers}
|
267
|
+
opts[:body] = body
|
268
|
+
request = MockRequest.new(:#{method}, path, opts)
|
269
|
+
self.requests << request
|
270
|
+
if response = Mocks.find_response(request)
|
271
|
+
response[:response].tap{|resp|
|
272
|
+
resp.generate_response(
|
273
|
+
request.params
|
274
|
+
.with_indifferent_access
|
275
|
+
.merge(response[:params].with_indifferent_access)
|
283
276
|
)
|
284
|
-
|
277
|
+
}
|
278
|
+
else
|
279
|
+
raise ApiResource::ResourceNotFound.new(
|
280
|
+
MockResponse.new({}, {:headers => {"Content-type" => "application/json"}, :status_code => 404}),
|
281
|
+
:message => "\nCould not find a response recorded for \#{request.pretty_inspect}\n" +
|
282
|
+
"Potential Responses Are:\n" +
|
283
|
+
"\#{Array.wrap(Mocks.responses_for_path(request.path)[:responses]).collect(&:first).pretty_inspect}"
|
284
|
+
)
|
285
285
|
end
|
286
|
-
|
287
|
-
|
286
|
+
end
|
287
|
+
EOE
|
288
288
|
end
|
289
289
|
end
|
290
290
|
end
|
data/lib/api_resource/version.rb
CHANGED
data/spec/lib/connection_spec.rb
CHANGED
@@ -26,7 +26,7 @@ describe Connection do
|
|
26
26
|
|
27
27
|
it "should set the Lifebooker-Token if one is present for DELETE requests" do
|
28
28
|
token = Kernel.rand(100000).to_s
|
29
|
-
ApiResource::Mocks::Connection.expects(:delete).with("/test_resources/1.json", {"Accept"=>"application/json", 'Lifebooker-Token' => "#{token}"}).returns(ApiResource::Mocks::MockResponse.new({}))
|
29
|
+
ApiResource::Mocks::Connection.expects(:delete).with("/test_resources/1.json", {}, {"Accept"=>"application/json", 'Lifebooker-Token' => "#{token}"}).returns(ApiResource::Mocks::MockResponse.new({}))
|
30
30
|
|
31
31
|
ApiResource::Base.token = token
|
32
32
|
|
@@ -35,7 +35,7 @@ describe Connection do
|
|
35
35
|
|
36
36
|
it "should set the Lifebooker-Token if one is present for :head requests" do
|
37
37
|
token = Kernel.rand(100000).to_s
|
38
|
-
ApiResource::Mocks::Connection.expects(:head).with("/test_resources/1.json", {"Accept"=>"application/json", 'Lifebooker-Token' => "#{token}"}).returns(ApiResource::Mocks::MockResponse.new({}))
|
38
|
+
ApiResource::Mocks::Connection.expects(:head).with("/test_resources/1.json", {}, {"Accept"=>"application/json", 'Lifebooker-Token' => "#{token}"}).returns(ApiResource::Mocks::MockResponse.new({}))
|
39
39
|
|
40
40
|
ApiResource::Base.token = token
|
41
41
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan Langevin
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-11-
|
13
|
+
date: 2013-11-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|