embulk-input-marketo 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 803b16c2edca4432ffcb1f32e9914d944b3747dd
4
- data.tar.gz: bb28951330b3b3ac1a8d3bf7a3e81541915268e2
3
+ metadata.gz: ab9b973d17f88ee84d60abec578abaf3734ef9db
4
+ data.tar.gz: 2875742fde0e64de55ea08458674f041b1ed2030
5
5
  SHA512:
6
- metadata.gz: 53f1320084a90a824af96b5205ae05f3d8596e79169abc7b15282c67d359ca8c26b8c1e433dcab5ff7b678ba1b239347b7ebd9eda547eb79bbde6ca931227aed
7
- data.tar.gz: e6a1e61e3a7d4d0b875b0e704298d7e96d0e1ab395125e461ef704ef069267ac407b515538e2576dbf7ada5420b2f8b473a5d04337f5600648dd5e3649d2c7f6
6
+ metadata.gz: 2b559f997b7f9e8cab9b1caec4e65fb21edce75665e1162a8ae93a2709b11cb9317c955320c0bd206d9b049a4f0d0f61157b2b86452bafe1f89bb2206de6eab5
7
+ data.tar.gz: 5df8a59649e0bdb9b1b607b983d1fa5cc35fa0108481d20e1aa195e052dc70b34779e572f793175de070bd90f96fd95dbf497965acef93ebfc8e55a09380bcee
@@ -1 +1 @@
1
- jruby-1.7.20
1
+ jruby-9.0.1.0
@@ -1,16 +1,34 @@
1
1
  language: ruby
2
- rvm:
3
- - jruby-19mode
2
+
4
3
  addons:
5
4
  code_climate:
6
5
  repo_token:
7
6
  secure: "cYPXD2Dv1VOU0rdUSsevrGuHcjBajCTq8s961R8d2pPkX+V1AbmIMKK0if00qMgqR7D65p6jOnfiuZfXolF1z4awqLXNu7LhP6zOr1hMRCOHOfjj/SJLbm5MFreN81G+6k4XpfBlA9YShA9E/nNVxBmakxC8aCnlJHGfDUbkb9kmNX/LXSNf0efZMRVr3vN8tP6tHP0TUCx90A2FNols9qHgl+boxF090OpgFTspyeqC6K82Q4D97RwajnM+oKIBMfxuc4Pc1n+PZ+mQQfYNK7ze4WszXRtQydwDD7rtF5d6IwczElZ243GjXxdJWL6inUvcMJQogC5X8ayh7m0ZNT2awfbJXT1tsLte42j+/eUAPaCD07bE8XzgdmfTdmpxP6nHasAMkleDMlcBRrxht+cGD61qEXcsSKd0c7mnvg35L+hl39NGFde0yz1Xxx/D69p9KHE0pa7cZNC7D8n1w9AUxFdl8OX6rfDlgiapIonAF/QG/5Z3ltHDzZu6XK1MMFugrdV7SxuSepL3xgBv5jN0jMA/GVmvFbXf6FGDXxt/bhSUCZoTJ/c8BaRnIM+QTkBts6TqgQ6BeUQNAe5p0TtssNwMW8RC4DpkaLDeQRSScJJ6V6UDpjsPJ3hcozpzrCVwy/5F72MYzcHeKg85EF30aA94Q+EDbsKUR0BEeGo="
7
+
8
8
  notifications:
9
9
  slack:
10
10
  secure: NP6hpwbwLnX9jFgENk3FN3B4jO4b2bIeK7gU9tRw87QmlUFDCcypSVYJrd7j1oQP4plZy+ohZMCs7RQJmtP1k2RQ99tu2ncWhslpz6f5zZo1Hjx4hleFpAv6N9tycfxEILcq/USxcTdM/8/YPtDr5WXM+w3hTuE21VlxqT6ED9LUYaiiUZeZApBXYAe36BIOGe+TtmwWrMfXvaqaoAt0A7pIzaXPD4i7WxR+qAMM4gjJGzH4JKs2zoQ2MgI81xD5Pe0yz/5ciiHATJj0WFkrOeZaoqFvW5MQ20eArvfW9dC7/fXnrPx8RPd6iaD29hQfnPI2mnWRvXxch0DsBcYOfFzYpdgx43XVTXVJ3zyudbgqnL8RrTbwIMsxIrEW3hAZ1MvxiKDBACWFdbzz8GAjywaq0zRZ/zKam1zcDRMQAWnZP54wUFHfSXvZWhRDzImSYTM75EqaspTabRQp89SpRuaGl+ab7wEDdJBXqLiUf7jHYc2K3F9o4B99luSvbxGv97M9D7P+Aee7tpFe4mjTuxjDnIVDbQzdza8qrZWXNfymSPb2pZOKP535alF92XalExBQnxKPzmUYDpTksrsgYPZeUHcnwO6J5lCPfPerWJ/U+s4PEm0HE5TpghhsZ901gYxCeDw/KnVQGsIy3f8YAI/+YVwjl4Ld4BOd1MV2PB8=
11
- jdk:
12
- - oraclejdk8
11
+
12
+ before_install:
13
+ - |
14
+ # Currently, Travis can't treat jruby 9.0.1.0
15
+ if [[ ${TRAVIS_RUBY_VERSION} = "jruby-9.0.0.0" ]];then
16
+ rvm get head
17
+ rvm use jruby-9.0.1.0 --install
18
+ ruby -v
19
+ fi
20
+
21
+ jdk: oraclejdk8
22
+
23
+ rvm:
24
+ - jruby-19mode
25
+ - jruby-9.0.0.0
26
+
13
27
  gemfile:
28
+ - gemfiles/embulk-0.6.0-latest
29
+ - gemfiles/embulk-0.6.13
30
+ - gemfiles/embulk-0.6.14
31
+ - gemfiles/embulk-0.6.15
14
32
  - gemfiles/embulk-0.6.16
15
33
  - gemfiles/embulk-0.6.17
16
34
  - gemfiles/embulk-0.6.18
@@ -22,8 +40,52 @@ gemfile:
22
40
  - gemfiles/embulk-0.6.24
23
41
  - gemfiles/embulk-0.6.25
24
42
  - gemfiles/embulk-0.6.26
43
+ - gemfiles/embulk-0.6.27
44
+ - gemfiles/embulk-0.7.0
45
+ - gemfiles/embulk-0.7.0-latest
46
+ - gemfiles/embulk-0.7.1
47
+ - gemfiles/embulk-0.7.2
48
+ - gemfiles/embulk-0.7.3
49
+ - gemfiles/embulk-0.7.4
50
+ - gemfiles/embulk-0.7.5
25
51
  - gemfiles/embulk-latest
52
+
26
53
  matrix:
54
+ exclude:
55
+ - jdk: oraclejdk8 # Ignore all matrix at first, use `include` to allow build
56
+ include:
57
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.0-latest}
58
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.13}
59
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.14}
60
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.15}
61
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.16}
62
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.17}
63
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.18}
64
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.19}
65
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.20}
66
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.21}
67
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.22}
68
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.23}
69
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.24}
70
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.25}
71
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.26}
72
+ - {rvm: jruby-19mode, gemfile: gemfiles/embulk-0.6.27}
73
+ - {rvm: jruby-9.0.0.0, gemfile: gemfiles/embulk-0.7.0}
74
+ - {rvm: jruby-9.0.0.0, gemfile: gemfiles/embulk-0.7.0-latest}
75
+ - {rvm: jruby-9.0.0.0, gemfile: gemfiles/embulk-0.7.1}
76
+ - {rvm: jruby-9.0.0.0, gemfile: gemfiles/embulk-0.7.2}
77
+ - {rvm: jruby-9.0.0.0, gemfile: gemfiles/embulk-0.7.3}
78
+ - {rvm: jruby-9.0.0.0, gemfile: gemfiles/embulk-0.7.4}
79
+ - {rvm: jruby-9.0.0.0, gemfile: gemfiles/embulk-0.7.5}
80
+ - {rvm: jruby-9.0.0.0, gemfile: gemfiles/embulk-latest}
81
+
82
+
27
83
  allow_failures:
28
84
  - gemfile: gemfiles/embulk-0.6.22
29
- - gemfile: gemfiles/embulk-latest
85
+ - gemfile: gemfiles/embulk-0.7.0
86
+ - gemfile: gemfiles/embulk-0.7.1
87
+ # Ignore failure for *-latest
88
+ - gemfile: embulk-0.6.0-latest
89
+ - gemfile: embulk-0.7.0-latest
90
+ - gemfile: embulk-latest
91
+
@@ -0,0 +1,47 @@
1
+ language: ruby
2
+
3
+ addons:
4
+ code_climate:
5
+ repo_token:
6
+ secure: "cYPXD2Dv1VOU0rdUSsevrGuHcjBajCTq8s961R8d2pPkX+V1AbmIMKK0if00qMgqR7D65p6jOnfiuZfXolF1z4awqLXNu7LhP6zOr1hMRCOHOfjj/SJLbm5MFreN81G+6k4XpfBlA9YShA9E/nNVxBmakxC8aCnlJHGfDUbkb9kmNX/LXSNf0efZMRVr3vN8tP6tHP0TUCx90A2FNols9qHgl+boxF090OpgFTspyeqC6K82Q4D97RwajnM+oKIBMfxuc4Pc1n+PZ+mQQfYNK7ze4WszXRtQydwDD7rtF5d6IwczElZ243GjXxdJWL6inUvcMJQogC5X8ayh7m0ZNT2awfbJXT1tsLte42j+/eUAPaCD07bE8XzgdmfTdmpxP6nHasAMkleDMlcBRrxht+cGD61qEXcsSKd0c7mnvg35L+hl39NGFde0yz1Xxx/D69p9KHE0pa7cZNC7D8n1w9AUxFdl8OX6rfDlgiapIonAF/QG/5Z3ltHDzZu6XK1MMFugrdV7SxuSepL3xgBv5jN0jMA/GVmvFbXf6FGDXxt/bhSUCZoTJ/c8BaRnIM+QTkBts6TqgQ6BeUQNAe5p0TtssNwMW8RC4DpkaLDeQRSScJJ6V6UDpjsPJ3hcozpzrCVwy/5F72MYzcHeKg85EF30aA94Q+EDbsKUR0BEeGo="
7
+
8
+ notifications:
9
+ slack:
10
+ secure: NP6hpwbwLnX9jFgENk3FN3B4jO4b2bIeK7gU9tRw87QmlUFDCcypSVYJrd7j1oQP4plZy+ohZMCs7RQJmtP1k2RQ99tu2ncWhslpz6f5zZo1Hjx4hleFpAv6N9tycfxEILcq/USxcTdM/8/YPtDr5WXM+w3hTuE21VlxqT6ED9LUYaiiUZeZApBXYAe36BIOGe+TtmwWrMfXvaqaoAt0A7pIzaXPD4i7WxR+qAMM4gjJGzH4JKs2zoQ2MgI81xD5Pe0yz/5ciiHATJj0WFkrOeZaoqFvW5MQ20eArvfW9dC7/fXnrPx8RPd6iaD29hQfnPI2mnWRvXxch0DsBcYOfFzYpdgx43XVTXVJ3zyudbgqnL8RrTbwIMsxIrEW3hAZ1MvxiKDBACWFdbzz8GAjywaq0zRZ/zKam1zcDRMQAWnZP54wUFHfSXvZWhRDzImSYTM75EqaspTabRQp89SpRuaGl+ab7wEDdJBXqLiUf7jHYc2K3F9o4B99luSvbxGv97M9D7P+Aee7tpFe4mjTuxjDnIVDbQzdza8qrZWXNfymSPb2pZOKP535alF92XalExBQnxKPzmUYDpTksrsgYPZeUHcnwO6J5lCPfPerWJ/U+s4PEm0HE5TpghhsZ901gYxCeDw/KnVQGsIy3f8YAI/+YVwjl4Ld4BOd1MV2PB8=
11
+
12
+ before_install:
13
+ - |
14
+ # Currently, Travis can't treat jruby 9.0.1.0
15
+ if [[ ${TRAVIS_RUBY_VERSION} = "jruby-9.0.0.0" ]];then
16
+ rvm get head
17
+ rvm use jruby-9.0.1.0 --install
18
+ ruby -v
19
+ fi
20
+
21
+ jdk: oraclejdk8
22
+
23
+ rvm:
24
+ - jruby-19mode
25
+ - jruby-9.0.0.0
26
+
27
+ gemfile:
28
+ <% versions.each do |file| -%>
29
+ - gemfiles/<%= file %>
30
+ <% end -%>
31
+
32
+ matrix:
33
+ exclude:
34
+ - jdk: oraclejdk8 # Ignore all matrix at first, use `include` to allow build
35
+ include:
36
+ <% matrix.each do |m| -%>
37
+ <%= m %>
38
+ <% end %>
39
+
40
+ allow_failures:
41
+ - gemfile: gemfiles/embulk-0.6.22
42
+ - gemfile: gemfiles/embulk-0.7.0
43
+ - gemfile: gemfiles/embulk-0.7.1
44
+ # Ignore failure for *-latest
45
+ <% versions.find_all{|file| file.to_s.match(/-latest/)}.each do |file| -%>
46
+ - gemfile: <%= file %>
47
+ <% end %>
@@ -1,3 +1,8 @@
1
+ ## 0.3.1 - 2015-10-06
2
+
3
+ * [enhancement] Supports embulk.0.7 [#43](https://github.com/treasure-data/embulk-input-marketo/pull/43)
4
+ * [maintenance] Refactor [#40](https://github.com/treasure-data/embulk-input-marketo/pull/40)
5
+
1
6
  ## 0.3.0 - 2015-09-30
2
7
 
3
8
  This version breaks backword compatibility of marketo/activity_log. Please check README.md to modify your config.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "embulk-input-marketo"
3
- spec.version = "0.3.0"
3
+ spec.version = "0.3.1"
4
4
  spec.authors = ["uu59", "yoshihara"]
5
5
  spec.summary = "Marketo input plugin for Embulk"
6
6
  spec.description = "Loads records from Marketo."
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "~> 0.6.0"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.6.13"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.6.14"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.6.15"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.6.27"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.7.0"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "~> 0.7.0"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.7.1"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.7.2"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.7.3"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.7.4"
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec :path => '../'
3
+
4
+ gem "embulk", "0.7.5"
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org/'
2
2
  gemspec :path => '../'
3
3
 
4
- gem "embulk", "> 0.6.16"
4
+ gem "embulk", "> 0.6.13"
@@ -4,12 +4,23 @@ module Embulk
4
4
  module Input
5
5
  module Marketo
6
6
  class ActivityLog < Base
7
+ BATCH_SIZE_DEFAULT = 100
8
+
7
9
  Plugin.register_input("marketo/activity_log", self)
8
10
 
9
11
  def self.target
10
12
  :activity_log
11
13
  end
12
14
 
15
+ def self.resume(task, columns, count, &control)
16
+ task_reports = yield(task, columns, count)
17
+
18
+ # NOTE: If this plugin supports to run by multi threads, this
19
+ # implementation is terrible.
20
+ next_config_diff = task_reports.first
21
+ return next_config_diff
22
+ end
23
+
13
24
  def self.transaction(config, &control)
14
25
  endpoint_url = config.param(:endpoint, :string)
15
26
 
@@ -25,16 +36,7 @@ module Embulk
25
36
  columns: config.param(:columns, :array)
26
37
  }
27
38
 
28
- columns = []
29
-
30
- task[:columns].each do |column|
31
- name = column["name"]
32
- type = column["type"].to_sym
33
-
34
- columns << Column.new(nil, name, type, column["format"])
35
- end
36
-
37
- resume(task, columns, 1, &control)
39
+ resume(task, embulk_columns(config), 1, &control)
38
40
  end
39
41
 
40
42
  def self.guess(config)
@@ -51,46 +53,37 @@ module Embulk
51
53
  return {"columns" => columns}
52
54
  end
53
55
 
54
- def run
55
- if preview?
56
- batch_size = PREVIEW_COUNT
57
- else
58
- batch_size = 100
59
- end
56
+ def init
57
+ @columns = task[:columns]
58
+ @soap = MarketoApi.soap_client(task, target)
59
+ end
60
60
 
61
- count = 0
61
+ def run
62
+ options = {
63
+ to: task[:to_datetime],
64
+ batch_size: (preview? ? PREVIEW_COUNT : BATCH_SIZE_DEFAULT),
65
+ }
62
66
 
63
- last_updated_at = @soap.each(task[:from_datetime], batch_size: batch_size, to: task[:to_datetime]) do |activity_log|
67
+ counter = 0
68
+ latest_updated_at = @soap.each(task[:from_datetime], options) do |activity_log|
64
69
  values = @columns.map do |column|
65
70
  name = column["name"].to_s
66
71
  value = activity_log[name]
67
- next unless value
68
-
69
- case column["type"].to_s
70
- when "timestamp"
71
- begin
72
- Time.parse(value)
73
- rescue => e
74
- raise ConfigError, "Can't parse as Time '#{value}' (column is #{column["name"]})"
75
- end
76
- else
77
- value
78
- end
72
+ cast_value(column, value)
79
73
  end
80
74
 
81
75
  page_builder.add(values)
82
- count += 1
83
- break if preview? && count >= PREVIEW_COUNT
76
+ break if preview? && (counter += 1) >= PREVIEW_COUNT
84
77
  end
85
78
 
86
79
  page_builder.finish
87
80
 
88
- commit_report = {}
89
- if !preview? && last_updated_at
90
- commit_report = {from_datetime: last_updated_at}
81
+ task_report = {}
82
+ if !preview? && latest_updated_at
83
+ task_report = {from_datetime: latest_updated_at}
91
84
  end
92
85
 
93
- return commit_report
86
+ return task_report
94
87
  end
95
88
  end
96
89
  end
@@ -1,4 +1,3 @@
1
- require "embulk/input/marketo/timeslice"
2
1
  require "embulk/input/marketo_api"
3
2
 
4
3
  module Embulk
@@ -13,15 +12,6 @@ module Embulk
13
12
  raise NotImplementedError
14
13
  end
15
14
 
16
- def self.resume(task, columns, count, &control)
17
- commit_reports = yield(task, columns, count)
18
-
19
- # NOTE: If this plugin supports to run by multi threads, this
20
- # implementation is terrible.
21
- next_config_diff = commit_reports.first
22
- return next_config_diff
23
- end
24
-
25
15
  def self.soap_client(config)
26
16
  @soap ||=
27
17
  begin
@@ -37,26 +27,15 @@ module Embulk
37
27
  end
38
28
  end
39
29
 
40
- def init
41
- @last_updated_at = task[:last_updated_at]
42
- @columns = task[:columns]
43
- @soap = MarketoApi.soap_client(task, target)
44
- end
45
-
46
- private
30
+ def self.embulk_columns(config)
31
+ config.param(:columns, :array).map do |column|
32
+ name = column["name"]
33
+ type = column["type"].to_sym
47
34
 
48
- def preview?
49
- begin
50
- org.embulk.spi.Exec.isPreview()
51
- rescue java.lang.NullPointerException => e
52
- false
35
+ Column.new(nil, name, type, column["format"])
53
36
  end
54
37
  end
55
38
 
56
- def target
57
- self.class.target
58
- end
59
-
60
39
  def self.format_range(config)
61
40
  if config.param(:last_updated_at, :string, default: nil)
62
41
  Embulk.logger.warn "config: last_updated_at is deprecated. Use from_datetime/to_datetime"
@@ -71,11 +50,11 @@ module Embulk
71
50
  Time.parse(to_datetime)
72
51
  rescue => e
73
52
  # possibly Time.parse fail
74
- raise ConfigError, e.message
53
+ raise ConfigError.new e.message
75
54
  end
76
55
 
77
56
  if Time.parse(from_datetime) > Time.parse(to_datetime)
78
- raise ConfigError, "config: from_datetime '#{from_datetime}' is later than '#{to_datetime}'."
57
+ raise ConfigError.new "config: from_datetime '#{from_datetime}' is later than '#{to_datetime}'."
79
58
  end
80
59
 
81
60
  {
@@ -83,6 +62,72 @@ module Embulk
83
62
  to: to_datetime,
84
63
  }
85
64
  end
65
+
66
+ def self.timeslice(from, to, count)
67
+ generate_time_range(from, to).each_slice(count).to_a
68
+ end
69
+
70
+ def self.generate_time_range(from, to)
71
+ # e.g. from = 2010-01-01 15:00, to = 2010-01-03 09:30
72
+ # convert to such array:
73
+ # [
74
+ # {from: 2010-01-01 15:00, to: 2010-01-01 16:00},
75
+ # {from: 2010-01-01 16:00, to: 2010-01-01 17:00},
76
+ # ...
77
+ # {from: 2010-01-03 08:00, to: 2010-01-03 09:00},
78
+ # {from: 2010-01-03 09:00, to: 2010-01-03 09:30},
79
+ # ]
80
+ # to fetch data from Marketo API with each day as
81
+ # desribed on official blog:
82
+ # http://developers.marketo.com/blog/performance-tuning-api-requests/
83
+ to ||= Time.now
84
+ from = Time.parse(from) unless from.is_a?(Time)
85
+ to = Time.parse(to) unless to.is_a?(Time)
86
+
87
+ result = []
88
+ since = from
89
+ while since < to
90
+ next_since = since + 3600
91
+ if to < next_since
92
+ next_since = to
93
+ end
94
+ result << {
95
+ "from" => since,
96
+ "to" => next_since
97
+ }
98
+ since = next_since
99
+ end
100
+ result
101
+ end
102
+
103
+ private
104
+
105
+ def preview?
106
+ begin
107
+ org.embulk.spi.Exec.isPreview()
108
+ rescue java.lang.NullPointerException => e
109
+ false
110
+ end
111
+ end
112
+
113
+ def cast_value(column, value)
114
+ return unless value
115
+
116
+ case column["type"].to_s
117
+ when "timestamp"
118
+ begin
119
+ Time.parse(value)
120
+ rescue => e
121
+ raise ConfigError.new "Can't parse as Time '#{value}' (column is #{column["name"]})"
122
+ end
123
+ else
124
+ value
125
+ end
126
+ end
127
+
128
+ def target
129
+ self.class.target
130
+ end
86
131
  end
87
132
  end
88
133
  end
@@ -4,7 +4,7 @@ module Embulk
4
4
  module Input
5
5
  module Marketo
6
6
  class Lead < Base
7
- include Timeslice
7
+ TIMESLICE_COUNT_PER_TASK = 24
8
8
 
9
9
  Plugin.register_input("marketo/lead", self)
10
10
 
@@ -12,6 +12,46 @@ module Embulk
12
12
  :lead
13
13
  end
14
14
 
15
+ def self.guess(config)
16
+ if config.param(:last_updated_at, :string, default: nil)
17
+ Embulk.logger.warn "config: last_updated_at is deprecated. Use from_datetime/to_datetime"
18
+ end
19
+
20
+ client = soap_client(config)
21
+ metadata = client.metadata
22
+
23
+ return {"columns" => generate_columns(metadata)}
24
+ end
25
+
26
+ def self.resume(task, columns, count, &control)
27
+ task_reports = yield(task, columns, count)
28
+
29
+ # When no task ran, task_reports is empty
30
+ return {} if task_reports.empty?
31
+ # all task returns same report as {from_datetime: to_datetime}
32
+ return task_reports.first
33
+ end
34
+
35
+ def self.transaction(config, &control)
36
+ endpoint_url = config.param(:endpoint, :string)
37
+
38
+ range = format_range(config)
39
+
40
+ ranges = timeslice(range[:from], range[:to], TIMESLICE_COUNT_PER_TASK)
41
+ task = {
42
+ endpoint_url: endpoint_url,
43
+ wsdl_url: config.param(:wsdl, :string, default: "#{endpoint_url}?WSDL"),
44
+ user_id: config.param(:user_id, :string),
45
+ encryption_key: config.param(:encryption_key, :string),
46
+ from_datetime: range[:from],
47
+ to_datetime: range[:to],
48
+ ranges: ranges,
49
+ columns: config.param(:columns, :array)
50
+ }
51
+
52
+ resume(task, embulk_columns(config), ranges.size, &control)
53
+ end
54
+
15
55
  def self.generate_columns(metadata)
16
56
  columns = [
17
57
  {name: "id", type: "long"},
@@ -48,41 +88,29 @@ module Embulk
48
88
  end
49
89
 
50
90
  def run
51
- from_datetime = task[:from_datetime]
52
- to_datetime = task[:to_datetime] || Time.now
53
-
54
91
  options = {}
55
92
  options[:batch_size] = PREVIEW_COUNT if preview?
56
93
 
94
+ counter = 0
57
95
  @ranges.each do |range|
58
96
  soap.each(range, options) do |lead|
59
97
  values = @columns.map do |column|
60
98
  name = column["name"].to_s
61
99
  value = (lead[name] || {})[:value]
62
- next unless value
63
-
64
- case column["type"]
65
- when "timestamp"
66
- begin
67
- Time.parse(value)
68
- rescue => e
69
- raise ConfigError, "Can't parse as Time '#{value}' (column is #{column["name"]})"
70
- end
71
- else
72
- value
73
- end
100
+ cast_value(column, value)
74
101
  end
75
102
 
76
103
  page_builder.add(values)
104
+ break if preview? && (counter += 1) >= PREVIEW_COUNT
77
105
  end
78
106
  end
79
107
 
80
108
  page_builder.finish
81
109
 
82
- commit_report = {
83
- from_datetime: to_datetime
110
+ task_report = {
111
+ from_datetime: task[:to_datetime]
84
112
  }
85
- return commit_report
113
+ return task_report
86
114
  end
87
115
  end
88
116
  end
@@ -5,30 +5,29 @@ module Embulk
5
5
  module MarketoApi
6
6
  module Soap
7
7
  class ActivityLog < Base
8
- def metadata(last_updated_at, options={})
8
+ def metadata(from_datetime, options={})
9
9
  activity_logs = []
10
10
 
11
- fetch_by_last_updated_at(last_updated_at, options) do |record|
11
+ fetch_by_from_datetime(from_datetime, options) do |record|
12
12
  activity_logs << record
13
13
  end
14
14
 
15
15
  Guess::SchemaGuess.from_hash_records(activity_logs)
16
16
  end
17
17
 
18
- def each(last_updated_at, options={}, &block)
19
- response = fetch_by_last_updated_at(last_updated_at, options, &block)
18
+ def each(from_datetime, options={}, &block)
19
+ response = fetch_by_from_datetime(from_datetime, options, &block)
20
20
  while response[:remaining_count] > 0 do
21
- response = fetch_by_last_updated_at(last_updated_at, options.merge(offset: response[:offset]), &block)
21
+ response = fetch_by_from_datetime(from_datetime, options.merge(offset: response[:offset]), &block)
22
22
  end
23
23
 
24
- response[:last_updated_at]
24
+ response[:from_datetime]
25
25
  end
26
26
 
27
27
  private
28
28
 
29
- def fetch_by_last_updated_at(last_updated_at, options={}, &block)
30
- last_updated_at = last_updated_at.to_s
31
- last_updated_at = Time.parse(last_updated_at).iso8601
29
+ def fetch_by_from_datetime(from_datetime, options={}, &block)
30
+ from = Time.parse(from_datetime.to_s).iso8601
32
31
 
33
32
  to =
34
33
  if options[:to]
@@ -39,7 +38,7 @@ module Embulk
39
38
 
40
39
  request = {
41
40
  start_position: {
42
- oldest_created_at: last_updated_at,
41
+ oldest_created_at: from,
43
42
  latest_created_at: to,
44
43
  },
45
44
  batch_size: options[:batch_size] || 100
@@ -58,7 +57,7 @@ module Embulk
58
57
 
59
58
  if activities_list.nil?
60
59
  Embulk.logger.info "No record is fetched."
61
- return {remaining_count: 0, offset: nil, last_updated_at: nil}
60
+ return {remaining_count: 0, offset: nil, from_datetime: nil}
62
61
  end
63
62
 
64
63
  activities = activities_list[:lead_change_record].sort_by { |activity| Time.parse(activity[:activity_date_time]) }
@@ -85,7 +84,7 @@ module Embulk
85
84
  {
86
85
  remaining_count: remaining,
87
86
  offset: response.body[:success_get_lead_changes][:result][:new_start_position][:offset],
88
- last_updated_at: activities.last[:activity_date_time]
87
+ from_datetime: activities.last[:activity_date_time]
89
88
  }
90
89
  end
91
90
  end
@@ -77,7 +77,7 @@ module Embulk
77
77
  rescue Savon::SOAPFault => e
78
78
  Embulk.logger.debug "#{e.class}: #{e.to_hash}"
79
79
  if e.to_hash[:fault][:faultcode].to_str == "SOAP-ENV:Client"
80
- raise ConfigError, e.message
80
+ raise ConfigError.new e.message
81
81
  end
82
82
  rescue Savon::HTTPError => e
83
83
  # NOTE: Marketo API always return error as HTTP 500
@@ -94,12 +94,12 @@ module Embulk
94
94
  raise e
95
95
  else
96
96
  # unretryable error such as Authentication Failed, Invalid Request, etc.
97
- raise ConfigError, soap_message
97
+ raise ConfigError.new soap_message
98
98
  end
99
99
  rescue SocketError, Errno::ECONNREFUSED => e
100
100
  # maybe endpoint/wsdl domain was wrong
101
101
  Embulk.logger.debug "Connection error: endpoint=#{endpoint} wsdl=#{wsdl}"
102
- raise ConfigError, "Connection error: #{e.message} (endpoint is '#{endpoint}')"
102
+ raise ConfigError.new "Connection error: #{e.message} (endpoint is '#{endpoint}')"
103
103
  end
104
104
  end
105
105
  end
@@ -1,4 +1,5 @@
1
1
  require "prepare_embulk"
2
+ require "override_assert_raise"
2
3
  require "embulk/input/marketo/activity_log"
3
4
  require "activity_log_fixtures"
4
5
 
@@ -7,6 +8,7 @@ module Embulk
7
8
  module Marketo
8
9
  class ActivityLogTest < Test::Unit::TestCase
9
10
  include ActivityLogFixtures
11
+ include OverrideAssertRaise
10
12
 
11
13
  class TransactionTest < self
12
14
  def test_generate_task
@@ -19,6 +21,17 @@ module Embulk
19
21
  ActivityLog.transaction(config, &control)
20
22
  end
21
23
 
24
+ def test_resume
25
+ next_config_diff = {from_datetime: from_datetime}
26
+ control = proc { [next_config_diff] } # In actual, embulk prepares control block returning Array.
27
+ columns = task[:columns].map do |col|
28
+ Column.new(nil, col["name"], col["type"].to_sym)
29
+ end
30
+
31
+ actual = ActivityLog.resume(task, columns, 1, &control)
32
+ assert_equal(next_config_diff, actual)
33
+ end
34
+
22
35
  private
23
36
 
24
37
  def settings
@@ -11,17 +11,6 @@ module Embulk
11
11
  end
12
12
  end
13
13
 
14
- def test_resume
15
- next_config_diff = {last_updated_at: last_updated_at}
16
- control = proc { [next_config_diff] } # In actual, embulk prepares control block returning Array.
17
- columns = task[:columns].map do |col|
18
- Column.new(nil, col["name"], col["type"].to_sym)
19
- end
20
-
21
- actual = Base.resume(task, columns, 1, &control)
22
- assert_equal(next_config_diff, actual)
23
- end
24
-
25
14
  class SoapClientTest < self
26
15
  def setup
27
16
  stub(Base).target { :lead }
@@ -57,14 +46,14 @@ module Embulk
57
46
  wsdl: "https://marketo.example.com/?wsdl",
58
47
  user_id: "user_id",
59
48
  encryption_key: "TOPSECRET",
60
- last_updated_at: last_updated_at,
49
+ from_datetime: from_datetime,
61
50
  columns: [
62
51
  {"name" => "Name", "type" => "string"},
63
52
  ]
64
53
  }
65
54
  end
66
55
 
67
- def last_updated_at
56
+ def from_datetime
68
57
  "2015-07-01 00:00:00+00:00"
69
58
  end
70
59
 
@@ -74,7 +63,7 @@ module Embulk
74
63
  wsdl_url: "https://marketo.example.com/?wsdl",
75
64
  user_id: "user_id",
76
65
  encryption_key: "TOPSECRET",
77
- last_updated_at: last_updated_at,
66
+ from_datetime: from_datetime,
78
67
  columns: [
79
68
  {"name" => "Name", "type" => "string"},
80
69
  ]
@@ -1,6 +1,7 @@
1
1
  require "prepare_embulk"
2
2
  require "lead_fixtures"
3
3
  require "mute_logger"
4
+ require "override_assert_raise"
4
5
  require "embulk/input/marketo/lead"
5
6
 
6
7
  module Embulk
@@ -9,6 +10,7 @@ module Embulk
9
10
  class LeadTest < Test::Unit::TestCase
10
11
  include LeadFixtures
11
12
  include MuteLogger
13
+ include OverrideAssertRaise
12
14
 
13
15
  def test_target
14
16
  assert_equal(:lead, Lead.target)
@@ -15,7 +15,7 @@ module Embulk
15
15
  def test_each
16
16
  request = {
17
17
  start_position: {
18
- oldest_created_at: Time.parse(last_updated_at).iso8601,
18
+ oldest_created_at: Time.parse(from_datetime).iso8601,
19
19
  },
20
20
  batch_size: 100
21
21
  }
@@ -31,13 +31,13 @@ module Embulk
31
31
  last_activity_log = activity_logs.last
32
32
 
33
33
  mock(proc).call(anything).times(activity_logs.size)
34
- assert_equal(last_activity_log[:activity_date_time], soap.each(last_updated_at, &proc))
34
+ assert_equal(last_activity_log[:activity_date_time], soap.each(from_datetime, &proc))
35
35
  end
36
36
 
37
37
  def test_each_with_no_response
38
38
  request = {
39
39
  start_position: {
40
- oldest_created_at: Time.parse(last_updated_at).iso8601,
40
+ oldest_created_at: Time.parse(from_datetime).iso8601,
41
41
  },
42
42
  batch_size: 100
43
43
  }
@@ -50,7 +50,7 @@ module Embulk
50
50
 
51
51
  proc = proc{ "" }
52
52
 
53
- assert_nil(soap.each(last_updated_at, &proc))
53
+ assert_nil(soap.each(from_datetime, &proc))
54
54
  end
55
55
 
56
56
  class TestMetadata < self
@@ -65,14 +65,14 @@ module Embulk
65
65
  mock(@savon).call(:get_lead_changes, message: request) {
66
66
  next_stream_activity_logs_response
67
67
  }
68
- soap.metadata(last_updated_at)
68
+ soap.metadata(from_datetime)
69
69
  end
70
70
 
71
71
  def test_return_schema
72
72
  stub(@savon).call(:get_lead_changes, message: request) {
73
73
  next_stream_activity_logs_response
74
74
  }
75
- assert_equal(schema, soap.metadata(last_updated_at))
75
+ assert_equal(schema, soap.metadata(from_datetime))
76
76
  end
77
77
 
78
78
  private
@@ -80,7 +80,7 @@ module Embulk
80
80
  def request
81
81
  {
82
82
  start_position: {
83
- oldest_created_at: Time.parse(last_updated_at).iso8601,
83
+ oldest_created_at: Time.parse(from_datetime).iso8601,
84
84
  },
85
85
  batch_size: 100
86
86
  }
@@ -105,7 +105,7 @@ module Embulk
105
105
 
106
106
  private
107
107
 
108
- def last_updated_at
108
+ def from_datetime
109
109
  "2015-07-06"
110
110
  end
111
111
 
@@ -0,0 +1,18 @@
1
+ module OverrideAssertRaise
2
+ # NOTE: Embulk 0.7.1+ required to raise ConfigError to do as `ConfigError.new("message")`,
3
+ # original `assert_raise` method can't catch that, but `begin .. rescue` can.
4
+ # So we override assert_raise as below.
5
+ def assert_raise(expected_class = StandardError, &block)
6
+ begin
7
+ block.call
8
+ assert_equal expected_class, nil
9
+ rescue ::Test::Unit::AssertionFailedError => e
10
+ # failed assert raises this Error and that extends StandardError, so rescue it first
11
+ raise e
12
+ rescue expected_class
13
+ assert true # passed
14
+ rescue => e
15
+ assert_equal(expected_class, e.class) # not expected one raised
16
+ end
17
+ end
18
+ end
@@ -1,10 +1,15 @@
1
1
  require "embulk/command/embulk_run"
2
2
 
3
- classpath_dir = Embulk.home("classpath")
4
- jars = Dir.entries(classpath_dir).select{|f| f =~ /\.jar$/ }.sort
5
- jars.each do |jar|
6
- require File.join(classpath_dir, jar)
3
+ if Embulk.respond_to?(:home)
4
+ # keep compatibility for Embulk 0.6.x
5
+ classpath_dir = Embulk.home("classpath")
6
+ jars = Dir.entries(classpath_dir).select{|f| f =~ /\.jar$/ }.sort
7
+ jars.each do |jar|
8
+ require File.join(classpath_dir, jar)
9
+ end
10
+ require "embulk/java/bootstrap"
11
+ require "embulk"
12
+ else
13
+ require "embulk"
14
+ Embulk.setup
7
15
  end
8
- require "embulk/java/bootstrap"
9
-
10
- require "embulk"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-marketo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - uu59
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-30 00:00:00.000000000 Z
12
+ date: 2015-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 2.11.1
20
20
  name: savon
@@ -22,13 +22,13 @@ dependencies:
22
22
  type: :runtime
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: 2.11.1
28
28
  - !ruby/object:Gem::Dependency
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  name: httpclient
@@ -36,16 +36,16 @@ dependencies:
36
36
  type: :runtime
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.6.13
48
- - - <
48
+ - - "<"
49
49
  - !ruby/object:Gem::Version
50
50
  version: '1.0'
51
51
  name: embulk
@@ -53,16 +53,16 @@ dependencies:
53
53
  type: :development
54
54
  version_requirements: !ruby/object:Gem::Requirement
55
55
  requirements:
56
- - - '>='
56
+ - - ">="
57
57
  - !ruby/object:Gem::Version
58
58
  version: 0.6.13
59
- - - <
59
+ - - "<"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.0'
62
62
  - !ruby/object:Gem::Dependency
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ~>
65
+ - - "~>"
66
66
  - !ruby/object:Gem::Version
67
67
  version: '1.0'
68
68
  name: bundler
@@ -70,13 +70,13 @@ dependencies:
70
70
  type: :development
71
71
  version_requirements: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.0'
76
76
  - !ruby/object:Gem::Dependency
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - '>='
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: '10.0'
82
82
  name: rake
@@ -84,13 +84,13 @@ dependencies:
84
84
  type: :development
85
85
  version_requirements: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '10.0'
90
90
  - !ruby/object:Gem::Dependency
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - '>='
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  name: pry
@@ -98,13 +98,13 @@ dependencies:
98
98
  type: :development
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  - !ruby/object:Gem::Dependency
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - '>='
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  name: test-unit
@@ -112,13 +112,13 @@ dependencies:
112
112
  type: :development
113
113
  version_requirements: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  - !ruby/object:Gem::Dependency
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - '>='
121
+ - - ">="
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  name: test-unit-rr
@@ -126,13 +126,13 @@ dependencies:
126
126
  type: :development
127
127
  version_requirements: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  - !ruby/object:Gem::Dependency
133
133
  requirement: !ruby/object:Gem::Requirement
134
134
  requirements:
135
- - - '>='
135
+ - - ">="
136
136
  - !ruby/object:Gem::Version
137
137
  version: '0'
138
138
  name: codeclimate-test-reporter
@@ -140,13 +140,13 @@ dependencies:
140
140
  type: :development
141
141
  version_requirements: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  - !ruby/object:Gem::Dependency
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
- - - '>='
149
+ - - ">="
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  name: everyleaf-embulk_helper
@@ -154,7 +154,7 @@ dependencies:
154
154
  type: :development
155
155
  version_requirements: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - '>='
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  description: Loads records from Marketo.
@@ -165,15 +165,20 @@ executables: []
165
165
  extensions: []
166
166
  extra_rdoc_files: []
167
167
  files:
168
- - .gitignore
169
- - .ruby-version
170
- - .travis.yml
168
+ - ".gitignore"
169
+ - ".ruby-version"
170
+ - ".travis.yml"
171
+ - ".travis.yml.erb"
171
172
  - CHANGELOG.md
172
173
  - Gemfile
173
174
  - LICENSE
174
175
  - README.md
175
176
  - Rakefile
176
177
  - embulk-input-marketo.gemspec
178
+ - gemfiles/embulk-0.6.0-latest
179
+ - gemfiles/embulk-0.6.13
180
+ - gemfiles/embulk-0.6.14
181
+ - gemfiles/embulk-0.6.15
177
182
  - gemfiles/embulk-0.6.16
178
183
  - gemfiles/embulk-0.6.17
179
184
  - gemfiles/embulk-0.6.18
@@ -185,12 +190,19 @@ files:
185
190
  - gemfiles/embulk-0.6.24
186
191
  - gemfiles/embulk-0.6.25
187
192
  - gemfiles/embulk-0.6.26
193
+ - gemfiles/embulk-0.6.27
194
+ - gemfiles/embulk-0.7.0
195
+ - gemfiles/embulk-0.7.0-latest
196
+ - gemfiles/embulk-0.7.1
197
+ - gemfiles/embulk-0.7.2
198
+ - gemfiles/embulk-0.7.3
199
+ - gemfiles/embulk-0.7.4
200
+ - gemfiles/embulk-0.7.5
188
201
  - gemfiles/embulk-latest
189
202
  - gemfiles/template.erb
190
203
  - lib/embulk/input/marketo/activity_log.rb
191
204
  - lib/embulk/input/marketo/base.rb
192
205
  - lib/embulk/input/marketo/lead.rb
193
- - lib/embulk/input/marketo/timeslice.rb
194
206
  - lib/embulk/input/marketo_api.rb
195
207
  - lib/embulk/input/marketo_api/soap/activity_log.rb
196
208
  - lib/embulk/input/marketo_api/soap/base.rb
@@ -205,6 +217,7 @@ files:
205
217
  - test/embulk/input/test_marketo_api.rb
206
218
  - test/lead_fixtures.rb
207
219
  - test/mute_logger.rb
220
+ - test/override_assert_raise.rb
208
221
  - test/prepare_embulk.rb
209
222
  - test/run-test.rb
210
223
  homepage: https://github.com/treasure-data/embulk-input-marketo
@@ -217,17 +230,17 @@ require_paths:
217
230
  - lib
218
231
  required_ruby_version: !ruby/object:Gem::Requirement
219
232
  requirements:
220
- - - '>='
233
+ - - ">="
221
234
  - !ruby/object:Gem::Version
222
235
  version: '0'
223
236
  required_rubygems_version: !ruby/object:Gem::Requirement
224
237
  requirements:
225
- - - '>='
238
+ - - ">="
226
239
  - !ruby/object:Gem::Version
227
240
  version: '0'
228
241
  requirements: []
229
242
  rubyforge_project:
230
- rubygems_version: 2.4.6
243
+ rubygems_version: 2.4.8
231
244
  signing_key:
232
245
  specification_version: 4
233
246
  summary: Marketo input plugin for Embulk
@@ -242,5 +255,6 @@ test_files:
242
255
  - test/embulk/input/test_marketo_api.rb
243
256
  - test/lead_fixtures.rb
244
257
  - test/mute_logger.rb
258
+ - test/override_assert_raise.rb
245
259
  - test/prepare_embulk.rb
246
260
  - test/run-test.rb
@@ -1,120 +0,0 @@
1
- module Embulk
2
- module Input
3
- module Marketo
4
- module Timeslice
5
- TIMESLICE_COUNT_PER_TASK = 24
6
-
7
- def self.included(klass)
8
- klass.extend ClassMethods
9
- end
10
-
11
- module ClassMethods
12
- def guess(config)
13
- if config.param(:last_updated_at, :string, default: nil)
14
- Embulk.logger.warn "config: last_updated_at is deprecated. Use from_datetime/to_datetime"
15
- end
16
-
17
- client = soap_client(config)
18
- metadata = client.metadata
19
-
20
- return {"columns" => generate_columns(metadata)}
21
- end
22
-
23
- def transaction(config, &control)
24
- endpoint_url = config.param(:endpoint, :string)
25
-
26
- if config.param(:last_updated_at, :string, default: nil)
27
- Embulk.logger.warn "config: last_updated_at is deprecated. Use from_datetime/to_datetime"
28
- end
29
-
30
- from_datetime = config.param(:from_datetime, :string)
31
- to_datetime = config.param(:to_datetime, :string, default: Time.now.to_s)
32
-
33
- # check from/to format to parse
34
- begin
35
- Time.parse(from_datetime)
36
- Time.parse(to_datetime)
37
- rescue => e
38
- # possibly Time.parse fail
39
- raise ConfigError, e.message
40
- end
41
-
42
- if Time.parse(from_datetime) > Time.parse(to_datetime)
43
- raise ConfigError, "config: from_datetime '#{from_datetime}' is later than '#{to_datetime}'."
44
- end
45
-
46
- ranges = timeslice(from_datetime, to_datetime, TIMESLICE_COUNT_PER_TASK)
47
- task = {
48
- endpoint_url: endpoint_url,
49
- wsdl_url: config.param(:wsdl, :string, default: "#{endpoint_url}?WSDL"),
50
- user_id: config.param(:user_id, :string),
51
- encryption_key: config.param(:encryption_key, :string),
52
- from_datetime: from_datetime,
53
- to_datetime: to_datetime,
54
- ranges: ranges,
55
- columns: config.param(:columns, :array)
56
- }
57
-
58
- columns = []
59
-
60
- task[:columns].each do |column|
61
- name = column["name"]
62
- type = column["type"].to_sym
63
-
64
- columns << Column.new(nil, name, type, column["format"])
65
- end
66
-
67
- resume(task, columns, ranges.size, &control)
68
- end
69
-
70
- def timeslice(from, to, count)
71
- generate_time_range(from, to).each_slice(count).to_a
72
- end
73
-
74
- def generate_time_range(from, to)
75
- # e.g. from = 2010-01-01 15:00, to = 2010-01-03 09:30
76
- # convert to such array:
77
- # [
78
- # {from: 2010-01-01 15:00, to: 2010-01-01 16:00},
79
- # {from: 2010-01-01 16:00, to: 2010-01-01 17:00},
80
- # ...
81
- # {from: 2010-01-03 08:00, to: 2010-01-03 09:00},
82
- # {from: 2010-01-03 09:00, to: 2010-01-03 09:30},
83
- # ]
84
- # to fetch data from Marketo API with each day as
85
- # desribed on official blog:
86
- # http://developers.marketo.com/blog/performance-tuning-api-requests/
87
- to ||= Time.now
88
- from = Time.parse(from) unless from.is_a?(Time)
89
- to = Time.parse(to) unless to.is_a?(Time)
90
-
91
- result = []
92
- since = from
93
- while since < to
94
- next_since = since + 3600
95
- if to < next_since
96
- next_since = to
97
- end
98
- result << {
99
- "from" => since,
100
- "to" => next_since
101
- }
102
- since = next_since
103
- end
104
- result
105
- end
106
-
107
- def resume(task, columns, count, &control)
108
- commit_reports = yield(task, columns, count)
109
-
110
- # When no task ran, commit_reports is empty
111
- return {} if commit_reports.empty?
112
- # all task returns same report as {from_datetime: to_datetime}
113
- return commit_reports.first
114
- end
115
-
116
- end
117
- end
118
- end
119
- end
120
- end