Sha256: 04efd4aeb11e3d91be1cc6b86dfb9c1023fd13c95d925747a82d59c06fbc87ea

Contents?: true

Size: 1.3 KB

Versions: 5

Compression:

Stored size: 1.3 KB

Contents

module Bitmovin::Helpers
  def result(response)
    Bitmovin::Helpers.result(response)
  end

  def self.result(response)
    (JSON.parse(response.body))['data']['result']
  end

  def camelize_hash(hash)
    ret = Hash.new
    hash.each do |key, value|
      if value.is_a?(Hash)
        ret[ActiveSupport::Inflector.camelize(key, false)] = camelize_hash(value)
      else
        ret[ActiveSupport::Inflector.camelize(key, false)] = value
      end
    end
    ret
  end

  def underscore_hash(hash)
    if !hash.instance_of? Hash
      return hash
    end

    ret = Hash.new
    hash.each do |key, value|
      if value.instance_of?(Hash)
        value = underscore_hash(value)
      end
      if (value.instance_of?(Array))
        value = value.map { |v| underscore_hash(v) }
      end
      new_key = ActiveSupport::Inflector.underscore(key)
      new_key = new_key.to_sym if key.instance_of? Symbol
      ret[new_key] = value
    end
    ret
  end

  def hash_to_struct(hash)
    if !hash.instance_of? Hash
      return hash
    end

    ret = Hash.new
    hash.each do |key, value|
      if value.instance_of?(Hash)
        value = hash_to_struct(value)
      end
      if value.instance_of?(Array)
        value = value.map { |v| hash_to_struct(v) }
      end
      ret[key] = value
    end
    OpenStruct.new(ret)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bitmovin-ruby-0.9.1 lib/bitmovin/helpers.rb
bitmovin-ruby-0.9.0 lib/bitmovin/helpers.rb
bitmovin-ruby-0.8.1 lib/bitmovin/helpers.rb
bitmovin-ruby-0.8.0 lib/bitmovin/helpers.rb
bitmovin-ruby-0.7.0 lib/bitmovin/helpers.rb