lib/embulk/input/zendesk/client.rb in embulk-input-zendesk-0.2.11 vs lib/embulk/input/zendesk/client.rb in embulk-input-zendesk-0.2.12
- old
+ new
@@ -1,8 +1,9 @@
require "strscan"
require "httpclient"
require 'concurrent'
+require 'set'
module Embulk
module Input
module Zendesk
class Client
@@ -81,11 +82,11 @@
# they have both Incremental API and non-incremental API
# 170717: `ticket_events` can use standard endpoint format now, ie. `<target>.json`
%w(tickets ticket_events users organizations).each do |target|
define_method(target) do |partial = true, start_time = 0, &block|
# Always use incremental_export. There is some difference between incremental_export and export.
- incremental_export("/api/v2/incremental/#{target}.json", target, start_time, [], partial, &block)
+ incremental_export("/api/v2/incremental/#{target}.json", target, start_time, Set.new, partial, &block)
end
end
# Ticket metrics will need to be export using both the non incremental and incremental on ticket
# We provide support by filter out ticket_metrics with created at smaller than start time
@@ -95,11 +96,11 @@
# If partial export then we need to use the old end point. Since new end point return both ticket and
# ticket metric with ticket come first so the current approach that cut off the response packet won't work
# Since partial is only use for preview and guess so this should be fine
export('/api/v2/ticket_metrics.json', 'ticket_metrics', &block)
else
- incremental_export('/api/v2/incremental/tickets.json', 'metric_sets', start_time, [], partial, { include: 'metric_sets' }, &block)
+ incremental_export('/api/v2/incremental/tickets.json', 'metric_sets', start_time, Set.new, partial, { include: 'metric_sets' }, &block)
end
end
# they have non-incremental API only
UNAVAILABLE_INCREMENTAL_EXPORT.each do |target|
@@ -172,10 +173,10 @@
data[key].each do |record|
block.call record
end
end
- def incremental_export(path, key, start_time = 0, known_ids = [], partial = true, query = {}, &block)
+ def incremental_export(path, key, start_time = 0, known_ids = Set.new, partial = true, query = {}, &block)
if partial
records = request_partial(path, query.merge(start_time: start_time)).first(5)
records.uniq{|r| r["id"]}.each do |record|
block.call record
end