module Icasework::Resource::Payload
Converts payload for iCasework API endpoints into a flat/titlecase keys
Public Class Methods
process(data)
click to toggle source
# File lib/icasework/resource/payload.rb, line 10 def process(data) case data when Hash nested_to_flat_keys(convert_keys(data)) else data end end
Private Class Methods
convert_keys(hash)
click to toggle source
converts: :foo_bar into: 'FooBar'
# File lib/icasework/resource/payload.rb, line 33 def convert_keys(hash) hash.each_with_object({}) do |(key, value), all| converted_key = key if valid_keys.include?(key.to_s) converted_key ||= key.to_s.gsub(/(?:^|_)([a-z])/i) do Regexp.last_match(1).upcase end all[converted_key.to_s] = process(value) end end
nested_to_flat_keys(hash, key = [])
click to toggle source
converts { 'foo' => { 'bar' => 'baz' } } into: { 'foo.bar' => 'baz' }
# File lib/icasework/resource/payload.rb, line 23 def nested_to_flat_keys(hash, key = []) return { key.join('.') => process(hash) } unless hash.is_a?(Hash) hash.inject({}) do |h, v| h.merge!(nested_to_flat_keys(v[-1], key + [v[0]])) end end
valid_keys()
click to toggle source
# File lib/icasework/resource/payload.rb, line 44 def valid_keys %w[db fromseq toseq grant_type assertion access_token] end