Sha256: f6a7d2b12a836e7de5f7fa5e0070002dd00b5b1800e668ad7cb05911ef182210

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

module RubyPsigate
  class Request

    attr_reader :params
    
    class << self
      def credential
        @@credential
      end

      def credential=(x)
        raise ArgumentError unless x.is_a?(Credential)
        @@credential = x
      end
      
      def storeid
        @@storeid
      end
      
      def storeid=(x)
        @@storeid = x
      end
    end
    
    def initialize(attributes={})
      @request = {}
      @request[:Request] = {}
      
      # Add credentials
      %w( CID UserID Password ).each do |c|
        @request[:Request][c.to_sym] = self.class.credential.send((c.downcase).to_sym)
      end
    end
    
    def params=(hash)
      raise ArgumentError unless hash.is_a?(Hash)
      @params = hash
    end
    
    def post
      begin
        parameters = RubyPsigate::Serializer.new(params, :header => true).to_xml
        connection = RubyPsigate::Connection.new(self.class.credential.endpoint)
        response = connection.post(parameters)
        response = Response.new(response)
      rescue ConnectionError => e
        response = nil
      end
      response
    end

    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pg_recurrence-0.1.1 lib/ruby_psigate/request.rb
pg_recurrence-0.1.0 lib/ruby_psigate/request.rb