Class: ErpIntegration::Fulfil::Resources::Product
- Inherits:
-
ApiResource
- Object
- ApiResource
- ErpIntegration::Fulfil::Resources::Product
- Defined in:
- lib/erp_integration/fulfil/resources/product.rb
Constant Summary
Constants included from PaginationMethods
PaginationMethods::DEFAULT_LIMIT, PaginationMethods::DEFAULT_OFFSET, PaginationMethods::MAX_LIMIT
Instance Attribute Summary
Attributes inherited from ApiResource
Attributes included from QueryMethods
#or_clauses, #selected_fields, #where_clauses
Attributes included from PaginationMethods
#limit_value, #offset_value, #page_number
Instance Method Summary collapse
-
#add_media(id, image_objects) ⇒ Object
developers.fulfil.io/rest_api/model/product.product/#add-product-images If you have your product images hosted not on Fulfil, you can use this endpoint to add the media in Fulfil to a product.
-
#bom?(sku) ⇒ Boolean
(also: #billing_of_materials?)
Checks whether a certain product is a BOM.
Methods inherited from ApiResource
#all, api_keys_pool, api_keys_pool=, client, config, #count, #each, #find_each, #initialize, model_name, model_name=
Methods included from QueryMethods
#or, #or!, #select, #select!, #where, #where!, #where_domain, #where_ilike, #where_in, #where_less_or_equal_to, #where_less_than, #where_like, #where_more_or_equal_to, #where_more_than, #where_not, #where_not_in
Methods included from Persistence
Methods included from PaginationMethods
#limit, #limit!, #offset, #offset!, #page, #page!
Methods included from FinderMethods
Methods included from Context
Constructor Details
This class inherits a constructor from ErpIntegration::Fulfil::ApiResource
Instance Method Details
#add_media(id, image_objects) ⇒ Object
developers.fulfil.io/rest_api/model/product.product/#add-product-images If you have your product images hosted not on Fulfil, you can use this endpoint to add the media in Fulfil to a product. The method expects a list of objects when making the request:
url (string) image URL name (string) name of the image file, including image extension
example:
[
[
{
"url": "https://dns.mysite.com/media/image1.jpg?format=jpg&name=small",
"name": "product1_1.jpg"
},
{
"url": "https://mysite.net/us/images/product_2.jpg",
"name": "product1_2.jpg"
}
]
]
To simplify the API usage, we’re sending the received image_objects wrapped in an array
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/erp_integration/fulfil/resources/product.rb', line 46 def add_media(id, image_objects) client.put("model/#{model_name}/#{id}/add_media", [image_objects]) true # Workaround: Fulfil api does not return a json when status code is 200 (a.k.a. "Ok") # and faraday is having an error when trying to parse it. Let's skip the parse error # and move on. rescue Faraday::ParsingError true end |
#bom?(sku) ⇒ Boolean Also known as: billing_of_materials?
Checks whether a certain product is a BOM.
14 15 16 |
# File 'lib/erp_integration/fulfil/resources/product.rb', line 14 def bom?(sku) select(:boms).find_by!(code: sku).boms.any? end |