Class: SagePayAdminAPI

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

Constant Summary collapse

VERSION =
'0.0.2'

Instance Method Summary collapse

Constructor Details

#initialize(vendor, username, password, live = true, sslverify = true) ⇒ SagePayAdminAPI

Returns a new instance of SagePayAdminAPI.



5
6
7
8
9
10
11
# File 'lib/sagepayadminapi.rb', line 5

def initialize(vendor, username, password, live=true, sslverify=true)
  @vendor    = vendor
  @username  = username
  @password  = password
  @url       = "https://#{ live ? 'live' : 'test' }.sagepay.com/access/access.htm"
  @sslverify = sslverify
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *arguments) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sagepayadminapi.rb', line 13

def method_missing(method_id, *arguments)
  
  uri = URI.parse(@url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  if @sslverify == false
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  
  request = Net::HTTP::Post.new(uri.request_uri)
  request.body = 'XML=' + to_xml(method_id, arguments[0])
  
  response = http.request(request)
  
  XmlSimple.xml_in(response.body, { ForceArray: false })
  
end