Sha256: 2df4ccc2abc9a5aadd0eebe96bf673aaabea9c46b525c5075d9b0df6ed6ecb1b

Contents?: true

Size: 793 Bytes

Versions: 6

Compression:

Stored size: 793 Bytes

Contents

module Xendit
  class JSONSerializer
    class << self
      # If you using Rails then it will call ActiveSupport::JSON.encode
      # Otherwise JSON.pretty_generate
      def encode(params)
        if defined?(ActiveSupport) && defined?(ActiveSupport::JSON)
          ActiveSupport::JSON.encode(params)
        else
          require 'json' unless defined?(JSON)
          JSON.pretty_generate(params)
        end
      end

      # If you using Rails then it will call ActiveSupport::JSON.decode
      # Otherwise JSON.parse
      def decode(params)
        if defined?(ActiveSupport) && defined?(ActiveSupport::JSON)
          ActiveSupport::JSON.decode(params)
        else
          require 'json' unless defined?(JSON)
          JSON.parse(params)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
xendit-client-0.3.1 lib/xendit/json_serializer.rb
xendit-client-0.2.1 lib/xendit/json_serializer.rb
xendit-client-0.2.0 lib/xendit/json_serializer.rb
xendit-client-0.1.3 lib/xendit/json_serializer.rb
xendit-client-0.1.1 lib/xendit/json_serializer.rb
xendit-client-0.1.0 lib/xendit/json_serializer.rb