embulk-output-mailchimp 0.1.0 → 0.2.0

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: 45060c5aec8200c9d1806d466414c014834dec45
4
- data.tar.gz: 975cf885d3d90f9de70c7b9a119a96a4753ecfe9
3
+ metadata.gz: 828ea72b349e1c3137c5c827039a24046f0b1094
4
+ data.tar.gz: 79827b4b52ce3fda14e2ff75fe708a571f5afeca
5
5
  SHA512:
6
- metadata.gz: ca60d58b8698b777e14df5ced2e3ff82543d4a42979c8a9ac2fff606852e6249131956d0b3c6f8f7b3c51d37c0b7a22da68de6cfd2be746f24c3b0cd04c0eb4b
7
- data.tar.gz: 940b9ce3f294f45e3d5797b64df87a6003c8ff413c3441122a66f447dfd64869d5d066daef91e5a047425b1ee171de7577c1683d1acecae08699f9cae5789429
6
+ metadata.gz: ce1545eeac72c8dba741854e98fc0033f0977aaac094b5abcb2fb7c11e0a8b446822148f8c8b99baa9fb4595a2d2a9f25ab3c230456052288f8f229bca6f4f92
7
+ data.tar.gz: 49a7c2ebca979114062cd4568e40d7661b24cbfa6c60be6f585547b553a81f113409a42fb1c1c4dc8af61fed84ef9e7420ad459622ce6a667b844fdb332ff904
data/README.md CHANGED
@@ -21,6 +21,7 @@ add e-mail to List in MailChimp.
21
21
  - **email_column**: column name for email (string, default: 'email')
22
22
  - **fname_column**: column name for first name (string, default: 'fname')
23
23
  - **lname_column**: column name for last name(string, default: 'lname')
24
+ - **grouping_columns**: column names array for group name(array, default: nil)
24
25
 
25
26
  ## Example
26
27
 
@@ -35,6 +36,9 @@ out:
35
36
  email_column: 'e-mail'
36
37
  fname_column: 'first name'
37
38
  lname_column: 'lname'
39
+ grouping_columns:
40
+ - group_1
41
+ - group_2
38
42
  ```
39
43
 
40
44
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "embulk-output-mailchimp"
4
- spec.version = "0.1.0"
4
+ spec.version = "0.2.0"
5
5
  spec.authors = ["takkanm"]
6
6
  spec.summary = "Mailchimp output plugin for Embulk"
7
7
  spec.description = "Dumps records to Mailchimp."
@@ -36,6 +36,7 @@ module Embulk
36
36
  email_column: config.param("email_column", :string, default: "email"),
37
37
  fname_column: config.param("fname_column", :string, default: "fname"),
38
38
  lname_column: config.param("lname_column", :string, default: "lname"),
39
+ grouping_columns: config.param("grouping_columns", :array, default: nil),
39
40
  retry_limit: config.param("retry_limit", :integer, default: 5),
40
41
  retry_initial_wait_sec: config.param("retry_initial_wait_sec", :integer, default: 1),
41
42
  stop_on_invalid_record: config.param("stop_on_invalid_record", :bool, default: true),
@@ -58,6 +59,7 @@ module Embulk
58
59
  @email_column = task[:email_column]
59
60
  @fname_column = task[:fname_column]
60
61
  @lname_column = task[:lname_column]
62
+ @grouping_columns = task[:grouping_columns]
61
63
  @subscribers = []
62
64
 
63
65
  @retry_manager = PerfectRetry.new do |config|
@@ -110,6 +112,19 @@ module Embulk
110
112
  m[key] = row[col_name] if row[col_name]
111
113
  end
112
114
 
115
+ if @grouping_columns && !@grouping_columns.empty?
116
+ merge_vars[:groupings] = []
117
+
118
+ @grouping_columns.each do |group|
119
+ next if row[group].nil? || row[group] == ''
120
+
121
+ merge_vars[:groupings] << {
122
+ 'name' => group,
123
+ 'groups' => row[group].split(','),
124
+ }
125
+ end
126
+ end
127
+
113
128
  @subscribers << {
114
129
  EMAIL: {
115
130
  email: row[@email_column]
@@ -77,6 +77,8 @@ module Embulk
77
77
  {name: 'email', type: :string},
78
78
  {name: 'fname', type: :string},
79
79
  {name: 'lname', type: :string},
80
+ {name: 'list_group1', type: :string},
81
+ {name: 'list_group2', type: :string},
80
82
  ]),
81
83
  1
82
84
  )
@@ -87,6 +89,10 @@ module Embulk
87
89
  [['a@example.com', 'first', 'last']]
88
90
  end
89
91
 
92
+ def page_with_groupings
93
+ [['a@example.com', 'first', 'last', 'group_1,group_2', 'group_3,group_4']]
94
+ end
95
+
90
96
  def test_stop_on_invalid_record_is_false
91
97
  mailchimp = create_mailchimp(
92
98
  lname_column: 'lname',
@@ -100,6 +106,25 @@ module Embulk
100
106
  assert_equal(subscriber[:merge_vars][:fname], 'first')
101
107
  assert_equal(subscriber[:merge_vars][:lname], 'last')
102
108
  end
109
+
110
+ def test_grouping_columns
111
+ mailchimp = create_mailchimp(
112
+ lname_column: 'lname',
113
+ fname_column: 'fname',
114
+ grouping_columns: ['list_group1', 'list_group2']
115
+ )
116
+
117
+ mailchimp.add(page_with_groupings)
118
+ subscriber = mailchimp.instance_variable_get(:@subscribers)[0]
119
+
120
+ assert_equal(
121
+ subscriber[:merge_vars][:groupings],
122
+ [
123
+ {'name' => 'list_group1', 'groups' => %w(group_1 group_2)},
124
+ {'name' => 'list_group2', 'groups' => %w(group_3 group_4)},
125
+ ]
126
+ )
127
+ end
103
128
  end
104
129
 
105
130
  # NOTE skip until const mocking
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-mailchimp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takkanm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-24 00:00:00.000000000 Z
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement