Sha256: 3ceebcfd05e18e28c1569bb47b406c13a7c31d6dea41ff9ce800874d87b8a50d

Contents?: true

Size: 837 Bytes

Versions: 16

Compression:

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

16 entries across 16 versions & 1 rubygems

Version Path
app_store_connect-0.38.0 lib/app_store_connect/client/utils.rb
app_store_connect-0.37.0 lib/app_store_connect/client/utils.rb
app_store_connect-0.36.0 lib/app_store_connect/client/utils.rb
app_store_connect-0.35.0 lib/app_store_connect/client/utils.rb
app_store_connect-0.34.0 lib/app_store_connect/client/utils.rb
app_store_connect-0.33.0 lib/app_store_connect/client/utils.rb
app_store_connect-0.32.0 lib/app_store_connect/client/utils.rb
app_store_connect-0.30.0 lib/app_store_connect/client/utils.rb
app_store_connect-0.29.0 lib/app_store_connect/client/utils.rb
app_store_connect-0.28.0 lib/app_store_connect/client/utils.rb
app_store_connect-0.27.0 lib/app_store_connect/client/utils.rb
app_store_connect-0.26.0 lib/app_store_connect/client/utils.rb
app_store_connect-0.25.0 lib/app_store_connect/client/utils.rb
app_store_connect-0.23.0 lib/app_store_connect/client/utils.rb
app_store_connect-0.22.0 lib/app_store_connect/client/utils.rb
app_store_connect-0.21.0 lib/app_store_connect/client/utils.rb