Last active
August 29, 2015 14:07
-
-
Save vijendra/9b31e18ebc7ec97bc6c4 to your computer and use it in GitHub Desktop.
Parse wufoo callback url data in rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Parse to get {"Location"=>"Field1", "First"=>"Field104", "Last"=>"Field105", "Email"=>"Field106"} Don't forget to check "Include Field and Form Structures with Entry Data (?)" in wufoo webhook setting. | |
title_to_labels = {} | |
fields_structure = MultiJson.decode(data['FieldStructure']) | |
fields_structure["Fields"].each do |field_structure| | |
unless field_structure.keys.include?('SubFields') | |
title_to_labels[ field_structure["Title"] ] = field_structure["ID"] | |
else | |
field_structure["SubFields"].each do |sub_field_structure| | |
title_to_labels[ sub_field_structure["Label"] ] = sub_field_structure["ID"] | |
end | |
end | |
end | |
# Get values for each field | |
values = Hash[title_to_labels.collect{ |field| | |
[field[0].gsub(/\s+/, "_").delete('^a-zA-Z0-9_').downcase.to_sym, params[field[1]] ] | |
}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment