Class: RBET::Client

Inherits:
Object
  • Object
show all
Includes:
Renderable
Defined in:
lib/rbet/client.rb

Direct Known Subclasses

List, Subscriber, Tracker, TriggeredSend

Instance Attribute Summary collapse

Instance Method Summary collapse

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,options={})
  @username = username
  @password = password
  service_url = options[:service_url] ? options[: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 = options.key?(:use_ssl) ? options[:use_ssl] : true
  @url.set_debug_output options.key?(:debug_output) ? options[:debug_output] : nil
  @headers = {
    'Content-Type' => 'application/x-www-form-urlencoded',
    'Connection' => 'close'
  }
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



32
33
34
# File 'lib/rbet/client.rb', line 32

def headers
  @headers
end

#passwordObject (readonly)

Returns the value of attribute password.



32
33
34
# File 'lib/rbet/client.rb', line 32

def password
  @password
end

#usernameObject (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

Returns:

  • (Boolean)


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

Yields:

  • (@system)


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.authorization 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

#statusObject

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