embulk-input-zendesk 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/embulk-input-zendesk.gemspec +1 -1
- data/lib/embulk/input/zendesk/client.rb +14 -6
- data/test/embulk/input/zendesk/test_client.rb +67 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c154709e56d9966d5bfb53da83c905151afb506
|
4
|
+
data.tar.gz: 744915c536f9fe8c6fa1fd20fd28a11bc57dee69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcdf6b6607ef344697eb8ea12e1669752821c853dfaf2f5cb675777664ad78e521223a68be813ac202bd884a398f9d194e9fbc1eaec9a9c0b01cb38e2948336d
|
7
|
+
data.tar.gz: b1bd6a19d263d48efdf9eb4047479dbce78e204e9d0304628d1fcc7e5670a01b3dbcdea20c9e5a8774c7068626c1b441185333a5c51b5986375bad188933f88c
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 0.1.6 - 2016-05-09
|
2
|
+
* [fixed] Fix non-incremental export to fetch all records [#11](https://github.com/treasure-data/embulk-input-zendesk/pull/11)
|
3
|
+
|
1
4
|
## 0.1.5 - 2016-04-14
|
2
5
|
* [enhancement] Mitigate debug pain when many retry then error [#10](https://github.com/treasure-data/embulk-input-zendesk/pull/10)
|
3
6
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
spec.name = "embulk-input-zendesk"
|
4
|
-
spec.version = "0.1.
|
4
|
+
spec.version = "0.1.6"
|
5
5
|
spec.authors = ["uu59", "muga", "sakama"]
|
6
6
|
spec.summary = "Zendesk input plugin for Embulk"
|
7
7
|
spec.description = "Loads records from Zendesk."
|
@@ -71,7 +71,7 @@ module Embulk
|
|
71
71
|
UNAVAILABLE_INCREMENTAL_EXPORT.each do |target|
|
72
72
|
define_method(target) do |partial = true, start_time = 0, &block|
|
73
73
|
path = "/api/v2/#{target}.json"
|
74
|
-
export(path, target, partial
|
74
|
+
export(path, target, partial, &block)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -89,11 +89,11 @@ module Embulk
|
|
89
89
|
|
90
90
|
private
|
91
91
|
|
92
|
-
def export(path, key,
|
93
|
-
|
94
|
-
#
|
95
|
-
|
96
|
-
response = request(path, per_page: per_page)
|
92
|
+
def export(path, key, partial, page = 1, known_ids = [], &block)
|
93
|
+
per_page = partial ? PARTIAL_RECORDS_SIZE : 100 # 100 is maximum https://developer.zendesk.com/rest_api/docs/core/introduction#pagination
|
94
|
+
Embulk.logger.debug("#{path} with page=#{page}" + (partial ? " (partial)" : ""))
|
95
|
+
|
96
|
+
response = request(path, per_page: per_page, page: page)
|
97
97
|
|
98
98
|
begin
|
99
99
|
data = JSON.parse(response.body)
|
@@ -102,8 +102,16 @@ module Embulk
|
|
102
102
|
end
|
103
103
|
|
104
104
|
data[key].each do |record|
|
105
|
+
next if known_ids.include?(record["id"])
|
106
|
+
known_ids << record["id"]
|
107
|
+
|
105
108
|
block.call record
|
106
109
|
end
|
110
|
+
return if partial
|
111
|
+
|
112
|
+
if data["next_page"]
|
113
|
+
return export(path, key, partial, page + 1, &block)
|
114
|
+
end
|
107
115
|
|
108
116
|
nil # this is necessary different with incremental_export
|
109
117
|
end
|
@@ -15,7 +15,7 @@ module Embulk
|
|
15
15
|
include FixtureHelper
|
16
16
|
include CaptureIo
|
17
17
|
|
18
|
-
sub_test_case "tickets" do
|
18
|
+
sub_test_case "tickets (incremental export)" do
|
19
19
|
sub_test_case "partial" do
|
20
20
|
def client
|
21
21
|
@client ||= Client.new(login_url: login_url, auth_method: "oauth", access_token: access_token, retry_limit: 1, retry_initial_wait_sec: 0)
|
@@ -48,6 +48,42 @@ module Embulk
|
|
48
48
|
client.tickets(&handler)
|
49
49
|
end
|
50
50
|
end
|
51
|
+
end
|
52
|
+
|
53
|
+
sub_test_case "ticket_metrics (non-incremental export)" do
|
54
|
+
sub_test_case "partial" do
|
55
|
+
def client
|
56
|
+
@client ||= Client.new(login_url: login_url, auth_method: "oauth", access_token: access_token, retry_limit: 1, retry_initial_wait_sec: 0)
|
57
|
+
end
|
58
|
+
|
59
|
+
setup do
|
60
|
+
stub(Embulk).logger { Logger.new(File::NULL) }
|
61
|
+
@httpclient = client.httpclient
|
62
|
+
stub(client).httpclient { @httpclient }
|
63
|
+
end
|
64
|
+
|
65
|
+
test "fetch ticket_metrics first page only" do
|
66
|
+
records = [
|
67
|
+
{"id" => 1},
|
68
|
+
{"id" => 2},
|
69
|
+
]
|
70
|
+
@httpclient.test_loopback_http_response << [
|
71
|
+
"HTTP/1.1 200",
|
72
|
+
"Content-Type: application/json",
|
73
|
+
"",
|
74
|
+
{
|
75
|
+
ticket_metrics: records,
|
76
|
+
next_page: "https://treasuredata.zendesk.com/api/v2/ticket_metrics.json?page=2",
|
77
|
+
}.to_json
|
78
|
+
].join("\r\n")
|
79
|
+
|
80
|
+
handler = proc { }
|
81
|
+
records.each do |record|
|
82
|
+
mock(handler).call(record)
|
83
|
+
end
|
84
|
+
client.ticket_metrics(true, &handler)
|
85
|
+
end
|
86
|
+
end
|
51
87
|
|
52
88
|
sub_test_case "all" do
|
53
89
|
def client
|
@@ -60,29 +96,46 @@ module Embulk
|
|
60
96
|
stub(client).httpclient { @httpclient }
|
61
97
|
end
|
62
98
|
|
63
|
-
test "fetch
|
64
|
-
|
99
|
+
test "fetch ticket_metrics all page" do
|
100
|
+
records = [
|
65
101
|
{"id" => 1},
|
66
102
|
{"id" => 2},
|
67
103
|
]
|
104
|
+
second_results = [
|
105
|
+
{"id" => 3}
|
106
|
+
]
|
68
107
|
@httpclient.test_loopback_http_response << [
|
69
108
|
"HTTP/1.1 200",
|
70
109
|
"Content-Type: application/json",
|
71
110
|
"",
|
72
111
|
{
|
73
|
-
|
112
|
+
ticket_metrics: records,
|
113
|
+
next_page: "https://treasuredata.zendesk.com/api/v2/ticket_metrics.json?page=2",
|
114
|
+
}.to_json
|
115
|
+
].join("\r\n")
|
116
|
+
|
117
|
+
@httpclient.test_loopback_http_response << [
|
118
|
+
"HTTP/1.1 200",
|
119
|
+
"Content-Type: application/json",
|
120
|
+
"",
|
121
|
+
{
|
122
|
+
ticket_metrics: second_results,
|
123
|
+
next_page: nil,
|
74
124
|
}.to_json
|
75
125
|
].join("\r\n")
|
76
126
|
|
77
127
|
handler = proc { }
|
78
|
-
|
79
|
-
mock(handler).call(
|
128
|
+
records.each do |record|
|
129
|
+
mock(handler).call(record)
|
130
|
+
end
|
131
|
+
second_results.each do |record|
|
132
|
+
mock(handler).call(record)
|
80
133
|
end
|
81
|
-
client.
|
134
|
+
client.ticket_metrics(false, &handler)
|
82
135
|
end
|
83
136
|
|
84
137
|
test "fetch tickets without duplicated" do
|
85
|
-
|
138
|
+
records = [
|
86
139
|
{"id" => 1},
|
87
140
|
{"id" => 2},
|
88
141
|
{"id" => 1},
|
@@ -93,13 +146,13 @@ module Embulk
|
|
93
146
|
"Content-Type: application/json",
|
94
147
|
"",
|
95
148
|
{
|
96
|
-
|
149
|
+
ticket_metrics: records
|
97
150
|
}.to_json
|
98
151
|
].join("\r\n")
|
99
152
|
|
100
153
|
handler = proc { }
|
101
154
|
mock(handler).call(anything).twice
|
102
|
-
client.
|
155
|
+
client.ticket_metrics(false, &handler)
|
103
156
|
end
|
104
157
|
|
105
158
|
test "fetch tickets with next_page" do
|
@@ -110,9 +163,8 @@ module Embulk
|
|
110
163
|
"Content-Type: application/json",
|
111
164
|
"",
|
112
165
|
{
|
113
|
-
|
114
|
-
|
115
|
-
end_time: end_time,
|
166
|
+
ticket_metrics: [{"id" => 1}],
|
167
|
+
next_page: "https://treasuredata.zendesk.com/api/v2/ticket_metrics.json?page=2",
|
116
168
|
}.to_json
|
117
169
|
].join("\r\n")
|
118
170
|
|
@@ -121,7 +173,7 @@ module Embulk
|
|
121
173
|
"Content-Type: application/json",
|
122
174
|
"",
|
123
175
|
{
|
124
|
-
|
176
|
+
ticket_metrics: [{"id" => 2}],
|
125
177
|
count: 2,
|
126
178
|
}.to_json
|
127
179
|
].join("\r\n")
|
@@ -131,7 +183,7 @@ module Embulk
|
|
131
183
|
|
132
184
|
handler = proc { }
|
133
185
|
mock(handler).call(anything).twice
|
134
|
-
client.
|
186
|
+
client.ticket_metrics(false, &handler)
|
135
187
|
end
|
136
188
|
|
137
189
|
test "raise DataError when invalid JSON response" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-input-zendesk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- uu59
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-05-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|