embulk-output-zendesk_users 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: deed5db6a5136a657abfd55cf8585e8bfd41868b
4
+ data.tar.gz: 584f8205fb14250ad86355d0c4a0f43c36959f0a
5
+ SHA512:
6
+ metadata.gz: a036e52085074881300aef91af102a32586803b0f16555ba3997cf94476962323163a642283e2888c83fb59fe882340555d0459e71d6772c18b48bea01f9dd60
7
+ data.tar.gz: 33c76a9f3e1f1ff21f14e6f51eac1d2a65bb320ab72b83ae2849101c91a9be8b80afd74f188aba1b0538a31e23b5e57b980e7c222dc2455c47824ad9d1e3bb89
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *~
2
+ /pkg/
3
+ /tmp/
4
+ /.bundle/
5
+ /Gemfile.lock
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ jruby-9.1.5.0
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+
2
+ MIT License
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Zendesk Users output plugin for Embulk
2
+
3
+ Embulk output plugin for Zendesk to update Zendesk User infomation. Fro more details, see https://developer.zendesk.com/rest_api/docs/core/users#content
4
+
5
+ This plugin's feature is limited, which allows you to update Zendesk User's tags and user_fileds.
6
+
7
+ ## Overview
8
+
9
+ * **Plugin type**: output
10
+ * **Load all or nothing**: no
11
+ * **Resume supported**: no
12
+ * **Cleanup supported**: no
13
+
14
+ ## Configuration
15
+
16
+ - **login_url**: Login URL for Zendesk (string, required)
17
+ - **auth_method**: Zendesk auth method (string, default: `token`)
18
+ - **username**: Zendesk Username (string, required)
19
+ - **token**: Zendesk API Token (string, required if auth_method is token)
20
+ - **method**: control whether to update the existing user or create new user(not supported) (string, default: `update`)
21
+ - **id_column**: column name for user's email (long, default: `id`)
22
+ - **tags_column**: column name for tags. Each tag is separated by comma (`string`, optional, default: `null`, overwrote)
23
+ - **user_fields_column**: column name for Values of custom fields in the user's profile. (json, optional, default: `null`)
24
+
25
+ ## Example
26
+
27
+ ### Config
28
+
29
+ ```yaml
30
+ in:
31
+ type: config
32
+ columns:
33
+ - {name: id, type: long}
34
+ - {name: tags, type: json}
35
+ - {name: user_fields, type: json}
36
+ values:
37
+ - - [ 1194094257, ["tag1", "tag2"], { "field0": "Support description", "field01": "2013-02-27T20:35:55Z" } ]
38
+ - [ 9811482788, ["tag3"], { "field0": "Support description" } ]
39
+ out:
40
+ type: zendesk_users
41
+ login_url: https://obscura.zendesk.com
42
+ auth_method: token
43
+ username: test@test.com
44
+ token: xxxxxxxxxx
45
+ method: update
46
+ id_column: id
47
+ tags_column: tags
48
+ user_fields_column: user_fields
49
+ ```
50
+
51
+ ### Data
52
+
53
+ - tags_column requires string data containing terms which separated by comma; Ex. `attention,attack,test`
54
+ - user_fields_column requires JSON data. For more details about available keys, See https://developer.zendesk.com/rest_api/docs/core/user_fields#json-format
55
+
56
+ ## Build
57
+
58
+ ```
59
+ $ rake
60
+ ```
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: :build
@@ -0,0 +1,20 @@
1
+
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "embulk-output-zendesk_users"
4
+ spec.version = "0.0.1"
5
+ spec.authors = ["Toru Takahashi"]
6
+ spec.summary = "Zendesk Users output plugin for Embulk"
7
+ spec.description = "Update Zendesk User's segments"
8
+ spec.email = ["torutakahashi.ayashi@gmail.com"]
9
+ spec.licenses = ["MIT"]
10
+ spec.homepage = "https://github.com/torutakahashi.ayashi/embulk-output-zendesk_users"
11
+
12
+ spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
13
+ spec.test_files = spec.files.grep(%r{^(test|spec)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_development_dependency 'embulk', ['>= 0.8.30']
17
+ spec.add_development_dependency 'bundler', ['>= 1.10.6']
18
+ spec.add_development_dependency 'rake', ['>= 10.0']
19
+ spec.add_dependency 'zendesk_api', ['>=1.16.0']
20
+ end
@@ -0,0 +1,139 @@
1
+ require 'zendesk_api'
2
+
3
+ module Embulk
4
+ module Output
5
+
6
+ class ZendeskUsers < OutputPlugin
7
+ Plugin.register_output("zendesk_users", self)
8
+
9
+ def self.transaction(config, schema, count, &control)
10
+ # configuration code:
11
+ task = {
12
+ "login_url" => config.param("login_url", :string, default: nil),
13
+ "auth_method" => config.param("auth_method", :string, default: "token"),
14
+ "username" => config.param("username", :string, default: nil),
15
+ "token" => config.param("token", :string, default: nil),
16
+ "method" => config.param("method", :string, default: "update"),
17
+ "id_column" => config.param("id_column", :string, default: "id"),
18
+ "tags_column" => config.param("tags_column", :string, default: nil),
19
+ "user_fields_column" => config.param("user_fields_column", :string, default: nil),
20
+ "timeout" => config.param("timeout", :integer, default: 5),
21
+ "open_timeout" => config.param("open_timeout", :integer, default: 2)
22
+ }
23
+
24
+ # resumable output:
25
+ # resume(task, schema, count, &control)
26
+
27
+ # non-resumable output:
28
+ task_reports = yield(task)
29
+ next_config_diff = {}
30
+ return next_config_diff
31
+ end
32
+
33
+ # def self.resume(task, schema, count, &control)
34
+ # task_reports = yield(task)
35
+ #
36
+ # next_config_diff = {}
37
+ # return next_config_diff
38
+ # end
39
+
40
+ def init
41
+ # initialization code:
42
+ @login_url = task["login_url"]
43
+ unless @login_url
44
+ raise "'login_url' is required."
45
+ end
46
+ @auth_method = task["auth_method"]
47
+ unless @auth_method == "token"
48
+ raise "Only 'token' is supported in auth_method"
49
+ end
50
+ @username = task["username"]
51
+ unless @username
52
+ raise "username is required"
53
+ end
54
+ @token = task["token"]
55
+ unless @username
56
+ raise "'token' is required"
57
+ end
58
+ @method = task["method"]
59
+ unless @method == "update"
60
+ raise "Only 'update' is supporeted in method"
61
+ end
62
+ @id_column = task["id_column"]
63
+ @tags_column = task["tags_column"]
64
+ @user_fields_column = task["user_fields_column"]
65
+ @timeout = task["timeout"]
66
+ @open_timeout = task["open_timeout"]
67
+
68
+ @client = ZendeskAPI::Client.new do |config|
69
+ config.url = @login_url + "/api/v2"
70
+ config.retry = true
71
+ config.username = @username
72
+ config.token = @token
73
+ config.client_options = {
74
+ :request => {
75
+ :timeout => @timeout,
76
+ :open_timeout => @open_timeout
77
+ }
78
+ }
79
+ end
80
+ end
81
+
82
+ def close
83
+ end
84
+
85
+ def add(page)
86
+ Embulk.logger.info { "Connecting to #{@login_url}" }
87
+ Embulk.logger.info { "Start to upload #{page.size} records" }
88
+ if @method == "update" then
89
+ # Batch Update updates up to 100 users.
90
+ page.each_slice(100).with_index do |records, index|
91
+ Embulk.logger.info { "Uploading #{records.size} records" }
92
+ update_users(records)
93
+ end
94
+ end
95
+ end
96
+
97
+ def update_users(records)
98
+ requests = Array.new
99
+ records.each do |record|
100
+ data = Hash[schema.names.zip(record)]
101
+ # Choose only target columns
102
+ temp = {}
103
+ temp.store("id", data["#{@id_column}"])
104
+ temp.store("tags", data["#{@tags_column}"]) if @tags_column
105
+ temp.store("user_fields", data["#{@user_fields_column}"]) if @user_fields_column
106
+ Embulk.logger.debug {"Uploading data: #{temp}"}
107
+ requests << temp
108
+ end
109
+
110
+ job_status = @client.users.update_many!(requests)
111
+
112
+ # https://github.com/zendesk/zendesk_api_client_rb#apps-api
113
+ # Note: job statuses are currently not supported, so you must manually poll the job status API for app creation.
114
+ body = {}
115
+ until %w{failed completed}.include?(job_status['status'])
116
+ response = @client.connection.get(job_status['url'])
117
+ job_status = response.body['job_status']
118
+ sleep(1)
119
+ end
120
+
121
+ job_status['results'].each do |result|
122
+ Embulk.logger.warn { "ID:#{result['id']}, Error:#{result['error']}" } unless result['success']
123
+ end
124
+ end
125
+
126
+ def finish
127
+ end
128
+
129
+ def abort
130
+ end
131
+
132
+ def commit
133
+ task_report = {}
134
+ return task_report
135
+ end
136
+ end
137
+
138
+ end
139
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-output-zendesk_users
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Toru Takahashi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 0.8.30
19
+ name: embulk
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.30
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.10.6
33
+ name: bundler
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.10.6
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '10.0'
47
+ name: rake
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.16.0
61
+ name: zendesk_api
62
+ prerelease: false
63
+ type: :runtime
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.16.0
69
+ description: Update Zendesk User's segments
70
+ email:
71
+ - torutakahashi.ayashi@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".ruby-version"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - embulk-output-zendesk_users.gemspec
83
+ - lib/embulk/output/zendesk_users.rb
84
+ homepage: https://github.com/torutakahashi.ayashi/embulk-output-zendesk_users
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.6.6
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Zendesk Users output plugin for Embulk
108
+ test_files: []