Module: ErpIntegration::Fulfil::Persistence
- Included in:
- ApiResource
- Defined in:
- lib/erp_integration/fulfil/persistence.rb
Instance Method Summary collapse
-
#create(attributes) ⇒ Array|Hash
Allows creating new resources in Fulfil.
-
#destroy(resource_id) ⇒ Boolean
Destroys the resource.
-
#update(resource_id, attributes) ⇒ Array|Hash
Updates the resource with the given attributes.
Instance Method Details
#create(attributes) ⇒ Array|Hash
Allows creating new resources in Fulfil.
10 11 12 13 14 15 16 17 |
# File 'lib/erp_integration/fulfil/persistence.rb', line 10 def create(attributes) client .post("model/#{model_name}", normalize_attributes(attributes)) .map { |new_record_id| attributes.merge!(id: new_record_id) } .first rescue ErpIntegration::HttpError::BadRequest => e [attributes, [(e)]] end |
#destroy(resource_id) ⇒ Boolean
Destroys the resource.
34 35 36 37 38 39 |
# File 'lib/erp_integration/fulfil/persistence.rb', line 34 def destroy(resource_id) client.delete("model/#{model_name}/#{resource_id}") { id: resource_id } rescue ErpIntegration::HttpError::BadRequest => e [{ id: resource_id }, [(e)]] end |
#update(resource_id, attributes) ⇒ Array|Hash
Updates the resource with the given attributes.
24 25 26 27 28 |
# File 'lib/erp_integration/fulfil/persistence.rb', line 24 def update(resource_id, attributes) client.put("model/#{model_name}/#{resource_id}", attributes) rescue ErpIntegration::HttpError::BadRequest => e [attributes, [(e)]] end |