Module: Bitmovin::Helpers

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.result(response) ⇒ Object



6
7
8
# File 'lib/bitmovin/helpers.rb', line 6

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

Instance Method Details

#camelize_hash(hash) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/bitmovin/helpers.rb', line 10

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

#hash_to_struct(hash) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bitmovin/helpers.rb', line 38

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

#result(response) ⇒ Object



2
3
4
# File 'lib/bitmovin/helpers.rb', line 2

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

#underscore_hash(hash) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bitmovin/helpers.rb', line 18

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