Class: ExactTarget::ResponseHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/exact_target/response_handler.rb

Overview

This class is responsible for turning parsed ExactTarget response xml into data that applications can use

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ResponseHandler



10
11
12
# File 'lib/exact_target/response_handler.rb', line 10

def initialize(config)
  @config = config
end

Instance Method Details

#accountinfo_retrieve_attrbs(resp) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/exact_target/response_handler.rb', line 24

def accountinfo_retrieve_attrbs(resp)
  resp.xpath('//attribute').map do |a|
    create_result(ListProfileAttribute, a) do |child|
      child.children.map { |v| cast_value(v.text) } if child.name == 'values'
    end
  end
end

#batch_inquire(resp) ⇒ Object



75
76
77
# File 'lib/exact_target/response_handler.rb', line 75

def batch_inquire(resp)
  create_result(BatchStatus, resp.xpath('//Batch').first)
end

#email_add(resp) ⇒ Object



111
112
113
# File 'lib/exact_target/response_handler.rb', line 111

def email_add(resp)
  resp.xpath('//emailID[1]').first.text.to_i
end

#email_retrieve(resp) ⇒ Object



105
106
107
108
109
# File 'lib/exact_target/response_handler.rb', line 105

def email_retrieve(resp)
  resp.xpath('//emaillist').map do |el|
    create_result(EmailInformation, el)
  end
end

#email_retrieve_body(resp) ⇒ Object



117
118
119
# File 'lib/exact_target/response_handler.rb', line 117

def email_retrieve_body(resp)
  resp.xpath('//htmlbody[1]').first.text
end

#handle_import_id_result(resp) ⇒ Object Also known as: list_import



14
15
16
# File 'lib/exact_target/response_handler.rb', line 14

def handle_import_id_result(resp)
  handle_id_result resp, :import_info, :importid, /is being imported/i
end

#list_bulkasync(resp) ⇒ Object



133
134
135
# File 'lib/exact_target/response_handler.rb', line 133

def list_bulkasync(resp)
  resp.xpath('//batchID').first.text.to_i
end

#list_importstatus(resp) ⇒ Object



52
53
54
# File 'lib/exact_target/response_handler.rb', line 52

def list_importstatus(resp)
  resp.xpath('//import_info[1]').first.text
end

#list_refresh_group(resp) ⇒ Object



71
72
73
# File 'lib/exact_target/response_handler.rb', line 71

def list_refresh_group(resp)
  resp.xpath('//groupRefresh/groupAsyncID[1]').first.text.to_i
end

#list_retrieve(resp) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/exact_target/response_handler.rb', line 38

def list_retrieve(resp)
  if resp.xpath('//list/list_name').size == 1
    resp.xpath('//list[1]').map do |list|
      create_result(ListInformation, list)
    end.first
  else
    resp.xpath('//listid').map do |id|
      id.text.to_i
    end
  end
end

#list_retrieve_sub(resp) ⇒ Object



56
57
58
59
60
61
# File 'lib/exact_target/response_handler.rb', line 56

def list_retrieve_sub(resp)
  resp.xpath('//subscriber').map do |s|
    return [] if s.text =~ /no subscribers found/i
    create_result(ExactTarget::Subscriber, s)
  end
end

#list_retrievegroups(resp) ⇒ Object



65
66
67
68
69
# File 'lib/exact_target/response_handler.rb', line 65

def list_retrievegroups(resp)
  resp.xpath('//group').map do |group|
    create_result(ListGroupInformation, group)
  end
end

#subscriber_bulkasync(resp) ⇒ Object



137
138
139
# File 'lib/exact_target/response_handler.rb', line 137

def subscriber_bulkasync(resp)
  resp.xpath('//batchID').first.text.to_i
end

#subscriber_masterunsub(resp) ⇒ Object



96
97
98
99
100
101
# File 'lib/exact_target/response_handler.rb', line 96

def subscriber_masterunsub(resp)
  resp = resp.xpath('//subscriberunsub').map do |su|
    %w(emailaddress status).map { |p| su.xpath(".//#{p}[1]").first.text }
  end
  Hash[resp]
end

#subscriber_retrieve(resp) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/exact_target/response_handler.rb', line 85

def subscriber_retrieve(resp)
  resp.xpath('//subscriber').map do |s|
    return [] if s.text =~ /no subscribers found/i
    sri = create_result(SubscriberInformation, s)
    sri.subscriber = create_result(ExactTarget::Subscriber, s)
    sri
  end
end

#tracking_sent_bulkasync_all(resp) ⇒ Object



141
142
143
# File 'lib/exact_target/response_handler.rb', line 141

def tracking_sent_bulkasync_all(resp)
  resp.xpath('//batchID').first.text.to_i
end

#tracking_sent_bulkasync_all_attributes(resp) ⇒ Object



145
146
147
# File 'lib/exact_target/response_handler.rb', line 145

def tracking_sent_bulkasync_all_attributes(resp)
  resp.xpath('//batchID').first.text.to_i
end

#triggeredsend_add(resp) ⇒ Object



123
124
125
# File 'lib/exact_target/response_handler.rb', line 123

def triggeredsend_add(resp)
  resp.xpath('//triggered_send_description[1]').first.text.to_i
end