Skip to main content

Ruby

The official Talon.One Ruby SDK can be found on GitHub. The SDK supports both the Integration API and Management API, and can be used on Ruby 2 (or newer).

# Fill in the details of your Talon.One Application here

talon = TalonOne::Integration::Client.new :endpoint => 'https://mycompany.europe-west1.talon.one',
:application_id => 213,
:application_key => '5ea4583bfb81beef'


# When the customer registers or updates their account

talon.update_customer_profile "my_unique_profile_id",
"name" => "Val Kust",
"billingAddress1" => "21 Jump St."


# When the customer adds an item to their cart

result = talon.update_customer_session "my_unique_session_id",
"profileId" => "my_unique_profile_id",
"cartItems" => [{
"name" => "Shiny Red Shoes",
"sku" => "srs_1234",
"price" => 49.99,
"quantity" => 1,
"currency" => "USD"
}],
"attributes" => {
"ShippingCost" => 3.75
},
"total" => 53.74


# Process the effects generated by Talon.One as a response

result.events.effects.each do |effect|
if effect.function == "rejectCoupon"
# Customer entered an invalid coupon

@talon_msg = "Coupon Invalid."
@sale.discount = 0
@sale.save
update_totals
elsif effect.function == "acceptCoupon"
# Customer entered a valid coupon

@talon_msg = "Coupon Accepted."
elsif effect.function == "setDiscount"
# Apply a discount to the current cart

@sale.discount = effect.args[1].to_f/total.to_f
@sale.save
elsif effect.function == "addFreeItem"
# Put a free item in the cart

sku = effect.args[1]
item = Item.where(sku: sku).first
create_line_item(item.id, @sale.id, 1)
end
end