Class: RealEx::Client

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

Class Method Summary collapse

Class Method Details

.build_hash(hash_string_items) ⇒ Object



9
10
11
12
# File 'lib/real_ex/client.rb', line 9

def build_hash(hash_string_items)
  first_hash = Digest::SHA1.hexdigest(hash_string_items.join('.'))
  Digest::SHA1.hexdigest("#{first_hash}.#{RealEx::Config.shared_secret}")
end

.build_xml(type, &block) ⇒ Object



14
15
16
17
18
19
# File 'lib/real_ex/client.rb', line 14

def build_xml(type, &block)
  xml = Builder::XmlMarkup.new(:indent => 2)
  xml.instruct!
  xml.request(:type => type, :timestamp => timestamp) { |r| block.call(r) }
  xml.target!
end

.call(url, xml) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/real_ex/client.rb', line 21

def call(url,xml)
  h = Net::HTTP.new('epage.payandshop.com', 443)
  h.use_ssl = true
  response = h.request_post(url, xml)
  result = Nokogiri.XML(response.body)
  result
end

.parse(response) ⇒ Object

Raises:

  • (RealExError)


29
30
31
32
# File 'lib/real_ex/client.rb', line 29

def parse(response)
  status = (response/:result).inner_html
  raise RealExError, "#{(response/:message).inner_html} (#{status})" unless status == "00"
end

.timestampObject



5
6
7
# File 'lib/real_ex/client.rb', line 5

def timestamp
  Time.now.strftime('%Y%m%d%H%M%S')
end