Class: OpenSRS::Server
- Inherits:
-
Object
- Object
- OpenSRS::Server
- Defined in:
- lib/opensrs/server.rb
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.
-
#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.
16 17 18 19 20 21 22 23 24 |
# File 'lib/opensrs/server.rb', line 16 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] end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
14 15 16 |
# File 'lib/opensrs/server.rb', line 14 def key @key end |
#logger ⇒ Object
Returns the value of attribute logger.
14 15 16 |
# File 'lib/opensrs/server.rb', line 14 def logger @logger end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
14 15 16 |
# File 'lib/opensrs/server.rb', line 14 def open_timeout @open_timeout end |
#password ⇒ Object
Returns the value of attribute password.
14 15 16 |
# File 'lib/opensrs/server.rb', line 14 def password @password end |
#server ⇒ Object
Returns the value of attribute server.
14 15 16 |
# File 'lib/opensrs/server.rb', line 14 def server @server end |
#timeout ⇒ Object
Returns the value of attribute timeout.
14 15 16 |
# File 'lib/opensrs/server.rb', line 14 def timeout @timeout end |
#username ⇒ Object
Returns the value of attribute username.
14 15 16 |
# File 'lib/opensrs/server.rb', line 14 def username @username end |
Class Method Details
.xml_processor=(name) ⇒ Object
49 50 51 52 |
# File 'lib/opensrs/server.rb', line 49 def self.xml_processor=(name) require "opensrs/xml_processor/#{name.to_s.downcase}" @@xml_processor = OpenSRS::XmlProcessor.const_get("#{name.to_s.capitalize}") end |
Instance Method Details
#call(data = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/opensrs/server.rb', line 26 def call(data = {}) xml = xml_processor.build({ :protocol => "XCP" }.merge!(data)) log('Request', xml, 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) return OpenSRS::Response.new(parsed_response, xml, response.body) rescue Timeout::Error => err raise OpenSRS::TimeoutError, err rescue Errno::ECONNRESET, Errno::ECONNREFUSED => err raise OpenSRS::ConnectionError, err end |
#xml_processor ⇒ Object
45 46 47 |
# File 'lib/opensrs/server.rb', line 45 def xml_processor @@xml_processor end |