Class: Iterable::Commerce

Inherits:
ApiResource show all
Defined in:
lib/iterable/commerce.rb

Overview

Interact with /commerce API endpoints

Examples:

Creating commerce endpoint object

# With default config
commerce = Iterable::Commerce.new
commerce.all

# With custom config
conf = Iterable::Config.new(token: 'new-token')
commerce = Iterable::Commerce.new(config)

Instance Attribute Summary

Attributes inherited from ApiResource

#conf

Instance Method Summary collapse

Methods inherited from ApiResource

#default_config, default_config, #initialize

Constructor Details

This class inherits a constructor from Iterable::ApiResource

Instance Method Details

#track_purchase(total, items = [], user = {}, attrs = {}) ⇒ Iterable::Response

Track a purchase. ‘shoppingCartItems’ field on the user profile is cleared. User profile is also updated (created otherwise) using the user request field

Parameters:

  • total (Float)

    Total order amount

  • items (Array[Hash]) (defaults to: [])

    Array of hashes of commerce items

  • user (Hash) (defaults to: {})

    User update request details to update or create user

  • attrs (Hash) (defaults to: {})

    Track purchase request additional fields

Returns:



26
27
28
29
30
31
32
33
34
# File 'lib/iterable/commerce.rb', line 26

def track_purchase(total, items = [], user = {}, attrs = {})
  data = {
    total: total,
    items: items,
    user: user
  }
  data.merge!(attrs)
  Iterable.request(conf, '/commerce/trackPurchase').post(data)
end

#update_cart(user = {}, items = []) ⇒ Iterable::Response

Updates the ‘shoppingCartItems’ field on the user profile with shopping cart items. User profile is updated (created otherwise) via the user field.

Parameters:

  • user (Hash) (defaults to: {})

    User update request details to update or create user

  • items (Array[Hash]) (defaults to: [])

    Array of hashes of commerce items

Returns:



45
46
47
48
49
50
51
# File 'lib/iterable/commerce.rb', line 45

def update_cart(user = {}, items = [])
  data = {
    items: items,
    user: user
  }
  Iterable.request(conf, '/commerce/updateCart').post(data)
end