Sha256: 29f3707c25d488365cb168400a1f84993f67f4d263db8feac3973b88fcd491fe

Contents?: true

Size: 811 Bytes

Versions: 1

Compression:

Stored size: 811 Bytes

Contents

# frozen_string_literal: true

module AppStoreConnect
  class Client
    class Utils
      def self.encode(hash)
        hash
          .deep_transform_keys { |s| s.to_s.camelize(:lower) }
          .to_json
      end

      # Right now this only supports gzip and json responses.
      # If you need to support a different type then add it.
      def self.decode(string, content_type='application/json')
        decoded_data = nil

        case content_type
        when 'application/a-gzip'
          sio = StringIO.new string
          gz = Zlib::GzipReader.new sio
          decoded_data = gz.read()
        else # Assume JSON
          decoded_data = JSON
            .parse(string)
            .deep_transform_keys { |k| k.underscore.to_sym }
        end

        decoded_data
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
app_store_connect-0.20.0 lib/app_store_connect/client/utils.rb