Class: Embulk::Input::Zendesk::Client
- Inherits:
-
Object
- Object
- Embulk::Input::Zendesk::Client
- Defined in:
- lib/embulk/input/zendesk/client.rb
Constant Summary collapse
- PARTIAL_RECORDS_SIZE =
50- PARTIAL_RECORDS_BYTE_SIZE =
50000- AVAILABLE_INCREMENTAL_EXPORT =
%w(tickets users organizations ticket_events ticket_metrics).freeze
- UNAVAILABLE_INCREMENTAL_EXPORT =
%w(ticket_fields ticket_forms).freeze
- AVAILABLE_TARGETS =
AVAILABLE_INCREMENTAL_EXPORT + UNAVAILABLE_INCREMENTAL_EXPORT
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #create_pool ⇒ Object
- #fetch_subresource(record_id, base, target) ⇒ Object
- #httpclient ⇒ Object
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #validate_config ⇒ Object
- #validate_credentials ⇒ Object
- #validate_target ⇒ Object
Constructor Details
#initialize(config) ⇒ Client
17 18 19 |
# File 'lib/embulk/input/zendesk/client.rb', line 17 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/embulk/input/zendesk/client.rb', line 9 def config @config end |
Instance Method Details
#create_pool ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/embulk/input/zendesk/client.rb', line 34 def create_pool Concurrent::ThreadPoolExecutor.new( min_threads: 10, max_threads: 100, max_queue: 10_000, fallback_policy: :caller_runs ) end |
#fetch_subresource(record_id, base, target) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/embulk/input/zendesk/client.rb', line 106 def fetch_subresource(record_id, base, target) Embulk.logger.info "Fetching subresource #{target} of #{base}:#{record_id}" response = request("/api/v2/#{base}/#{record_id}/#{target}.json") return [] if response.status == 404 begin data = JSON.parse(response.body) data[target] rescue => e raise Embulk::DataError.new(e) end end |
#httpclient ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/embulk/input/zendesk/client.rb', line 21 def httpclient # multi-threading + retry can create lot of instances, and each will keep connecting # re-using instance in multi threads can help to omit cleanup code @httpclient ||= begin clnt = HTTPClient.new clnt.connect_timeout = 240 # default:60 is not enough for huge data clnt.receive_timeout = 240 # better change default receive_timeout too # httpclient.debug_dev = STDOUT set_auth(clnt) end end |
#validate_config ⇒ Object
43 44 45 46 |
# File 'lib/embulk/input/zendesk/client.rb', line 43 def validate_config validate_credentials validate_target end |
#validate_credentials ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/embulk/input/zendesk/client.rb', line 48 def validate_credentials valid = case config[:auth_method] when "basic" config[:username] && config[:password] when "token" config[:username] && config[:token] when "oauth" config[:access_token] else raise Embulk::ConfigError.new("Unknown auth_method (#{config[:auth_method]}). Should pick one from 'basic', 'token' or 'oauth'.") end unless valid raise Embulk::ConfigError.new("Missing required credentials for #{config[:auth_method]}") end end |
#validate_target ⇒ Object
65 66 67 68 69 |
# File 'lib/embulk/input/zendesk/client.rb', line 65 def validate_target unless AVAILABLE_TARGETS.include?(config[:target]) raise Embulk::ConfigError.new("target: '#{config[:target]}' is not supported. Supported targets are #{AVAILABLE_TARGETS.join(", ")}.") end end |