Class: Io::Flow::V0::Models::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Overview

The Flow item defines a specific item that can be purchased by a consumer. For many clients, this will map to a Sku.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Item



15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15576

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :number, :locale, :name, :price, :dimensions], 'Item')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @number = HttpClient::Preconditions.assert_class('number', opts.delete(:number), String)
  @locale = HttpClient::Preconditions.assert_class('locale', opts.delete(:locale), String)
  @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
  @price = (x = opts.delete(:price); x.is_a?(::Io::Flow::V0::Models::Price) ? x : ::Io::Flow::V0::Models::Price.new(x))
  @categories = HttpClient::Preconditions.assert_class('categories', (x = opts.delete(:categories); x.nil? ? [] : x), Array).map { |v| HttpClient::Preconditions.assert_class('categories', v, String) }
  @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String))
  @attributes = HttpClient::Preconditions.assert_class('attributes', (x = opts.delete(:attributes); x.nil? ? {} : x), Hash).inject({}) { |h, d| h[d[0]] = HttpClient::Preconditions.assert_class('attributes', d[1], String); h }
  @dimensions = (x = opts.delete(:dimensions); x.is_a?(::Io::Flow::V0::Models::Dimensions) ? x : ::Io::Flow::V0::Models::Dimensions.new(x))
  @images = HttpClient::Preconditions.assert_class('images', (x = opts.delete(:images); x.nil? ? [] : x), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::Image) ? x : ::Io::Flow::V0::Models::Image.new(x)) }
  @local = (x = opts.delete(:local); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Local) ? x : ::Io::Flow::V0::Models::Local.new(x)))
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



15574
15575
15576
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15574

def attributes
  @attributes
end

#categoriesObject (readonly)

Returns the value of attribute categories.



15574
15575
15576
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15574

def categories
  @categories
end

#descriptionObject (readonly)

Returns the value of attribute description.



15574
15575
15576
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15574

def description
  @description
end

#dimensionsObject (readonly)

Returns the value of attribute dimensions.



15574
15575
15576
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15574

def dimensions
  @dimensions
end

#idObject (readonly)

Returns the value of attribute id.



15574
15575
15576
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15574

def id
  @id
end

#imagesObject (readonly)

Returns the value of attribute images.



15574
15575
15576
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15574

def images
  @images
end

#localObject (readonly)

Returns the value of attribute local.



15574
15575
15576
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15574

def local
  @local
end

#localeObject (readonly)

Returns the value of attribute locale.



15574
15575
15576
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15574

def locale
  @locale
end

#nameObject (readonly)

Returns the value of attribute name.



15574
15575
15576
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15574

def name
  @name
end

#numberObject (readonly)

Returns the value of attribute number.



15574
15575
15576
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15574

def number
  @number
end

#priceObject (readonly)

Returns the value of attribute price.



15574
15575
15576
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15574

def price
  @price
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



15596
15597
15598
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15596

def copy(incoming={})
  Item.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
end

#to_hashObject



15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15600

def to_hash
  {
    :id => id,
    :number => number,
    :locale => locale,
    :name => name,
    :price => price.to_hash,
    :categories => categories,
    :description => description,
    :attributes => attributes,
    :dimensions => dimensions.to_hash,
    :images => images.map { |o| o.to_hash },
    :local => local.nil? ? nil : local.to_hash
  }
end

#to_jsonObject



15592
15593
15594
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15592

def to_json
  JSON.dump(to_hash)
end