embulk-output-mailchimp 0.2.0 → 0.2.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: 828ea72b349e1c3137c5c827039a24046f0b1094
4
- data.tar.gz: 79827b4b52ce3fda14e2ff75fe708a571f5afeca
3
+ metadata.gz: 263d6be5b427f50337210f1f42e92a9ca85fea18
4
+ data.tar.gz: 3b798a92f1358a5331f2b19b358c96eda65b5ea6
5
5
  SHA512:
6
- metadata.gz: ce1545eeac72c8dba741854e98fc0033f0977aaac094b5abcb2fb7c11e0a8b446822148f8c8b99baa9fb4595a2d2a9f25ab3c230456052288f8f229bca6f4f92
7
- data.tar.gz: 49a7c2ebca979114062cd4568e40d7661b24cbfa6c60be6f585547b553a81f113409a42fb1c1c4dc8af61fed84ef9e7420ad459622ce6a667b844fdb332ff904
6
+ metadata.gz: 1aaf3df35727fc7df1bcb609d0e0cba5dbb6242e6469b75cc6307b10cb1ff2e8f11379d2c34f2312148a4c07422426779abe9b25504004c599aafea4fc05c679
7
+ data.tar.gz: 6b9c2537a67c6168b02d5f1656730972a5732e5f03fdb36cb9e645da4965b78d9b5fbefb8b22e43ae2d9c0254db4fd1f46094a65541d00b2033801df5d78d648
@@ -2,8 +2,7 @@ language: jruby
2
2
  before_install:
3
3
  - rvm get head --auto-dotfiles
4
4
  - rvm install jruby-9.0.1.0
5
- - gem install bundler
6
- - gem update bundler
5
+ - gem install bundler --version 1.10.6
7
6
  - bundle install
8
7
  script:
9
8
  - bundle exec rake cov
@@ -0,0 +1,5 @@
1
+ ## 0.2.1 - 2016-01-06
2
+
3
+ - Logging API request/response [#5](https://github.com/treasure-data/embulk-output-mailchimp/pull/5)
4
+ - Default `double_optin` to be `false` [#6](https://github.com/treasure-data/embulk-output-mailchimp/pull/6)
5
+ - Fixed when non-string groups given [#7](https://github.com/treasure-data/embulk-output-mailchimp/pull/7)
data/README.md CHANGED
@@ -41,6 +41,9 @@ out:
41
41
  - group_2
42
42
  ```
43
43
 
44
+ ## Mailchimp Client
45
+
46
+ use https://bitbucket.org/mailchimp/mailchimp-api-ruby .
44
47
 
45
48
  ## Build
46
49
 
@@ -1,11 +1,11 @@
1
1
 
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "embulk-output-mailchimp"
4
- spec.version = "0.2.0"
5
- spec.authors = ["takkanm"]
4
+ spec.version = "0.2.1"
5
+ spec.authors = ["uu59", "takkanm"]
6
6
  spec.summary = "Mailchimp output plugin for Embulk"
7
7
  spec.description = "Dumps records to Mailchimp."
8
- spec.email = ["takkanm@gmail.com"]
8
+ spec.email = ["k@uu59.org", "takkanm@gmail.com"]
9
9
  spec.licenses = ["MIT"]
10
10
  # TODO set this: spec.homepage = "https://github.com/takkanm/embulk-output-mailchimp"
11
11
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.add_dependency 'perfect_retry', "~> 0.3"
19
19
 
20
20
  spec.add_development_dependency 'embulk', ['~> 0.7.9']
21
- spec.add_development_dependency 'bundler', ['~> 1.0']
21
+ spec.add_development_dependency 'bundler', ['~> 1.10.6']
22
22
  spec.add_development_dependency 'rake', ['>= 10.0']
23
23
  spec.add_development_dependency 'test-unit'
24
24
  spec.add_development_dependency 'test-unit-rr'
@@ -1,6 +1,8 @@
1
1
  require 'mailchimp'
2
2
  require 'perfect_retry'
3
3
 
4
+ require 'securerandom'
5
+
4
6
  module Embulk
5
7
  module Output
6
8
 
@@ -30,7 +32,7 @@ module Embulk
30
32
  task = {
31
33
  apikey: config.param("apikey", :string),
32
34
  list_id: config.param("list_id", :string),
33
- double_optin: config.param("double_optin", :bool, default: true),
35
+ double_optin: config.param("double_optin", :bool, default: false),
34
36
  update_existing: config.param("update_existing", :bool, default: false),
35
37
  replace_interests: config.param("replace_interests", :bool, default: true),
36
38
  email_column: config.param("email_column", :string, default: "email"),
@@ -103,11 +105,22 @@ module Embulk
103
105
 
104
106
  private
105
107
 
108
+ # NOTE we expect row has #{email_column} column.
109
+ # expected full data is following columns.
110
+ # | #{email_column} | #{fname_column} | #{lname_column} | #{grouping_columns[0]} | #{grouping_columns[1]…|
111
+ # |-----------------|-----------------|-----------------|------------------------|-----------------------|
112
+ # | hi@example.com | first_name | last_name | music,book | middle |
106
113
  def add_subscriber(row)
107
114
  return unless row[@email_column]
108
115
 
109
116
  merge_columns = {fname: @fname_column, lname: @lname_column}
110
117
 
118
+ # NOTE merge_vars can add extra infomation.
119
+ # https://apidocs.mailchimp.com/api/2.0/lists/merge-vars.php
120
+ # embulk-output-mailchimp can add following infomation
121
+ # - lname
122
+ # - fname
123
+ # - interest group
111
124
  merge_vars = merge_columns.each_with_object({}) do |(key, col_name), m|
112
125
  m[key] = row[col_name] if row[col_name]
113
126
  end
@@ -116,11 +129,12 @@ module Embulk
116
129
  merge_vars[:groupings] = []
117
130
 
118
131
  @grouping_columns.each do |group|
119
- next if row[group].nil? || row[group] == ''
132
+ groups = row[group].to_s.split(",")
133
+ next if groups.empty?
120
134
 
121
135
  merge_vars[:groupings] << {
122
136
  'name' => group,
123
- 'groups' => row[group].split(','),
137
+ 'groups' => groups,
124
138
  }
125
139
  end
126
140
  end
@@ -142,13 +156,16 @@ module Embulk
142
156
 
143
157
  def send_subscribers!
144
158
  @retry_manager.with_retry do
145
- @client.batch_subscribe_list(
159
+ request_id = SecureRandom.uuid
160
+ Embulk.logger.info "[#{request_id}] Request : #{@subscribers.size} items"
161
+ res = @client.batch_subscribe_list(
146
162
  @list_id,
147
163
  @subscribers,
148
164
  @double_optin,
149
165
  @update_existing,
150
166
  @replace_interests
151
167
  )
168
+ Embulk.logger.info "[#{request_id}] Result : #{res.to_s}"
152
169
  end
153
170
  end
154
171
  end
@@ -125,6 +125,28 @@ module Embulk
125
125
  ]
126
126
  )
127
127
  end
128
+
129
+ def test_grouping_columns_not_string
130
+ groups_1 = 42
131
+ groups_2 = 1.3
132
+
133
+ mailchimp = create_mailchimp(
134
+ lname_column: 'lname',
135
+ fname_column: 'fname',
136
+ grouping_columns: ['list_group1', 'list_group2']
137
+ )
138
+
139
+ mailchimp.add([['i@example.com', 'lname', 'fname', groups_1, groups_2]])
140
+ subscriber = mailchimp.instance_variable_get(:@subscribers)[0]
141
+
142
+ assert_equal(
143
+ subscriber[:merge_vars][:groupings],
144
+ [
145
+ {'name' => 'list_group1', 'groups' => [groups_1.to_s] },
146
+ {'name' => 'list_group2', 'groups' => [groups_2.to_s] },
147
+ ]
148
+ )
149
+ end
128
150
  end
129
151
 
130
152
  # NOTE skip until const mocking
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-mailchimp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
+ - uu59
7
8
  - takkanm
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-12-09 00:00:00.000000000 Z
12
+ date: 2016-01-06 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  requirement: !ruby/object:Gem::Requirement
@@ -57,7 +58,7 @@ dependencies:
57
58
  requirements:
58
59
  - - "~>"
59
60
  - !ruby/object:Gem::Version
60
- version: '1.0'
61
+ version: 1.10.6
61
62
  name: bundler
62
63
  prerelease: false
63
64
  type: :development
@@ -65,7 +66,7 @@ dependencies:
65
66
  requirements:
66
67
  - - "~>"
67
68
  - !ruby/object:Gem::Version
68
- version: '1.0'
69
+ version: 1.10.6
69
70
  - !ruby/object:Gem::Dependency
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
@@ -138,6 +139,7 @@ dependencies:
138
139
  version: '0'
139
140
  description: Dumps records to Mailchimp.
140
141
  email:
142
+ - k@uu59.org
141
143
  - takkanm@gmail.com
142
144
  executables: []
143
145
  extensions: []
@@ -147,6 +149,7 @@ files:
147
149
  - ".gitignore"
148
150
  - ".ruby-version"
149
151
  - ".travis.yml"
152
+ - CHANGELOG.md
150
153
  - Gemfile
151
154
  - LICENSE.txt
152
155
  - README.md