Class: RBET::Client
Direct Known Subclasses
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(username, password, options = {}) ⇒ Client
constructor
Initializes a new ET::Client object.
-
#live? ⇒ Boolean
Boolean value of whether the service is running or not currently.
-
#send {|@system| ... } ⇒ Object
usage: send do|io| io << ‘more xml’ end.
-
#status ⇒ Object
Returns the string value from the ExactTarget API ping method.
Methods included from Renderable
#render_template, #set_template_path, #template_path
Constructor Details
#initialize(username, password, options = {}) ⇒ Client
Initializes a new ET::Client object
Usaage:
client = ET::Client.new('tester','tester11', {:service_url => 'http://127.0.0.1:99999/test/', :use_ssl => false})
client.status
=> "Running"
client.live?
=> true
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rbet/client.rb', line 45 def initialize(username,password,={}) @username = username @password = password service_url = [:service_url] ? [:service_url] : 'https://www.exacttarget.com/api/integrate.asp?qf=xml' @uri = URI.parse(service_url) @url = Net::HTTP.new(@uri.host, @uri.port) @url.use_ssl = .key?(:use_ssl) ? [:use_ssl] : true @url.set_debug_output .key?(:debug_output) ? [:debug_output] : nil @headers = { 'Content-Type' => 'application/x-www-form-urlencoded', 'Connection' => 'close' } end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
32 33 34 |
# File 'lib/rbet/client.rb', line 32 def headers @headers end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
32 33 34 |
# File 'lib/rbet/client.rb', line 32 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
32 33 34 |
# File 'lib/rbet/client.rb', line 32 def username @username end |
Instance Method Details
#live? ⇒ Boolean
Boolean value of whether the service is running or not currently
60 61 62 63 |
# File 'lib/rbet/client.rb', line 60 def live? @current_status ||= status @current_status == 'Running' end |
#send {|@system| ... } ⇒ Object
usage:
send do|io|
io << 'more xml'
end
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rbet/client.rb', line 79 def send @system = "" yield @system data = "" xml = Builder::XmlMarkup.new(:target => data, :indent => 2) xml.instruct! xml.exacttarget do |x| x. do x.username @username x.password @password end x << @system end data_encoded = url_encode(data) result = 'qf=xml&xml=' + data_encoded @url.post( @uri.path, result, @headers.merge('Content-length' => result.length.to_s) ) end |
#status ⇒ Object
Returns the string value from the ExactTarget API ping method. (“Running” when the system is operational)
66 67 68 69 70 71 72 73 |
# File 'lib/rbet/client.rb', line 66 def status response = send do|io| io << render_template('ping') end Error.check_response_error(response) doc = Hpricot.XML( response.read_body ) @current_status = doc.at("Ping").inner_html end |