Class: EROI::Request::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/eroi/request.rb

Constant Summary collapse

API_URL =
'http://emailer.emailroi.com/dbadmin/xml_post.pl'

Class Method Summary collapse

Class Method Details

.api_available?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'lib/eroi/request.rb', line 25

def self.api_available?
  url = URI.parse(Request::Post::API_URL)
  request = Net::HTTP::Get.new(url.path)
  response = Net::HTTP.start(url.host, url.port) { |http| http.request(request) }
  response.class == Net::HTTPOK
end

.send(client, xml) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/eroi/request.rb', line 32

def self.send(client, xml)
  response = Net::HTTP.post_form(
     URI.parse(API_URL),
     { :user_token => client.user_token,
       :api_password => client.api_password,
       :xml_body => xml }).body
  Response::Post.new(Crack::XML.parse("<Response>#{response}</Response>"))
end