Sha256: 04c28d8f6884adec7523f5a32e3953653a4e4f3efadb5d9e2572b60371918c51

Contents?: true

Size: 482 Bytes

Versions: 12

Compression:

Stored size: 482 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

12 entries across 12 versions & 1 rubygems

Version Path
activemerchant-1.114.0 lib/active_merchant/post_data.rb
activemerchant-1.113.0 lib/active_merchant/post_data.rb
activemerchant-1.112.0 lib/active_merchant/post_data.rb
activemerchant-1.111.0 lib/active_merchant/post_data.rb
activemerchant-1.110.0 lib/active_merchant/post_data.rb
activemerchant-1.109.0 lib/active_merchant/post_data.rb
activemerchant-1.108.0 lib/active_merchant/post_data.rb
activemerchant-1.107.4 lib/active_merchant/post_data.rb
activemerchant-1.107.3 lib/active_merchant/post_data.rb
activemerchant-1.107.2 lib/active_merchant/post_data.rb
activemerchant-1.107.1 lib/active_merchant/post_data.rb
activemerchant-1.106.0 lib/active_merchant/post_data.rb