Class: Embulk::Input::Zendesk::Plugin
- Inherits:
-
InputPlugin
- Object
- InputPlugin
- Embulk::Input::Zendesk::Plugin
- Defined in:
- lib/embulk/input/zendesk/plugin.rb
Class Method Summary collapse
- .config_to_task(config) ⇒ Object
- .guess(config) ⇒ Object
- .resume(task, columns, count, &control) ⇒ Object
- .transaction(config, &control) ⇒ Object
Instance Method Summary collapse
Class Method Details
.config_to_task(config) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/embulk/input/zendesk/plugin.rb', line 62 def self.config_to_task(config) { login_url: config.param("login_url", :string), auth_method: config.param("auth_method", :string, default: "basic"), target: config.param("target", :string), username: config.param("username", :string, default: nil), password: config.param("password", :string, default: nil), token: config.param("token", :string, default: nil), access_token: config.param("access_token", :string, default: nil), start_time: config.param("start_time", :string, default: nil), retry_limit: config.param("retry_limit", :integer, default: 5), retry_initial_wait_sec: config.param("retry_initial_wait_sec", :integer, default: 1), schema: config.param(:columns, :array, default: []), } end |
.guess(config) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/embulk/input/zendesk/plugin.rb', line 31 def self.guess(config) task = config_to_task(config) client = Client.new(task) client.validate_config records = [] client.public_send(task[:target]) do |record| records << record end columns = Guess::SchemaGuess.from_hash_records(records).map do |column| hash = column.to_h hash.delete(:index) hash.delete(:format) unless hash[:format] # NOTE: Embulk 0.8.1 guesses Hash and Hashes in Array as string. # https://github.com/embulk/embulk/issues/379 # This is workaround for that if records.any? {|r| [Array, Hash].include?(r[hash[:name]].class) } hash[:type] = :json end # NOTE: current version don't support JSON type next if hash[:type] == :json hash end return {"columns" => columns.compact} end |
.resume(task, columns, count, &control) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/embulk/input/zendesk/plugin.rb', line 24 def self.resume(task, columns, count, &control) task_reports = yield(task, columns, count) next_config_diff = {} return next_config_diff end |
.transaction(config, &control) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/embulk/input/zendesk/plugin.rb', line 9 def self.transaction(config, &control) task = config_to_task(config) client = Client.new(task) client.validate_config columns = task[:schema].map do |column| name = column["name"] type = column["type"].to_sym Column.new(nil, name, type, column["format"]) end resume(task, columns, 1, &control) end |
Instance Method Details
#init ⇒ Object
78 79 80 |
# File 'lib/embulk/input/zendesk/plugin.rb', line 78 def init @start_time = Time.parse(task[:start_time]) if task[:start_time] end |
#run ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/embulk/input/zendesk/plugin.rb', line 82 def run method = task[:target] args = [preview?] if !preview? && @start_time args << @start_time.to_i end client = Client.new(task) client.public_send(method, *args) do |record| values = extract_values(record) page_builder.add(values) end page_builder.finish task_report = {} return task_report end |