Class: OpenSRS::Server
- Inherits:
-
Object
- Object
- OpenSRS::Server
- Defined in:
- lib/opensrs/server.rb
Overview
Server
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#password ⇒ Object
Returns the value of attribute password.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#server ⇒ Object
Returns the value of attribute server.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #call(data = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
- #xml_processor ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/opensrs/server.rb', line 19 def initialize( = {}) @server = URI.parse([:server] || 'https://rr-n1-tor.opensrs.net:55443/') @username = [:username] @password = [:password] @key = [:key] @timeout = [:timeout] @open_timeout = [:open_timeout] @logger = [:logger] @proxy = URI.parse([:proxy]) if [:proxy] @sanitize_request = [:sanitize_request] OpenSRS::SanitizableString.enable_sanitization = @sanitize_request end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
17 18 19 |
# File 'lib/opensrs/server.rb', line 17 def key @key end |
#logger ⇒ Object
Returns the value of attribute logger.
17 18 19 |
# File 'lib/opensrs/server.rb', line 17 def logger @logger end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
17 18 19 |
# File 'lib/opensrs/server.rb', line 17 def open_timeout @open_timeout end |
#password ⇒ Object
Returns the value of attribute password.
17 18 19 |
# File 'lib/opensrs/server.rb', line 17 def password @password end |
#proxy ⇒ Object
Returns the value of attribute proxy.
17 18 19 |
# File 'lib/opensrs/server.rb', line 17 def proxy @proxy end |
#server ⇒ Object
Returns the value of attribute server.
17 18 19 |
# File 'lib/opensrs/server.rb', line 17 def server @server end |
#timeout ⇒ Object
Returns the value of attribute timeout.
17 18 19 |
# File 'lib/opensrs/server.rb', line 17 def timeout @timeout end |
#username ⇒ Object
Returns the value of attribute username.
17 18 19 |
# File 'lib/opensrs/server.rb', line 17 def username @username end |
Class Method Details
.xml_processor=(name) ⇒ Object
57 58 59 60 |
# File 'lib/opensrs/server.rb', line 57 def self.xml_processor=(name) require "opensrs/xml_processor/#{name.to_s.downcase}" @@xml_processor = OpenSRS::XmlProcessor.const_get(name.to_s.capitalize.to_s) end |
Instance Method Details
#call(data = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/opensrs/server.rb', line 33 def call(data = {}) xml = xml_processor.build({ protocol: 'XCP' }.merge!(data)) log('Request', xml.sanitized, data) begin response = http.post(server_path, xml, headers(xml)) log('Response', response.body, data) rescue Net::HTTPBadResponse raise OpenSRS::BadResponse, 'Received a bad response from OpenSRS. Please check that your IP address is added to the whitelist, and try again.' end parsed_response = xml_processor.parse(response.body) OpenSRS::Response.new(parsed_response, xml.sanitized, response.body) rescue Timeout::Error => e raise OpenSRS::TimeoutError, e rescue Errno::ECONNRESET, Errno::ECONNREFUSED => e raise OpenSRS::ConnectionError, e end |
#xml_processor ⇒ Object
53 54 55 |
# File 'lib/opensrs/server.rb', line 53 def xml_processor @@xml_processor end |