Class: SterlingApi::RemoteActions::Request
- Inherits:
-
Object
- Object
- SterlingApi::RemoteActions::Request
- Defined in:
- lib/sterling_api/remote_actions.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#http_process ⇒ Object
Returns the value of attribute http_process.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #host_from_url ⇒ Object
-
#initialize(options = {}) ⇒ Request
constructor
A new instance of Request.
- #is_ssl? ⇒ Boolean
- #port_from_url ⇒ Object
- #send_request ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Request
Returns a new instance of Request.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/sterling_api/remote_actions.rb', line 62 def initialize(={}) = { :body => nil, :headers => {'Content-Type' => 'application/xml', 'Accept' => 'application/xml'}, :proxy => nil, :proxy_port => nil, } .merge!() self.proxy = [:proxy] self.proxy_port = [:proxy_port] self.headers = [:headers] self.body = [:body] self.url = [:url] end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
58 59 60 |
# File 'lib/sterling_api/remote_actions.rb', line 58 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
55 56 57 |
# File 'lib/sterling_api/remote_actions.rb', line 55 def headers @headers end |
#http_process ⇒ Object
Returns the value of attribute http_process.
59 60 61 |
# File 'lib/sterling_api/remote_actions.rb', line 59 def http_process @http_process end |
#proxy ⇒ Object
Returns the value of attribute proxy.
56 57 58 |
# File 'lib/sterling_api/remote_actions.rb', line 56 def proxy @proxy end |
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
57 58 59 |
# File 'lib/sterling_api/remote_actions.rb', line 57 def proxy_port @proxy_port end |
#url ⇒ Object
Returns the value of attribute url.
60 61 62 |
# File 'lib/sterling_api/remote_actions.rb', line 60 def url @url end |
Instance Method Details
#host_from_url ⇒ Object
78 79 80 |
# 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? ⇒ Boolean
82 83 84 |
# File 'lib/sterling_api/remote_actions.rb', line 82 def is_ssl? !!(self.url =~ /^https:/i) end |
#port_from_url ⇒ Object
86 87 88 89 90 91 92 93 94 |
# 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 ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# 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 |