Class: Mws::Apis::Feeds::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/mws/apis/feeds/product.rb

Defined Under Namespace

Classes: DelegatingBuilder, DetailBuilder, Dimensions, DimensionsBuilder, ProductBuilder

Constant Summary collapse

CategorySerializer =
Mws::Serializer.new ce: 'CE', fba: 'FBA', eu_compliance: 'EUCompliance'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sku, &block) ⇒ Product

Returns a new instance of Product.



13
14
15
16
17
18
# File 'lib/mws/apis/feeds/product.rb', line 13

def initialize(sku, &block)
  @sku = sku
  @bullet_points = []
  ProductBuilder.new(self).instance_eval &block if block_given?
  raise Mws::Errors::ValidationError, 'Product must have a category when details are specified.' if @details and @category.nil?
end

Instance Attribute Details

#brandObject

Returns the value of attribute brand.



9
10
11
# File 'lib/mws/apis/feeds/product.rb', line 9

def brand
  @brand
end

#bullet_pointsObject

Returns the value of attribute bullet_points.



9
10
11
# File 'lib/mws/apis/feeds/product.rb', line 9

def bullet_points
  @bullet_points
end

#categoryObject

Returns the value of attribute category.



11
12
13
# File 'lib/mws/apis/feeds/product.rb', line 11

def category
  @category
end

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/mws/apis/feeds/product.rb', line 7

def description
  @description
end

#detailsObject

Returns the value of attribute details.



11
12
13
# File 'lib/mws/apis/feeds/product.rb', line 11

def details
  @details
end

#item_dimensionsObject

Returns the value of attribute item_dimensions.



10
11
12
# File 'lib/mws/apis/feeds/product.rb', line 10

def item_dimensions
  @item_dimensions
end

#manufacturerObject

Returns the value of attribute manufacturer.



9
10
11
# File 'lib/mws/apis/feeds/product.rb', line 9

def manufacturer
  @manufacturer
end

#msrpObject

Returns the value of attribute msrp.



9
10
11
# File 'lib/mws/apis/feeds/product.rb', line 9

def msrp
  @msrp
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/mws/apis/feeds/product.rb', line 9

def name
  @name
end

#package_dimensionsObject

Returns the value of attribute package_dimensions.



10
11
12
# File 'lib/mws/apis/feeds/product.rb', line 10

def package_dimensions
  @package_dimensions
end

#package_weightObject

Returns the value of attribute package_weight.



10
11
12
# File 'lib/mws/apis/feeds/product.rb', line 10

def package_weight
  @package_weight
end

#shipping_weightObject

Returns the value of attribute shipping_weight.



10
11
12
# File 'lib/mws/apis/feeds/product.rb', line 10

def shipping_weight
  @shipping_weight
end

#skuObject (readonly)

Returns the value of attribute sku.



7
8
9
# File 'lib/mws/apis/feeds/product.rb', line 7

def sku
  @sku
end

#tax_codeObject

Returns the value of attribute tax_code.



9
10
11
# File 'lib/mws/apis/feeds/product.rb', line 9

def tax_code
  @tax_code
end

#upcObject

Returns the value of attribute upc.



9
10
11
# File 'lib/mws/apis/feeds/product.rb', line 9

def upc
  @upc
end

Instance Method Details

#to_xml(name = 'Product', parent = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mws/apis/feeds/product.rb', line 20

def to_xml(name='Product', parent=nil)
  Mws::Serializer.tree name, parent do |xml|
    xml.SKU @sku
    xml.StandardProductID {
      xml.Type 'UPC'
      xml.Value @upc
    } unless @upc.nil?
    xml.ProductTaxCode @tax_code unless @upc.nil?
    xml.DescriptionData {
      xml.Title @name unless @name.nil?
      xml.Brand @brand  unless @brand.nil?
      xml.Description @description  unless @description.nil?
      bullet_points.each do | bullet_point |
        xml.BulletPoint bullet_point
      end
      @item_dimensions.to_xml('ItemDimensions', xml) unless @item_dimensions.nil?
      @package_dimensions.to_xml('PackageDimensions', xml) unless @item_dimensions.nil?

      @package_weight.to_xml('PackageWeight', xml) unless @package_weight.nil?
      @shipping_weight.to_xml('ShippingWeight', xml) unless @shipping_weight.nil?

      @msrp.to_xml 'MSRP', xml unless @msrp.nil?

      xml.Manufacturer @manufacturer unless @manufacturer.nil?
    }

    unless @details.nil?
      xml.ProductData {
        CategorySerializer.xml_for @category, {product_type: @details}, xml
      }
    end
  end
end