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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2af71db2c3a963841ab839ade45d05ebb66d361d
4
- data.tar.gz: 60c676ba2a79c483c9be7e4f9668eeb4e001ef90
3
+ metadata.gz: 36c5282462a20c9ac625c83f0c8b0c4135c459de
4
+ data.tar.gz: cb4fc1a93be1e17ec2e7eaa78e4e4d9206c79211
5
5
  SHA512:
6
- metadata.gz: 1c1ca6670e7d3d8141dec91c9efc617084b8b97bc32f9ea7bde82f7f917fdb457dc99dae65806553a94e291b97e3f5a5186a5f05377d80c32c995c7e1dcc0a3c
7
- data.tar.gz: cef0c28c031cfa715ea50ce1b892aa2e8f05ae0db52ef54eb9a97ef84d406305db60234c72ef8c939f3ae4786c9d48f94f1e8e12fa0d37a676a0b2dd037cf0bb
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.19)
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.3)
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
- @attributes[:#{id_method_name}] = val
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
@@ -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
- # body? methods
249
- { true => %w(post put get),
250
- false => %w(delete head) }.each do |has_body, methods|
251
- methods.each do |method|
252
- # def post(path, body, headers)
253
- # request = ApiResource::Request.new(:post, path, body, headers)
254
- # self.class.requests << request
255
- # if response = LifebookerClient::Mocks.find_response(request)
256
- # response
257
- # else
258
- # raise InvalidRequestError.new("Could not find a response
259
- # recorded for #{request.to_s} - Responses recorded are: -
260
- # #{inspect_responses}")
261
- # end
262
- # end
263
- instance_eval <<-EOE, __FILE__, __LINE__ + 1
264
- def #{method}(path, #{'body, ' if has_body}headers)
265
- opts = {:headers => headers}
266
- #{"opts[:body] = body" if has_body}
267
- request = MockRequest.new(:#{method}, path, opts)
268
- self.requests << request
269
- if response = Mocks.find_response(request)
270
- response[:response].tap{|resp|
271
- resp.generate_response(
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
- end
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
- EOE
287
- end
286
+ end
287
+ EOE
288
288
  end
289
289
  end
290
290
  end
@@ -1,3 +1,3 @@
1
1
  module ApiResource
2
- VERSION = "0.6.20"
2
+ VERSION = "0.6.21"
3
3
  end
@@ -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.20
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-19 00:00:00.000000000 Z
13
+ date: 2013-11-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake