shutl_resource 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzAyN2EwMWRhNjYwOWUxYjIzNWYwZWY0ZDcyZWI4YTlhOWVlNDZhZA==
4
+ MzQzZjljYzZjYmY0MjVkMmEzZTFmODIyMDU2N2UyMzQwN2I3YmVkOA==
5
5
  data.tar.gz: !binary |-
6
- ZmQ3MGQ0ZTY2MWFjNGYzMjlmM2FjMjg0ZjAxYTE2ZjM5ZDYxZDM0Mg==
6
+ ZDRmODZkZTMxMWI1MjA5NWUxMzEwN2U4ZDRjODE3OGIyOWZjMGYxZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTIzN2YyYzI0ZWU4YTNhYWZlYzc0ZTU1MDE2MGQ3MDkzYjk5MzM2ZDVhNjNm
10
- ZGM2MWNlNzRjZGQ4YmQzNWRlOGQ3ZDgyZWFhNTE1YmNkMTk5MTY5YjY0ZDgw
11
- MTY2OTQyZDJhNzI3YjdkY2E0ODhlYWRlMmZjYjU0MDE3N2Y0ZjE=
9
+ ZTgwMDY2ODUyN2E4ZGM1Y2ZkNGRjNGRkYzcxNmM4ZTAwMDRmYjhlMDI4OWUz
10
+ MmRjMDc3MGYyMzFhN2I3ZWVlOTkzYmFlNTQ1NDZjNjc3NjQ3ZWEyNzk3ZWNh
11
+ ZTEwYjdhNDc2OTgwMTkxOGRiNDAwYmJlYjhlZjkwOTY5NWYwZjY=
12
12
  data.tar.gz: !binary |-
13
- NmQwYWY0MWJkMGEzZjcxYWI5NjNlMjEzNDdiMThmNGU1N2IxODYzZGY1ZTRl
14
- NDhjZmE1NmYwOTI0YzFjZDlmMWVhOTJhOWM2ZTFjYzYyOGIzNjM1ZGZjMzUw
15
- MTQzOTQxYWY1MzQwMmI5ZGZkY2YyNjMwMzAxYTIyODdiMTBiMzE=
13
+ OGZhMDY5NDZkMDA2MDAzMDAyNTBiYTIzZWQyZGFiZWM1N2QyZTY1MzQzNDI5
14
+ OTZjOWE0Mjg4N2I5NjNjNTM2ZjYyNGExODcxZGQ1OTExNzU2NThlNWJjYmVk
15
+ Zjk1MTY0NGNhMDhjM2QyYTkwYWI2NTQ5Y2JkZTdlOGU1YTk5MjE=
@@ -23,26 +23,26 @@ module Shutl::Resource
23
23
  end
24
24
 
25
25
  def as_json(_)
26
- attributes
26
+ resource_attributes
27
27
  end
28
28
 
29
29
  def to_json(options = nil)
30
30
  {
31
- :"#{prefix}" => attributes
31
+ :"#{prefix}" => resource_attributes
32
32
  }.to_json(options)
33
33
  end
34
34
 
35
35
  def update_attributes(attrs)
36
36
  attrs.each do |a, v|
37
- unless String(a) == 'id' && attributes.include?('id')
37
+ unless String(a) == 'id' && resource_attributes.include?('id')
38
38
  a = 'id' if String(a) == 'new_id'
39
- attributes.update String(a) => v
39
+ resource_attributes[String(a)] = v
40
40
  end
41
41
  end
42
42
  end
43
43
 
44
44
  def update!(attrs, headers = {})
45
- new_attributes = attributes.merge attrs
45
+ new_attributes = resource_attributes.merge attrs
46
46
  update_attributes(self.class.add_resource_id_to new_attributes)
47
47
  save(headers)
48
48
  end
@@ -56,12 +56,13 @@ module Shutl::Resource
56
56
  end
57
57
 
58
58
  def method_missing(method, *args, &block)
59
- return attributes[String(args.first)] if method.to_s == '[]'
60
- attributes.fetch(String(method)) { super }
59
+ return resource_attributes['id'] if String(method) == 'id'
60
+ return resource_attributes[String(args.first)] if method.to_s == '[]'
61
+ resource_attributes.fetch(String(method)) { super }
61
62
  end
62
63
 
63
64
  def respond_to? method
64
- attributes.has_key?(String(method)) ? true : super
65
+ resource_attributes.has_key?(String(method)) ? true : super
65
66
  end
66
67
 
67
68
  def next_resource
@@ -77,11 +78,18 @@ module Shutl::Resource
77
78
  end
78
79
 
79
80
  def resource_id
80
- instance_variable_get :"@#{self.class.resource_id_name}"
81
+ self.instance_variable_get :"@#{self.class.resource_id_name}"
81
82
  end
82
83
 
83
84
  def attributes
84
- @attributes ||= {}
85
+ resource_attributes
86
+ end
87
+
88
+ def resource_attributes
89
+ unless self.instance_variables.include?(:@resource_attributes)
90
+ self.instance_variable_set(:@resource_attributes, {})
91
+ end
92
+ self.instance_variable_get :@resource_attributes
85
93
  end
86
94
 
87
95
  protected
@@ -1,5 +1,5 @@
1
1
  module Shutl
2
2
  module Resource
3
- VERSION = '1.5.1'
3
+ VERSION = '1.5.2'
4
4
  end
5
5
  end
@@ -38,6 +38,10 @@ describe Shutl::Resource::Rest do
38
38
  resource.a.should == 'a'
39
39
  resource.b.should == 2
40
40
  end
41
+
42
+ it 'always responsd to id even if there is no attribute' do
43
+ resource.id.should be_nil
44
+ end
41
45
  end
42
46
 
43
47
  context 'pagination' do
@@ -481,4 +485,14 @@ describe Shutl::Resource::Rest do
481
485
  subject.respond_to?(:foo).should be_false
482
486
  end
483
487
  end
488
+
489
+ describe 'parses successfuly a quote' do
490
+ let(:attrs) do
491
+ {"id"=>"5283836fe4b074c20bb4f4e1-1384351475", "created_at"=>"2013-11-13T13:49+00:00", "valid_until"=>"2013-11-13T14:15+00:00", "basket_value"=>999, "distance"=>12.1, "total_weight"=>nil, "time_zone"=>"America/Chicago", "merchant"=>{"id"=>"ebay_us", "name"=>"eBay US", "shutl_account_number"=>"", "notify_updates"=>true, "notification_endpoint"=>"https://triton-alpha.ebay.com/delivery-events-qa/shutl", "hide_customer_phone_from_carrier"=>false}, "pickup_location"=>{"notes"=>"", "address"=>{"company_name"=>"eBay US", "name"=>"", "line_1"=>"929 W Belmont Ave", "line_2"=>"", "county_or_state"=>"IL", "city"=>"Chicago", "postcode"=>"60657", "country"=>"US"}, "contact"=>{"name"=>"eBay US", "email"=>"email@example.com", "phone"=>"+1 7734720500"}}, "delivery_location"=>{"address"=>{"company_name"=>"", "name"=>"Dean Chen", "line_1"=>"500 S Central Ave", "line_2"=>"", "county_or_state"=>"IL", "city"=>"Chicago", "postcode"=>"60644", "country"=>"US"}, "contact"=>{"name"=>"Dean Chen", "email"=>"zhuichen@ebay.com", "phone"=>"+1 7840536666"}}, "carrier"=>{"id"=>"united_express_systems", "name"=>"United Express Systems", "shutl_account_number"=>"", "time_zone"=>"America/Chicago", "booking_api"=>{"manual"=>false, "url"=>"http://localhost:5000", "client_key"=>"4B91C40C7480A75069790A69AE97A56A", "client_id"=>"674611e57f"}, "vehicle"=>{"id"=>"small_van", "name"=>"Small van", "reference"=>"MiniVan"}, "out_of_hours_notification"=>{}}, "times"=>{"pickup_start"=>"2013-11-13T14:15+00:00", "pickup_finish"=>"2013-11-13T17:00+00:00", "delivery_start"=>"2013-11-13T17:00+00:00", "delivery_finish"=>"2013-11-13T18:00+00:00", "delivery_sla_buffer"=>900, "sliding_amount"=>0}, "prices"=>{"merchant"=>3075, "customer"=>3075, "carrier"=>2563}, "products"=>[]}
492
+ end
493
+
494
+ subject { TestRest.new attrs }
495
+
496
+ its(:prices) { should_not be_empty }
497
+ end
484
498
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shutl_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Rouchy