Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

talon-one/talon-one.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

THIS SDK IS NOT BEING MAINTAINED. REFER TO https://github.com/talon-one/talon_one.js

talon-one - client for Talon.One Integration API

Synopsis

var TalonOne = require('talon-one')

var applicationId = 15025
var applicationKey = '41d3f05e76fd667b'
var client = new TalonOne.IntegrationClient('https://mycompany.talon.one', applicationId, applicationKey)

var sessionId = 'some-identifier-for-this-session'
var customerId = 'id-used-by-my-company'


client.updateCustomerProfile(customerId, {
  attributes: {
    // only include properties you want to update, null values are ignored
    Name: 'Val Kust',
  }
}, function (err, integrationState) {
  if (err) {
    console.log(err)
  } else {
    console.log(integrationState.profile)
    console.log(integrationState.session)
    console.log(integrationState.event)
  }
})


client.updateCustomerSession(sessionId, {
  // associate this session with the profile we created above
  profileId: customerId,
  // set referral ID for this session
  referral: 'somereferral-identifier',
}, function (err, integrationState) {

  if (err){
    console.log(err)
  } else {
    console.log(integrationState.profile)
    console.log(integrationState.session)
    console.log(integrationState.event)
  }
})


// sessionId, customerId, eventType, eventData, callback
client.trackEvent(sessionId, customerId, 'bought_upgrade', {
  type: "premium"
}, function (err, integrationState) {
  if (err) {
    console.log(err)
  } else {
    console.log(integrationState.profile)
    console.log(integrationState.session)
    console.log(integrationState.event)
  }
})


// campaignId, customerId, options
client.createReferral(campaignId, customerId, {
  friendId: 'some-friend-id', // friendId - optional
  start: '2014-07-07T00:00:00Z', // start date of eligibility - optional
  end: '2014-07-14T00:00:00Z' // expiry date of eligibility - optional
}, function (err, integrationState) {
  if (err) {
    console.log(err)
  } else {
    console.log(integrationState.campaignId)
    console.log(integrationState.advocateProfileIntegrationId)
    console.log(integrationState.code)
    /*
    console.log(integrationState.friendProfileIntegrationId) // (if supplied)
    console.log(integrationState.startDate) // (if supplied)
    console.log(integrationState.expiryDate) // (if supplied)
    */
  }
})

API

talon-one/integration

talon-one/integration.Client

Kind: static class of talon-one/integration

new IntegrationClient(baseUrl, applicationId, applicationKey, context)

Create an HTTP client that will handle signing requests for the integration API

Param Type Description
baseUrl string The root URL for requests, e.g. https://mycompany.talon.one
applicationId number | string The ID of the application sending the request.
applicationKey string The hexadecimal API key for the application sending the request.
context object Data specific to this client instance that will be passed to global effect handlers.

client.updateCustomerSession(sessionId, updates)

Update/create a customer session.

Kind: instance method of Client See: http://developers.talon.one/integration-api/reference/#updateCustomerSession

Param Type Description
sessionId string The integration ID of the customer
updates Object an object containing session properties to update

client.updateCustomerProfile(customerId, updates)

Update/create a customer profile

Kind: instance method of Client See: http://developers.talon.one/integration-api/reference/#updateCustomerProfile

Param Type Description
customerId string The integration ID of the customer
updates Object an object containing profile properties to update

client.trackEvent(sessionId, customerId, eventType, eventData)

Track a custom event

Kind: instance method of Client See: http://developers.talon.one/integration-api/reference/#trackEvent

Param Type Description
sessionId string The integration ID of the customer
customerId string The integration ID of the customer
eventType string Event type name
eventData Object an object containing event data to update

client.createReferral(campaignId, customerId, options)

Create a referral code

Kind: instance method of Client See: http://developers.talon.one/integration-api/reference/#createReferral

Param Type Description
campaignId number The ID of the campaign that the referral code belongs to
customerId string The integration ID of the customer
options Object | null an optional object containing referral's friend ID, start and expiry dates

talon-one/integration.handleEffect(effectName, handler)

Register a global effect handler. This handler will be called whenever a matching effect is returned by the API, with it's first argument being the context value of the client that performed the request. See the API docs on handling effects to see which handlers should be registered and what their remaining arguments will be.

Kind: static method of talon-one/integration See: http://developers.talon.one/integration-api/handling-effects/

Param Type Description
effectName string The name of the effect to handle.
handler function The handler callback.