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.
-
#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.
13 14 15 16 17 18 19 20 |
# File 'lib/opensrs/server.rb', line 13 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] end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
11 12 13 |
# File 'lib/opensrs/server.rb', line 11 def key @key end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
11 12 13 |
# File 'lib/opensrs/server.rb', line 11 def open_timeout @open_timeout end |
#password ⇒ Object
Returns the value of attribute password.
11 12 13 |
# File 'lib/opensrs/server.rb', line 11 def password @password end |
#server ⇒ Object
Returns the value of attribute server.
11 12 13 |
# File 'lib/opensrs/server.rb', line 11 def server @server end |
#timeout ⇒ Object
Returns the value of attribute timeout.
11 12 13 |
# File 'lib/opensrs/server.rb', line 11 def timeout @timeout end |
#username ⇒ Object
Returns the value of attribute username.
11 12 13 |
# File 'lib/opensrs/server.rb', line 11 def username @username end |
Class Method Details
.xml_processor=(name) ⇒ Object
41 42 43 44 |
# File 'lib/opensrs/server.rb', line 41 def self.xml_processor=(name) require File.dirname(__FILE__) + "/xml_processor/#{name.to_s.downcase}" @@xml_processor = OpenSRS::XmlProcessor.const_get("#{name.to_s.capitalize}") end |
Instance Method Details
#call(data = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/opensrs/server.rb', line 22 def call(data = {}) xml = xml_processor.build({ :protocol => "XCP" }.merge!(data)) begin response = http.post(server_path, xml, headers(xml)) 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 end |
#xml_processor ⇒ Object
37 38 39 |
# File 'lib/opensrs/server.rb', line 37 def xml_processor @@xml_processor end |