Sha256: aecb65323c706d15f9deeb41e4c19a787453a4e14f495c4d2ba5f403ce479718

Contents?: true

Size: 776 Bytes

Versions: 16

Compression:

Stored size: 776 Bytes

Contents

module Appsignal
  class ZippedPayload
    attr_reader :body

    def initialize(given_body)
      @body = Zlib::Deflate.deflate(
        Appsignal::ZippedPayload.json_generate(given_body),
        Zlib::BEST_SPEED
      )
    end

    protected

    def self.json_generate(given_body)
      JSON.generate(jsonify(given_body))
    end

    def self.jsonify(value)
      case value
      when String
        value.encode(
          'utf-8',
          :invalid => :replace,
          :undef   => :replace
        )
      when Numeric, NilClass, TrueClass, FalseClass
        value
      when Hash
        Hash[value.map { |k, v| [jsonify(k), jsonify(v)] }]
      when Array
        value.map { |v| jsonify(v) }
      else
        jsonify(value.to_s)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
appsignal-0.11.18 lib/appsignal/zipped_payload.rb
appsignal-0.11.17 lib/appsignal/zipped_payload.rb
appsignal-0.11.16 lib/appsignal/zipped_payload.rb
appsignal-0.11.15 lib/appsignal/zipped_payload.rb
appsignal-0.11.14 lib/appsignal/zipped_payload.rb
appsignal-0.11.14.beta.1 lib/appsignal/zipped_payload.rb
appsignal-0.11.13 lib/appsignal/zipped_payload.rb
appsignal-0.11.13.beta.4 lib/appsignal/zipped_payload.rb
appsignal-0.11.13.beta.3 lib/appsignal/zipped_payload.rb
appsignal-0.11.13.beta.2 lib/appsignal/zipped_payload.rb
appsignal-0.11.13.beta.1 lib/appsignal/zipped_payload.rb
appsignal-0.11.13.beta.0 lib/appsignal/zipped_payload.rb
appsignal-0.11.12 lib/appsignal/zipped_payload.rb
appsignal-0.11.11 lib/appsignal/zipped_payload.rb
appsignal-0.11.10 lib/appsignal/zipped_payload.rb
appsignal-0.11.10.beta.2 lib/appsignal/zipped_payload.rb