Module: SolidusShipwire::Proxy
Class Method Summary collapse
Instance Method Summary collapse
- #create_on_shipwire(obj) ⇒ Object
- #find_on_shipwire(shipwire_id) ⇒ Object
- #find_or_create_on_shipwire_api(shipwire_id) ⇒ Object
- #in_shipwire ⇒ Object
- #shipwire_instance ⇒ Object
- #update_on_shipwire ⇒ Object
Class Method Details
.prepended(base) ⇒ Object
3 4 5 6 |
# File 'lib/solidus_shipwire/proxy.rb', line 3 def self.prepended(base) klass = Class.new SolidusShipwire::ShipwireObject base.const_set 'ShipwireObject', klass end |
Instance Method Details
#create_on_shipwire(obj) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/solidus_shipwire/proxy.rb', line 36 def create_on_shipwire(obj) response = shipwire_instance.create(obj) raise SolidusShipwire::ResponseException.new(response), response.error_report unless response.ok? update_column(:shipwire_id, response.body['resource']['items'].first['resource']['id']) find_on_shipwire(response.body['resource']['items'].first['resource']['id']) end |
#find_on_shipwire(shipwire_id) ⇒ Object
22 23 24 |
# File 'lib/solidus_shipwire/proxy.rb', line 22 def find_on_shipwire(shipwire_id) shipwire_instance.find shipwire_id end |
#find_or_create_on_shipwire_api(shipwire_id) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/solidus_shipwire/proxy.rb', line 12 def find_or_create_on_shipwire_api(shipwire_id) shipwire_response = find_on_shipwire(shipwire_id) unless shipwire_response.ok? shipwire_response = create_on_shipwire(to_shipwire) end to_shipwire_object(shipwire_response.body['resource']) end |
#in_shipwire ⇒ Object
8 9 10 |
# File 'lib/solidus_shipwire/proxy.rb', line 8 def in_shipwire find_or_create_on_shipwire_api(shipwire_id) end |
#shipwire_instance ⇒ Object
30 31 32 33 34 |
# File 'lib/solidus_shipwire/proxy.rb', line 30 def shipwire_instance super rescue NoMethodError raise 'override shipwire_instance' end |
#update_on_shipwire ⇒ Object
26 27 28 |
# File 'lib/solidus_shipwire/proxy.rb', line 26 def update_on_shipwire shipwire_instance.update(shipwire_id, to_shipwire) end |