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


16
17
18
19
20
21
22
23
24
# File 'lib/opensrs/server.rb', line 16

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]
  @logger   = options[:logger]
end

Instance Attribute Details

#keyObject

Returns the value of attribute key


14
15
16
# File 'lib/opensrs/server.rb', line 14

def key
  @key
end

#loggerObject

Returns the value of attribute logger


14
15
16
# File 'lib/opensrs/server.rb', line 14

def logger
  @logger
end

#open_timeoutObject

Returns the value of attribute open_timeout


14
15
16
# File 'lib/opensrs/server.rb', line 14

def open_timeout
  @open_timeout
end

#passwordObject

Returns the value of attribute password


14
15
16
# File 'lib/opensrs/server.rb', line 14

def password
  @password
end

#serverObject

Returns the value of attribute server


14
15
16
# File 'lib/opensrs/server.rb', line 14

def server
  @server
end

#timeoutObject

Returns the value of attribute timeout


14
15
16
# File 'lib/opensrs/server.rb', line 14

def timeout
  @timeout
end

#usernameObject

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_processorObject


45
46
47
# File 'lib/opensrs/server.rb', line 45

def xml_processor
  @@xml_processor
end