Class: Io::Flow::V0::Models::ShopifyCart

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

Overview

Representation of a Shopify cart exactly as defined by shopify.com

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ ShopifyCart



39659
39660
39661
39662
39663
39664
39665
39666
39667
39668
39669
39670
39671
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39659

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :items, :item_count, :total_price, :local], 'ShopifyCart')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @items = HttpClient::Preconditions.assert_class('items', opts.delete(:items), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::ShopifyCartItem) ? x : ::Io::Flow::V0::Models::ShopifyCartItem.new(x)) }
  @item_count = HttpClient::Preconditions.assert_class('item_count', opts.delete(:item_count), Integer)
  @total_price = HttpClient::Preconditions.assert_class('total_price', opts.delete(:total_price), Integer)
  @local = (x = opts.delete(:local); x.is_a?(::Io::Flow::V0::Models::) ? x : ::Io::Flow::V0::Models::.new(x))
  @attributes = (x = opts.delete(:attributes); x.nil? ? nil : HttpClient::Preconditions.assert_class('attributes', HttpClient::Helper.to_object(x), Hash))
  @note = (x = opts.delete(:note); x.nil? ? nil : HttpClient::Preconditions.assert_class('note', x, String))
  @requires_shipping = HttpClient::Preconditions.assert_boolean('requires_shipping', (x = opts.delete(:requires_shipping); x.nil? ? true : x))
  @total_weight = (x = opts.delete(:total_weight); x.nil? ? nil : HttpClient::Preconditions.assert_class('total_weight', x, Integer))
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



39657
39658
39659
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39657

def attributes
  @attributes
end

#idObject (readonly)

Returns the value of attribute id.



39657
39658
39659
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39657

def id
  @id
end

#item_countObject (readonly)

Returns the value of attribute item_count.



39657
39658
39659
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39657

def item_count
  @item_count
end

#itemsObject (readonly)

Returns the value of attribute items.



39657
39658
39659
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39657

def items
  @items
end

#localObject (readonly)

Returns the value of attribute local.



39657
39658
39659
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39657

def local
  @local
end

#noteObject (readonly)

Returns the value of attribute note.



39657
39658
39659
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39657

def note
  @note
end

#requires_shippingObject (readonly)

Returns the value of attribute requires_shipping.



39657
39658
39659
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39657

def requires_shipping
  @requires_shipping
end

#total_priceObject (readonly)

Returns the value of attribute total_price.



39657
39658
39659
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39657

def total_price
  @total_price
end

#total_weightObject (readonly)

Returns the value of attribute total_weight.



39657
39658
39659
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39657

def total_weight
  @total_weight
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



39677
39678
39679
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39677

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

#to_hashObject



39681
39682
39683
39684
39685
39686
39687
39688
39689
39690
39691
39692
39693
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39681

def to_hash
  {
    :id => id,
    :items => items.map { |o| o.to_hash },
    :item_count => item_count,
    :total_price => total_price,
    :local => local.to_hash,
    :attributes => attributes,
    :note => note,
    :requires_shipping => requires_shipping,
    :total_weight => total_weight
  }
end

#to_jsonObject



39673
39674
39675
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39673

def to_json
  JSON.dump(to_hash)
end