Sha256: b9232734a0e9e464bcebebe06dac4eaa5128e24f3f08dd7b232adb8ff5db1bff

Contents?: true

Size: 794 Bytes

Versions: 4

Compression:

Stored size: 794 Bytes

Contents

require 'net/http'
require 'uri'
require 'active_support/all'
# require 'ostruct'
require 'payture/hash'

class Payture::API
  def initialize(host)
    raise ArgumentError, "host is required" if not host
    @host = host
  end

  def host
    @host
  end

  def request(path, merchant, params)
    data      = { VWID: merchant, DATA: params.url_encode }
    # puts "request.data: #{data}"

    uri       = URI::HTTPS.build({ host: @host, path: path })
    puts "URI: #{uri}"
    http      = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    req       = Net::HTTP::Post.new(uri.request_uri)
    req.body  = data.to_query
    # puts "request: #{req}"
    res       = http.request(req)

    # OpenStruct.new(Hash.from_xml(res.body).downcase_key)
    Hash.from_xml(res.body)
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
payture_api-0.2.0 lib/payture/api.rb
payture_api-0.1.9 lib/payture/api.rb
payture_api-0.1.8 lib/payture/api.rb
payture_api-0.1.7 lib/payture/api.rb