Class: OpenSRS::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/opensrs/server.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options = {})
  @server   = URI.parse(options[:server] || "https://rr-n1-tor.opensrs.net:55443/")
  @username = options[:username]
  @password = options[:password]
  @key      = options[:key]
  @timeout  = options[:timeout]
  @open_timeout  = options[:open_timeout]
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



11
12
13
# File 'lib/opensrs/server.rb', line 11

def key
  @key
end

#open_timeoutObject

Returns the value of attribute open_timeout.



11
12
13
# File 'lib/opensrs/server.rb', line 11

def open_timeout
  @open_timeout
end

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/opensrs/server.rb', line 11

def password
  @password
end

#serverObject

Returns the value of attribute server.



11
12
13
# File 'lib/opensrs/server.rb', line 11

def server
  @server
end

#timeoutObject

Returns the value of attribute timeout.



11
12
13
# File 'lib/opensrs/server.rb', line 11

def timeout
  @timeout
end

#usernameObject

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_processorObject



37
38
39
# File 'lib/opensrs/server.rb', line 37

def xml_processor
  @@xml_processor
end