Class: Traction::WebConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/traction/web_connection.rb

Overview

Creates a new WebConnection object to contain wrapped API methods associated with a particular WebConnection, or Function, in Traction API terminology.

Method examples use the hypothetical namespaces from the configuration example.

Constant Summary collapse

DOMAIN =
"int.api.tractionplatform.com"

Instance Method Summary collapse

Constructor Details

#initialize(path, password) ⇒ WebConnection

Returns a new instance of WebConnection.



13
14
15
16
# File 'lib/traction/web_connection.rb', line 13

def initialize(path, password)
  @path = path
  @password = password
end

Instance Method Details

#add_competition_entrant(details, entry_code, subscribe = true, optional_data = {}) ⇒ Object

Competition method for adding an entrant to (or removing an entrant from) a competition.

Examples:

Traction.competition.add_competition_entrant({"EMAIL" => "[email protected]", "MOBILE" => "0412345678", "FIRSTNAME" => "Jane", "LASTNAME" => "Doe"}, "XYZ123")
#=> {data: {}, success: true}
# OR
#=>
#{
#  error: {
#    code: 2040,
#    description: "Entry Code Used",
#    cause: [{
#      field: "entryCode",
#      message: "[XYZ123]  has already been used"
#    }]
#  },
#  success: false
#}

Parameters:

  • details (Hash)

    The customer details to add.

  • entry_code (String)

    The entry code for the entrant.

  • subscribe (Boolean) (defaults to: true)

    Optional. Subscribe (true) or unsubscribe (false) from the competition. Defaults to true.

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

    Optional. Data available in triggered emails to the customer.



194
195
196
197
198
199
200
201
# File 'lib/traction/web_connection.rb', line 194

def add_competition_entrant(details, entry_code, subscribe=true, optional_data={})
  body = {customer: details,
          entryCode: entry_code,
          subscribe: subscribe,
          transData: optional_data}
   
  get_response_for(body)
end

#add_customer(details, optional_data = {}) ⇒ Object

Registration method for adding a customer to the campaign customer list.

Examples:

Traction.registration.add_customer("EMAIL" => "[email protected]", "MOBILE" => "0412345678", "FIRSTNAME" => "John", "LASTNAME" => "Doe")
#=> {data: {}, success: true}
# OR
#=>
#{
#  error: {
#    code: 1000,
#    description: "Invalid Parameter Data",
#    cause: [{
#      field: "customer.EMAIL",
#      message: "invalid email address"
#    }]
#  },
#  success: false
#}

Parameters:

  • details (Hash)

    The customer details to add.

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

    Optional. Data available in triggered emails to the customer.



77
78
79
80
81
82
# File 'lib/traction/web_connection.rb', line 77

def add_customer(details, optional_data={})
  body = {customer: details,
          transData: optional_data}

  get_response_for(body)
end

#add_customer_with_group_and_subscription(details, groups = {}, subscriptions = {}) ⇒ Object

Registration method for adding a customer to the campaign customer list, and associating the customer with (or dissociating a customer from) groups and/or subscriptions.

Examples:

Traction.registration.add_customer_with_group_and_subscription({"EMAIL" => "[email protected]", "MOBILE" => "0412345678", "FIRSTNAME" => "John", "LASTNAME" => "Doe"}, {"12345" => true, "12346" => true, "23456" => false}, {"9876543210" => "SUBSCRIBE", "9876543211" => "SUBSCRIBE", "9876543212" => "UNSUBSCRIBE"})
#=> {data: {}, success: true}
# OR
#=>
#{
#  error: {
#    code: 1150,
#    description: "Invalid Group ID, please confirm group exists",
#    cause: "Group Id [12345] should be pre-existing"
#  },
#  success: false
#}

Parameters:

  • details (Hash)

    The customer details to add.

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

    Optional. Groups to associate or dissociate with; true associates, false dissociates.

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

    Optional. Subscriptions to associate or dissociate with; “SUBSCRIBE” associates, “UNSUBSCRIBE” dissociates.



104
105
106
107
108
109
110
# File 'lib/traction/web_connection.rb', line 104

def add_customer_with_group_and_subscription(details, groups={}, subscriptions={})
  body = {customer: details,
          groups: groups,
          subscriptions: subscriptions}

  get_response_for(body)
end

#draw_competition(venue_ids = []) ⇒ Object

Competition method for drawing the competition winner/s.

Examples:

Traction.competition.draw
#=> {data: {}, success: true}
# OR
#=>
#{
#  error: {
#    code: 2140,
#    description: "Draw already done",
#    cause: null
#  },
#  success: false
#}

Parameters:

  • venues_ids (Array)

    Optional. List of venues for which the winner is drawn from. Defaults to all venues.



220
221
222
223
224
225
# File 'lib/traction/web_connection.rb', line 220

def draw_competition(venue_ids=[])
  body = {mode: "DRAW"}
  body[:venueIdList] = venue_ids if venue_ids.any?

  get_response_for(body)
end

#get_customer_by(field, value, attributes = []) ⇒ Object

Registration method for retrieving attributes for a customer, searching against a given field.

Examples:

Traction.registration.get_customer_by("EMAIL", "[email protected]", ["EMAIL", "MOBILE", "FIRSTNAME", "LASTNAME"]
#=>
#{
#  data: {
#    customer: {
#      email: "[email protected]",
#      mobile: "0412345678",
#      firstname: "John",
#      lastname: "Doe"
#    }
#  },
#  success: true
#}
# OR
#=>
#{
#  error: {
#    code: 1010,
#    description: "Customer not found",
#    cause: [{
#      "field": "customer.EMAIL"
#    }]
#  }
#}

Parameters:

  • field (String)

    The field to search against.

  • value (String)

    The value to search for.

  • attributes (Array) (defaults to: [])

    The retrieved customer fields on a successful result.



49
50
51
52
53
54
# File 'lib/traction/web_connection.rb', line 49

def get_customer_by(field, value, attributes=[])
  body = {customerLookup: {field => value},
          customerAttributes: attributes}

  get_response_for(body)
end

#redeem_winner(field, value, venue_id, redemption_code, optional_data = {}) ⇒ Object

Competition method for providing redemption code to a winner.

Examples:

Traction.competition.redeem_winner("EMAIL", "[email protected]", "XYZ", "ABC123") 
#=>
#{
#  data: {
#    numWinners: 8,
#    numWinnersNoRedemptionCode: 2
#  },
#  success: true
#}
# OR
#=>
#{
#  error: {
#    code: 2120,
#    description: "Claim code invalid",
#    cause: null
#  },
#  success: false
#}

Parameters:

  • field (String)

    The field to search against.

  • value (String)

    The value to search for.

  • venues_id (String)

    Id of venue for which redemption code and customer apply.

  • redemption_code (String)

    The redemption code for the winner.

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

    Optional. Data available in triggered emails to the customer.



255
256
257
258
259
260
261
262
263
# File 'lib/traction/web_connection.rb', line 255

def redeem_winner(field, value, venue_id, redemption_code, optional_data={})
  body = {mode: "REDEEM",
          customer: {field => value},
          venueId: venue_id,
          redemptionCode: redemption_code,
          transData: optional_data}

  get_response_for(body)
end

#send_triggered_email(email, optional_data = {}) ⇒ Object

Triggered Message method for sending a triggered email to a subscriber. The content of the email can be personalised with optional data, but should already exist in traction.

Examples:

Traction.triggered.send_triggered_email("[email protected]")
#=> {data: {}, success: true}
# OR
#=>
#{
#  error: {
#    code: 1000,
#    description: "Invalid Parameter Data",
#    cause: [{
#      field: "customer.Email",
#      message: "Invalid Email Address"
#    }]
#  },
#  success: false
#}

Parameters:

  • email (String)

    The email to search against.

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

    Optional. Data available in triggered emails to the customer.



287
288
289
290
291
292
# File 'lib/traction/web_connection.rb', line 287

def send_triggered_email(email, optional_data={})
  body = {customer: {EMAIL: email},
          transData: optional_data}

  get_response_for(body)
end

#validate_entry(field, value, entry_code) ⇒ Object

Competition method for validating a potential entry to a competition.

Examples:

Traction.competition.validate_entry("EMAIL", "[email protected]", "ABC123")
#=> {data: {}, success: true}
# OR
#=>
#{
#  error: {
#    code: 2040,
#    description: "Entry Code Used",
#    cause: [{
#      field: "entryCode",
#      message: "[ABC123]  has already been used"
#    }]
#  },
#  success: false
#}

Parameters:

  • field (String)

    The relevant customer field to validate with.

  • value (String)

    The value associated with the field.

  • entry_code (String)

    The entry code to validate.



163
164
165
166
167
168
169
# File 'lib/traction/web_connection.rb', line 163

def validate_entry(field, value, entry_code)
  body = {mode: "VALIDATE",
          customer: {field => value},
          entryCode: entry_code}
   
  get_response_for(body)
end

#web_registration(details, optional_data = {}) ⇒ Object

Registration method for adding a customer directly to an associated email list, selected on creation of the function in traction.

Examples:

Traction.registration.add_customer("EMAIL" => "[email protected]", "MOBILE" => "0412345678", "FIRSTNAME" => "John", "LASTNAME" => "Doe")
#=> {data: {}, success: true}
# OR
#=>
#{
#  error: {
#    code: 1000,
#    description: "Invalid Parameter Data",
#    cause: [{
#      field: "customer.EMAIL",
#      message: "invalid email address"
#    }]
#  },
#  success: false
#}

Parameters:

  • details (Hash)

    The customer details to add.

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

    Optional. Data available in triggered emails to the customer.



134
135
136
137
138
139
# File 'lib/traction/web_connection.rb', line 134

def web_registration(details, optional_data={})
  body = {customer: details,
          transData: optional_data}

  get_response_for(body)
end