Class: ExactTargetRest::TriggeredSend
- Inherits:
-
Object
- Object
- ExactTargetRest::TriggeredSend
- Defined in:
- lib/exact_target_rest/triggered_send.rb
Instance Method Summary collapse
-
#deliver ⇒ Object
TriggeredSend with loaded attributes.
-
#initialize(authorization, external_key, snake_to_camel: true) ⇒ TriggeredSend
constructor
Execute TriggeredSends to one or several subscribers.
-
#send_one(email_address:, subscriber_key: email_address, **data_extension_attributes) ⇒ Object
TriggeredSend for just one subscriber.
-
#with_options(request_type: "ASYNC", email_address:, subscriber_key: email_address, from_address: "", from_name: "", subscriber_attributes: {}) ⇒ Object
Load attributes and return “self”.
Constructor Details
#initialize(authorization, external_key, snake_to_camel: true) ⇒ TriggeredSend
Execute TriggeredSends to one or several subscribers.
8 9 10 11 12 |
# File 'lib/exact_target_rest/triggered_send.rb', line 8 def initialize(, external_key, snake_to_camel: true) @authorization = @external_key = external_key @snake_to_camel = snake_to_camel end |
Instance Method Details
#deliver ⇒ Object
TriggeredSend with loaded attributes.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/exact_target_rest/triggered_send.rb', line 60 def deliver tries ||= 1 @authorization. do |access_token| resp = endpoint.post do |p| p.url(format(TRIGGERED_SEND_PATH, URI.encode(@external_key))) p.headers['Authorization'] = "Bearer #{access_token}" p.body = { From: { Address: @from_address, Name: @from_name }, To: { Address: @email_address, SubscriberKey: @subscriber_key, ContactAttributes: { SubscriberAttributes: @subscriber_attributes } }, OPTIONS: { RequestType: @request_type } } end raise NotAuthorizedError if resp.status == 401 resp end rescue NotAuthorizedError tries -= 1 retry if tries >= 0 raise NotAuthorizedError end |
#send_one(email_address:, subscriber_key: email_address, **data_extension_attributes) ⇒ Object
TriggeredSend for just one subscriber.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/exact_target_rest/triggered_send.rb', line 20 def send_one( email_address:, subscriber_key: email_address, ** data_extension_attributes ) ( email_address: email_address, subscriber_key: subscriber_key, subscriber_attributes: prepare_attributes(data_extension_attributes) ).deliver end |
#with_options(request_type: "ASYNC", email_address:, subscriber_key: email_address, from_address: "", from_name: "", subscriber_attributes: {}) ⇒ Object
Load attributes and return “self”. To send using async methods.
> it uses Email if not set
> Keys as Strings (when your ExactTarget’s fields doesn’t have a pattern)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/exact_target_rest/triggered_send.rb', line 41 def ( request_type: "ASYNC", email_address:, subscriber_key: email_address, from_address: "", from_name: "", subscriber_attributes: {} ) @request_type = request_type @email_address = email_address @subscriber_key = subscriber_key @from_address = from_address @from_name = from_name @subscriber_attributes = subscriber_attributes self end |