39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/infunnel_cli/cli/form.rb', line 39
def data(form_id)
start_at = options[:full] ? 0 : Time.now - (5*360*24*3600)
fetch_options = { start_at: start_at, account: options[:account]}
form = EloquaApiService::Form.new(account: options[:account]).find(id: form_id)
elements = form[:elements]
unless options[:csv]
puts black on_white "Form name: #{form[:name]}"
puts black on_white "Id: #{form[:id]}"
puts black on_white "Submits after: #{start_at}"
end
submissions = data_fetch(form_id: form_id, options: fetch_options)
if options[:count]
puts submissions.size
return
end
if options[:raw]
puts submissions.to_json
return
end
first = true
if options[:live]
while true
new_data = data_fetch(form_id: form_id, options: fetch_options)
data_print(submissions: new_data, elements: elements) if first
only_new = new_data.reject { |s| submissions.map{ |old| old[:id] }.include?(s[:id]) }
data_print(submissions: only_new, elements: elements) if only_new != submissions && !first
submissions = new_data
first = false
sleep 7
end
else
data_print(submissions: submissions, elements: elements, options: { csv: options[:csv] } )
if options[:full]
puts "Total submissions: #{submissions.count}"
end
end
end
|