Sha256: 82a0993d0ceaaef10031c5614d209ed331dab0fbfc48fc9fbd428e2183c1e0d7

Contents?: true

Size: 483 Bytes

Versions: 4

Compression:

Stored size: 483 Bytes

Contents

require 'cgi'

module ActiveMerchant
  class PostData < Hash
    class_attribute :required_fields, :instance_writer => false
    self.required_fields = []

    def []=(key, value)
      return if value.blank? && !required?(key)
      super
    end

    def to_post_data
      collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&')
    end

    alias_method :to_s, :to_post_data

    private
    def required?(key)
      required_fields.include?(key)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activemerchant-1.83.0 lib/active_merchant/post_data.rb
activemerchant-1.82.0 lib/active_merchant/post_data.rb
activemerchant-1.81.0 lib/active_merchant/post_data.rb
activemerchant-1.80.0 lib/active_merchant/post_data.rb