class SterlingApi::RemoteActions::Request

Attributes

body[RW]
headers[RW]
http_process[RW]
proxy[RW]
proxy_port[RW]
url[RW]

Public Class Methods

new(options={}) click to toggle source
# File lib/sterling_api/remote_actions.rb, line 62
def initialize(options={})
  default_options = {
    :body       => nil,
    :headers    => {'Content-Type' => 'application/xml', 'Accept' => 'application/xml'},
    :proxy      => nil,
    :proxy_port => nil,
  }
  default_options.merge!(options)
  
  self.proxy      = default_options[:proxy]
  self.proxy_port = default_options[:proxy_port]
  self.headers    = default_options[:headers]
  self.body       = default_options[:body]
  self.url        = default_options[:url]
end

Public Instance Methods

host_from_url() click to toggle source
# File lib/sterling_api/remote_actions.rb, line 78
def host_from_url
  self.url.match(%r{(?:https?://)?([^/]+)})[1].gsub(/:\d+$/, "") rescue nil
end
is_ssl?() click to toggle source
# File lib/sterling_api/remote_actions.rb, line 82
def is_ssl?
  !!(self.url =~ /^https:/i)
end
port_from_url() click to toggle source
# File lib/sterling_api/remote_actions.rb, line 86
def port_from_url
  if m = self.url.match(%r{(?:(http|https)://)[^:]+:(\d+)/?})
    return m[2].to_i
  elsif self.url =~ /^https:/i
    return 443
  else
    80
  end
end
send_request() click to toggle source
# File lib/sterling_api/remote_actions.rb, line 96
def send_request
  self.http_process = Net::HTTP.new( host_from_url, port_from_url, self.proxy, self.proxy_port )
  self.http_process.use_ssl = is_ssl?

  http_process.start
  resp = http_process.post(self.url, self.body, self.headers)
  ret_val = false
  case resp
  when Net::HTTPSuccess, Net::HTTPRedirection
    ret_val = true
  else
    ret_val = false
  end
  return SterlingApi::RemoteActions::Response.new(ret_val, resp)
end