gooddata_eloqua 0.0.5 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gooddata_eloqua/helpers/request.rb +223 -86
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bfdd680536bdc65c7003fdc816748ebf2006d9e
|
4
|
+
data.tar.gz: 62904c80d1487d0bb8b8553c62aaa5d49f25a84f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a8f3d93a69619c86c4b4c0dda011d72bb2d55be269e618ee170628ed76bbb19979d94d993fef30c44331eb17886a45bb8c5d718d2259f9c1e320683ef31b8f2
|
7
|
+
data.tar.gz: 9e3a548f9ce3b9940973ed8e5a044375c9b5e9e924512ba73a689a66f1160b30b2e84d9d1ba2b6980917e946064a39011eaf75614ce148ee4d90af7bf2021896
|
@@ -29,9 +29,9 @@ class GoodDataEloqua::Request
|
|
29
29
|
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
33
|
-
|
32
|
+
def download_all_ids_return_csv(file_name, config={})
|
34
33
|
|
34
|
+
puts "#{Time.now} => Downloading IDs..."
|
35
35
|
if file_name
|
36
36
|
fd = IO.sysopen("./downloads/#{file_name}", 'w+')
|
37
37
|
end
|
@@ -42,22 +42,47 @@ class GoodDataEloqua::Request
|
|
42
42
|
pages = first_download['total'].to_i
|
43
43
|
total = (pages/1000).round
|
44
44
|
|
45
|
-
total = 1 if total == 0
|
45
|
+
total = 1 if total == 0 || total < 1
|
46
46
|
|
47
47
|
if total == 1
|
48
48
|
|
49
|
+
count = 0
|
49
50
|
first_download['elements'].each { |record|
|
51
|
+
count += 1
|
50
52
|
csv << [record['id']]
|
51
53
|
}
|
52
54
|
|
55
|
+
puts "#{Time.now} => #{count} IDs extracted."
|
56
|
+
puts "#{Time.now} => Flushing IO to \"./downloads/#{file_name}\"\n"
|
53
57
|
csv.flush
|
54
58
|
|
55
|
-
puts "\n#{Time.now} => Flushing IO (#{@session_csv}.id)..."
|
56
|
-
|
57
59
|
else
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
+
iterations = []
|
62
|
+
total.times { |i| iterations << i }
|
63
|
+
iterations << total
|
64
|
+
|
65
|
+
puts "#{Time.now} => #{iterations.length} pages queued for download."
|
66
|
+
count = iterations.length
|
67
|
+
mutex = Mutex.new
|
68
|
+
iterations.pmap { |page|
|
69
|
+
|
70
|
+
response = self.get_all_by_page(page)
|
71
|
+
print "\r#{Time.now} => Extracting page: #{page} of #{count}\s\s\s"
|
72
|
+
|
73
|
+
mutex.synchronize {
|
74
|
+
count -= 1
|
75
|
+
response['elements'].each { |element|
|
76
|
+
csv << [element['id']]
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
}
|
81
|
+
|
82
|
+
csv.flush
|
83
|
+
puts "#{Time.now} => #{count} IDs extracted."
|
84
|
+
|
85
|
+
puts "\n#{Time.now} => Flushing IO to \"./downloads/#{file_name}\"\n"
|
61
86
|
|
62
87
|
end
|
63
88
|
|
@@ -65,98 +90,197 @@ class GoodDataEloqua::Request
|
|
65
90
|
|
66
91
|
end
|
67
92
|
|
68
|
-
def
|
93
|
+
def get_complete_profile_from_ids_csv(csv, config = {})
|
94
|
+
|
95
|
+
return unless File.exists? "./downloads/#{csv}"
|
69
96
|
|
97
|
+
puts "#{Time.now} => Extracting complete profile from IDs..."
|
70
98
|
if csv
|
71
99
|
fd = IO.sysopen("./downloads/#{csv}", 'r')
|
72
100
|
end
|
73
101
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
csv = CSV.new(IO.new(write_fd))
|
79
|
-
pool = Pool.new
|
80
|
-
|
102
|
+
file_name = "./downloads/#{@session_id}_complete_profile.csv"
|
103
|
+
write_fd = IO.sysopen(file_name, 'w+')
|
104
|
+
@csv = CSV.new(IO.new(write_fd))
|
105
|
+
mutex = Mutex.new
|
81
106
|
CSV.open(fd) do |read_csv|
|
82
107
|
|
83
108
|
ids = read_csv.map { |row|
|
84
109
|
row[0]
|
85
110
|
}
|
86
111
|
|
87
|
-
|
112
|
+
return if ids.empty?
|
88
113
|
|
89
|
-
|
114
|
+
headers = nil
|
115
|
+
rows = []
|
116
|
+
count = 0
|
90
117
|
|
91
|
-
|
118
|
+
def process_batch_of_rows batch
|
92
119
|
|
93
|
-
|
120
|
+
batch.each { |row|
|
121
|
+
@csv << row
|
122
|
+
}
|
94
123
|
|
95
|
-
|
124
|
+
end
|
96
125
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
126
|
+
ids.pmap { |id|
|
127
|
+
count += 1
|
128
|
+
response = self.get_one_by_id(id)
|
129
|
+
|
130
|
+
case response['type']
|
131
|
+
when "Contact"
|
132
|
+
keys = 'fieldValues'
|
133
|
+
when "Campaign"
|
134
|
+
keys = 'elements'
|
135
|
+
when "Email"
|
136
|
+
keys = 'htmlContent'
|
137
|
+
when "Form"
|
138
|
+
keys = 'elements'
|
139
|
+
else
|
140
|
+
keys = 'elements'
|
101
141
|
end
|
102
142
|
|
103
|
-
if
|
104
|
-
time_readable = "#{((estimated_time/60)/60).round(2)} hours"
|
105
|
-
|
106
|
-
elsif (estimated_time/60) < 60 && (estimated_time/60) > 1 && estimated_time != 0
|
107
|
-
time_readable = "#{(estimated_time/60).round(2)} minutes"
|
143
|
+
if response.empty?
|
108
144
|
|
109
|
-
|
110
|
-
time_readable = "#{(estimated_time).round(2)} seconds"
|
145
|
+
payload = [[id]]
|
111
146
|
|
112
147
|
else
|
113
|
-
time_readable = 'Estimating...'
|
114
148
|
|
115
|
-
|
149
|
+
if headers == nil
|
116
150
|
|
117
|
-
|
151
|
+
begin
|
152
|
+
unless response[keys].empty?
|
118
153
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
response = self.get_one_by_id(i)
|
123
|
-
csv << response.values
|
124
|
-
csv.flush
|
125
|
-
print "\r#{Time.now} => IDs Remaing: #{ids.length} - Complete: #{time_readable} - Thread Pool: #{pool.active_threads} \s\s\s\s"
|
126
|
-
}
|
127
|
-
}
|
154
|
+
element_keys = response[keys][0].keys.map { |key|
|
155
|
+
"element_#{key}"
|
156
|
+
}
|
128
157
|
|
129
|
-
|
158
|
+
else
|
159
|
+
element_keys = []
|
160
|
+
end
|
130
161
|
|
131
|
-
|
132
|
-
|
133
|
-
|
162
|
+
headers = response.keys + element_keys
|
163
|
+
|
164
|
+
rescue NoMethodError
|
165
|
+
headers = [id]
|
166
|
+
end
|
134
167
|
|
135
|
-
if elapsed_times.length < 10
|
136
|
-
elapsed_times << estimated_batch_time
|
137
|
-
elsif elapsed_times.length > 50
|
138
|
-
40.times do
|
139
|
-
elapsed_times.pop
|
140
168
|
end
|
141
|
-
end
|
142
169
|
|
170
|
+
if response[keys].is_a? Array
|
171
|
+
if response[keys].empty?
|
172
|
+
payload = [response.values]
|
173
|
+
else
|
174
|
+
payload = []
|
175
|
+
|
176
|
+
response[keys].each { |element|
|
177
|
+
payload << response.values + element.values
|
178
|
+
}
|
179
|
+
end
|
180
|
+
else
|
181
|
+
payload = [response]
|
182
|
+
end
|
143
183
|
|
144
|
-
if pool.active_threads > 21
|
145
|
-
sleep 3
|
146
184
|
end
|
147
185
|
|
148
|
-
|
186
|
+
rows << payload
|
187
|
+
print "\r#{Time.now} => IDs Remaining: #{ids.length-count} Pool: #{rows.length}-#{Thread.current}"
|
188
|
+
}
|
149
189
|
|
190
|
+
count = rows.length
|
191
|
+
rows.pmap { |row|
|
192
|
+
print "\r#{Time.now} => Dumping pool to CSV #{count}\s\s\s\s"
|
193
|
+
count -= 1
|
194
|
+
@csv << row
|
195
|
+
}
|
150
196
|
|
151
|
-
|
197
|
+
@csv.flush
|
152
198
|
|
199
|
+
puts "\n#{Time.now} => Flushing IO to \"#{file_name}\"\n"
|
153
200
|
|
201
|
+
end
|
154
202
|
|
155
|
-
|
203
|
+
file_name
|
204
|
+
|
205
|
+
#
|
206
|
+
#
|
207
|
+
# CSV.open(fd) do |read_csv|
|
208
|
+
#
|
209
|
+
#
|
210
|
+
#
|
211
|
+
# puts "#{Time.now} => Extracted from CSV: #{ids.length}\n"
|
212
|
+
#
|
213
|
+
# elapsed_times = []
|
214
|
+
#
|
215
|
+
# loop do
|
216
|
+
#
|
217
|
+
# batch = ids.slice!(1..20)
|
218
|
+
#
|
219
|
+
# started_batch = Time.now
|
220
|
+
#
|
221
|
+
# if elapsed_times.length > 5
|
222
|
+
# estimated_time = elapsed_times.inject{ |sum, el| sum + el }.to_f / elapsed_times.size
|
223
|
+
# else
|
224
|
+
# estimated_time = 0
|
225
|
+
# end
|
226
|
+
#
|
227
|
+
# if (estimated_time/60) > 60 && estimated_time != 0
|
228
|
+
# time_readable = "#{((estimated_time/60)/60).round(2)} hours"
|
229
|
+
#
|
230
|
+
# elsif (estimated_time/60) < 60 && (estimated_time/60) > 1 && estimated_time != 0
|
231
|
+
# time_readable = "#{(estimated_time/60).round(2)} minutes"
|
232
|
+
#
|
233
|
+
# elsif (estimated_time/60) > 0 && estimated_time != 0
|
234
|
+
# time_readable = "#{(estimated_time).round(2)} seconds"
|
235
|
+
#
|
236
|
+
# else
|
237
|
+
# time_readable = 'Estimating...'
|
238
|
+
#
|
239
|
+
# end
|
240
|
+
#
|
241
|
+
# break unless batch.length > 0 && pool.list.length
|
242
|
+
#
|
243
|
+
# #
|
244
|
+
# batch.each { |i|
|
245
|
+
# pool.thread {
|
246
|
+
# response = self.get_one_by_id(i)
|
247
|
+
# csv << response.values
|
248
|
+
# csv.flush
|
249
|
+
# print "\r#{Time.now} => IDs Remaing: #{ids.length} - Complete: #{time_readable} - Thread Pool: #{pool.active_threads} \s\s\s\s"
|
250
|
+
# }
|
251
|
+
# }
|
252
|
+
#
|
253
|
+
# ended_batch = Time.now
|
254
|
+
#
|
255
|
+
# elapsed_time = ended_batch - started_batch
|
256
|
+
# number_of_estimated_chunks = ids.length/20
|
257
|
+
# estimated_batch_time = (elapsed_time*number_of_estimated_chunks).round
|
258
|
+
#
|
259
|
+
# if elapsed_times.length < 10
|
260
|
+
# elapsed_times << estimated_batch_time
|
261
|
+
# elsif elapsed_times.length > 50
|
262
|
+
# 40.times do
|
263
|
+
# elapsed_times.pop
|
264
|
+
# end
|
265
|
+
# end
|
266
|
+
#
|
267
|
+
#
|
268
|
+
# if pool.active_threads > 21
|
269
|
+
# sleep 3
|
270
|
+
# end
|
271
|
+
#
|
272
|
+
# break if ids.length == 0 && pool.list.length
|
273
|
+
#
|
274
|
+
#
|
275
|
+
# end
|
276
|
+
#
|
277
|
+
#
|
278
|
+
#
|
279
|
+
# puts "#{Time.now} => Complete. CSV written to \"./downloads/#{@session_id}_complete.csv\""
|
280
|
+
#
|
281
|
+
# end
|
156
282
|
|
157
|
-
end
|
158
283
|
|
159
|
-
write_path
|
160
284
|
|
161
285
|
end
|
162
286
|
|
@@ -167,36 +291,49 @@ class GoodDataEloqua::Request
|
|
167
291
|
num_iterations.times { |i| iterations << i }
|
168
292
|
iterations << num_iterations
|
169
293
|
|
170
|
-
|
171
|
-
|
172
|
-
while pool.running do
|
173
|
-
|
174
|
-
batch = iterations.slice!(1..20)
|
294
|
+
mutex = Mutex.new
|
175
295
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
csv << [element['id']]
|
183
|
-
}
|
184
|
-
csv.flush
|
185
|
-
print "\r#{Time.now} => Pages #{iterations.length} of #{num_iterations} - Workers: #{pool.active_threads}\s"
|
296
|
+
iterations.pmap { |page|
|
297
|
+
response = self.get_all_by_page(page)
|
298
|
+
puts "#{Time.now} => Extracting page: #{page}"
|
299
|
+
mutex.synchronize {
|
300
|
+
response['elements'].each { |element|
|
301
|
+
csv << [element['id']]
|
186
302
|
}
|
187
|
-
}
|
188
303
|
|
189
|
-
|
190
|
-
sleep 2
|
191
|
-
end
|
192
|
-
|
193
|
-
if iterations.length == 0 && pool.active_threads == 0
|
194
|
-
pool.running = false
|
195
|
-
else
|
196
|
-
next
|
197
|
-
end
|
304
|
+
}
|
198
305
|
|
199
|
-
|
306
|
+
}
|
307
|
+
|
308
|
+
csv.flush
|
309
|
+
|
310
|
+
# pool = Pool.new
|
311
|
+
#
|
312
|
+
# while pool.running do
|
313
|
+
#
|
314
|
+
# batch = iterations.slice!(1..20)
|
315
|
+
#
|
316
|
+
# break unless batch
|
317
|
+
#
|
318
|
+
# batch.each { |i|
|
319
|
+
# pool.thread {
|
320
|
+
#
|
321
|
+
#
|
322
|
+
# print "\r#{Time.now} => Pages #{iterations.length} of #{num_iterations} - Workers: #{pool.active_threads}\s"
|
323
|
+
# }
|
324
|
+
# }
|
325
|
+
#
|
326
|
+
# if pool.active_threads > 20
|
327
|
+
# sleep 2
|
328
|
+
# end
|
329
|
+
#
|
330
|
+
# if iterations.length == 0 && pool.active_threads == 0
|
331
|
+
# pool.running = false
|
332
|
+
# else
|
333
|
+
# next
|
334
|
+
# end
|
335
|
+
#
|
336
|
+
# end
|
200
337
|
|
201
338
|
end
|
202
339
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gooddata_eloqua
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick McConlogue
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: gooddata_s3
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '0.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '0.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rest-client
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|