emarsys 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/README.md +42 -38
  4. data/lib/emarsys/client.rb +11 -5
  5. data/lib/emarsys/configuration.rb +54 -0
  6. data/lib/emarsys/data_object.rb +16 -23
  7. data/lib/emarsys/data_objects/condition.rb +2 -2
  8. data/lib/emarsys/data_objects/contact.rb +27 -25
  9. data/lib/emarsys/data_objects/contact_list.rb +8 -8
  10. data/lib/emarsys/data_objects/email.rb +19 -19
  11. data/lib/emarsys/data_objects/email_category.rb +2 -2
  12. data/lib/emarsys/data_objects/event.rb +8 -8
  13. data/lib/emarsys/data_objects/export.rb +4 -4
  14. data/lib/emarsys/data_objects/field.rb +5 -5
  15. data/lib/emarsys/data_objects/file.rb +8 -8
  16. data/lib/emarsys/data_objects/folder.rb +2 -2
  17. data/lib/emarsys/data_objects/form.rb +2 -2
  18. data/lib/emarsys/data_objects/language.rb +2 -2
  19. data/lib/emarsys/data_objects/segment.rb +2 -2
  20. data/lib/emarsys/data_objects/source.rb +6 -6
  21. data/lib/emarsys/error.rb +4 -0
  22. data/lib/emarsys/request.rb +9 -8
  23. data/lib/emarsys/response.rb +9 -11
  24. data/lib/emarsys/version.rb +1 -1
  25. data/lib/emarsys.rb +6 -18
  26. data/spec/emarsys/client_spec.rb +13 -9
  27. data/spec/emarsys/configuration_spec.rb +22 -0
  28. data/spec/emarsys/data_object_spec.rb +11 -11
  29. data/spec/emarsys/data_objects/contact_spec.rb +12 -12
  30. data/spec/emarsys/data_objects/email_launch_status_spec.rb +1 -1
  31. data/spec/emarsys/data_objects/email_spec.rb +5 -5
  32. data/spec/emarsys/data_objects/email_status_code_spec.rb +1 -1
  33. data/spec/emarsys/data_objects/event_spec.rb +3 -3
  34. data/spec/emarsys/data_objects/field_spec.rb +1 -1
  35. data/spec/emarsys/data_objects/file_spec.rb +5 -5
  36. data/spec/emarsys/data_objects/folder_spec.rb +1 -1
  37. data/spec/emarsys/data_objects/source_spec.rb +1 -1
  38. data/spec/emarsys/request_spec.rb +1 -1
  39. data/spec/emarsys/response_spec.rb +17 -12
  40. data/spec/emarsys_spec.rb +1 -7
  41. data/spec/spec_helper.rb +1 -0
  42. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ae8a2be8a9eb47480f0dfa43f730039a5fc8129
4
- data.tar.gz: 97ac47f4b22dc3eca4146573fb714aa7c7104280
3
+ metadata.gz: c006c15b3aa1bc20e0660c77d7003d4d03084db4
4
+ data.tar.gz: a9561b3ba62ecf8f9e4830ef615fe4001d415a84
5
5
  SHA512:
6
- metadata.gz: deb3b4aa58dad053e9bf7fb61e87146d118a83e9eee652f1d6076195a29935138b147982fb3a128bb65d7f3d03f59efee3acddb981fc337a31005d4a3c4c6545
7
- data.tar.gz: 7022cdbe34e40380b0c17ff50860055acdd036a037435debb72d89c95b09eb2542a2ca93e691a7964629cc5d43dd8d75d8020d602739b95af2953d9253e4d866
6
+ metadata.gz: 291d6f93c68a17a9a67fa805dc3d8b24f28b0871957f0daa2d54f2e5adb48572c3f85451a218e8b803d827aca0df6c2d7eefbeb7681196a7a5404920506b591a
7
+ data.tar.gz: e93647e7963726a2a97c6b177084a4f3d62b52b0262460e66c79d11d7695bb5ce67d82e11ec0a975f5e2e1cd89d41fae39594808431f0d19b873d566284c6123
data/CHANGELOG.md ADDED
@@ -0,0 +1,32 @@
1
+ # Changelog
2
+
3
+ ## HEAD (not yet released)
4
+
5
+ * Return response, not just (parsed) body of it ([#29](https://github.com/Absolventa/emarsys-rb/pull/29)). To migrate existing code, you need to call `#data` on the
6
+ response object.
7
+ * Allow to configure multiple Emarsys accounts. This is optional, existing configuration continues to work unchanged, however, you will need to add `Emarsys.allow_default_configuration = true` ([#30](https://github.com/Absolventa/emarsys-rb/pull/30))
8
+ * Migrate API calls to keyword arguments (also in [#30](https://github.com/Absolventa/emarsys-rb/pull/30))
9
+
10
+ ## v0.2.3
11
+
12
+ * Convert params when using the batch APIs ([#25](https://github.com/Absolventa/emarsys-rb/pull/25))
13
+
14
+ ## v0.2.2
15
+
16
+ * Allow batch updates to create missing contacts ([#22](https://github.com/Absolventa/emarsys-rb/pull/22))
17
+ * Add support for the data export API ([#23]((https://github.com/Absolventa/emarsys-rb/pull/23))
18
+
19
+ ## v0.2.1
20
+
21
+ * Added basic support for rate-limiting response from Emarsys API ([#21](https://github.com/Absolventa/emarsys-rb/pull/21))
22
+
23
+ ## v0.2.0
24
+ * Added country mapping ([#17](https://github.com/Absolventa/emarsys-rb/pull/17))
25
+ * Proper encoding of GET parameters ([#11](https://github.com/Absolventa/emarsys-rb/pull/11))
26
+ * Update default endpoint fom `suite5.emarsys.net/api/v2` to `api.emarsys.net/api/v2` ([#10](https://github.com/Absolventa/emarsys-rb/pull/10))
27
+ * Bugfixes in nonce header ([#5](https://github.com/Absolventa/emarsys-rb/pull/5) and [#19](https://github.com/Absolventa/emarsys-rb/pull/19))
28
+ * Trigger an external event for multiple contacts ([#3](https://github.com/Absolventa/emarsys-rb/pull/3))
29
+
30
+ ## v0.1.0
31
+
32
+ Initial version
data/README.md CHANGED
@@ -40,6 +40,20 @@ Emarsys.configure do |c|
40
40
  end
41
41
  ```
42
42
 
43
+ It is also possible to configure multiple Emarsys accounts like this:
44
+
45
+ ```ruby
46
+ Emarsys.configure(account: :foo) do |c|
47
+ c.api_username = 'foo_username'
48
+ c.api_password = 'foo_password'
49
+ end
50
+
51
+ Emarsys.configure(account: :bar) do |c|
52
+ c.api_username = 'bar_username'
53
+ c.api_password = 'bar_password'
54
+ end
55
+ ```
56
+
43
57
  ### Field Mapping
44
58
 
45
59
  As said before, Emarsys loves IDs. For using an API, they are evil. This gem provides
@@ -86,7 +100,24 @@ If you exceed the limit, the Emarsys API returns an HTTP 429 'Too Many Requests'
86
100
 
87
101
  ## Interacting with the API
88
102
 
89
- You can interact with the API on the provided data objects:
103
+ ### Responses
104
+
105
+ Each API request returns a response object, which exposes the following methods:
106
+
107
+ * `code`: HTTP status code
108
+ * `text`: 'replyText' from parsed JSON
109
+ * `data`: 'data' from parsed JSON
110
+ * `code`: 'replyCode' from parsed JSON
111
+
112
+ If the `replyCode` is not `0`, an exception will be raised.
113
+
114
+ ### Multiple accounts
115
+ If you configured multiple Emarsys accounts, you will need to pass the keyword
116
+ argument `account` to every API call, e.g.
117
+ `Emarsys::Condition.collection(account: :foo)`.
118
+
119
+
120
+ ### Endpoints
90
121
 
91
122
  #### Condition
92
123
 
@@ -99,12 +130,12 @@ Emarsys::Condition.collection
99
130
 
100
131
  ```ruby
101
132
  # Create a contact with custom key_field (one example with mapped identifier, one without)
102
- Emarsys::Contact.create('user_id', 10, {firstname: "Jane", lastname: "Doe", email: "jane.doe@example.com"})
103
- Emarsys::Contact.create(4980, 10, {1 => "Jane", 2 => "Doe", 3 => "jane.doe@example.com"})
133
+ Emarsys::Contact.create(key_id: 'user_id', key_value: 10, params: {firstname: "Jane", lastname: "Doe", email: "jane.doe@example.com"})
134
+ Emarsys::Contact.create(key_id: 4980, key_value: 10, params: {1 => "Jane", 2 => "Doe", 3 => "jane.doe@example.com"})
104
135
 
105
136
  # Update a contact with key_field (one example with mapped identifier, one without)
106
- Emarsys::Contact.update('email', "jane.doe@example.com", {firstname: "John", lastname: "Doe"})
107
- Emarsys::Contact.update(3, "jane.doe@example.com", {1 => "John", 2 => "Doe"})
137
+ Emarsys::Contact.update(key_id: 'email', key_value: "jane.doe@example.com", params: {firstname: "John", lastname: "Doe"})
138
+ Emarsys::Contact.update(key_id: 3, key_value: "jane.doe@example.com", params: {1 => "John", 2 => "Doe"})
108
139
  ```
109
140
 
110
141
  #### ContactList
@@ -128,9 +159,9 @@ Emarsys::Email.collection(status: 3)
128
159
  Emarsys::Email.resource(1)
129
160
 
130
161
  # Create a new email campaign
131
- Emarsys::Email.create({})
162
+ Emarsys::Email.create
132
163
 
133
- Emarsys::Email.launch({})
164
+ Emarsys::Email.launch(1)
134
165
  ```
135
166
 
136
167
  #### Event
@@ -139,11 +170,11 @@ Emarsys::Email.launch({})
139
170
  Emarsys::Event.collection
140
171
 
141
172
  # Trigger a custom event
142
- Emarsys::Event.trigger(65, 3, ["test@example.com"])
173
+ Emarsys::Event.trigger(65, key_id: 3, external_id: "test@example.com")
143
174
 
144
175
  # Trigger a custom event which actually sends a mail
145
176
  # (Emarsys way to send transactional mails with placeholders)
146
- Emarsys::Event.trigger(2, 3, 'test@example.com', {:global => {:my_placeholder => "some content"}})
177
+ Emarsys::Event.trigger(2, key_id: 3, external_id: 'test@example.com', data: {:global => {:my_placeholder => "some content"}})
147
178
  ```
148
179
 
149
180
  #### Export
@@ -164,7 +195,7 @@ Emarsys::Field.choice(1)
164
195
  ```ruby
165
196
  # Get all forms, optional filter parameters
166
197
  Emarsys::Folder.collection
167
- Emarsys::Folder.collection(:folder => 3)
198
+ Emarsys::Folder.collection(folder: 3)
168
199
  ```
169
200
 
170
201
  #### Form
@@ -195,7 +226,7 @@ Emarsys::Segment.collection
195
226
  Emarsys::Source.collection
196
227
 
197
228
  # Create a new source
198
- Emarsys::Source.create("New Source")
229
+ Emarsys::Source.create(name: "New Source")
199
230
 
200
231
  # Destroy a source
201
232
  Emarsys::Source.destroy(123)
@@ -204,33 +235,6 @@ Emarsys::Source.destroy(123)
204
235
  Please refer to the code for detailed instructions of each method.
205
236
 
206
237
 
207
- ## Changelog
208
-
209
- ### HEAD (not yet released)
210
-
211
- ### v0.2.3
212
-
213
- * Convert params when using the batch APIs ([#25](https://github.com/Absolventa/emarsys-rb/pull/25))
214
-
215
- ### v0.2.2
216
-
217
- * Allow batch updates to create missing contacts ([#22](https://github.com/Absolventa/emarsys-rb/pull/22))
218
- * Add support for the data export API ([#23]((https://github.com/Absolventa/emarsys-rb/pull/23))
219
-
220
- ### v0.2.1
221
-
222
- * Added basic support for rate-limiting response from Emarsys API ([#21](https://github.com/Absolventa/emarsys-rb/pull/21))
223
-
224
- ### v0.2.0
225
- * Added country mapping ([#17](https://github.com/Absolventa/emarsys-rb/pull/17))
226
- * Proper encoding of GET parameters ([#11](https://github.com/Absolventa/emarsys-rb/pull/11))
227
- * Update default endpoint fom `suite5.emarsys.net/api/v2` to `api.emarsys.net/api/v2` ([#10](https://github.com/Absolventa/emarsys-rb/pull/10))
228
- * Bugfixes in nonce header ([#5](https://github.com/Absolventa/emarsys-rb/pull/5) and [#19](https://github.com/Absolventa/emarsys-rb/pull/19))
229
- * Trigger an external event for multiple contacts ([#3](https://github.com/Absolventa/emarsys-rb/pull/3))
230
-
231
- ### v0.1.0
232
-
233
- Initial version
234
238
 
235
239
  ## Contributing
236
240
 
@@ -1,15 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
  module Emarsys
3
3
  class Client
4
+ attr_accessor :account
5
+
6
+ def initialize(account = nil)
7
+ self.account = account
8
+ end
9
+
10
+ def endpoint
11
+ Emarsys::Configuration.for(account).api_endpoint
12
+ end
4
13
 
5
14
  def username
6
- raise ArgumentError, "Emarsys.api_username is not set" if Emarsys.api_username.nil?
7
- Emarsys.api_username
15
+ Emarsys::Configuration.for(account).api_username
8
16
  end
9
17
 
10
18
  def password
11
- raise ArgumentError, "Emarsys.api_password is not set" if Emarsys.api_password.nil?
12
- Emarsys.api_password
19
+ Emarsys::Configuration.for(account).api_password
13
20
  end
14
21
 
15
22
  def x_wsse_string
@@ -33,6 +40,5 @@ module Emarsys
33
40
  def calculated_digest
34
41
  Digest::SHA1.hexdigest(header_nonce + header_created + password)
35
42
  end
36
-
37
43
  end
38
44
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ module Emarsys
3
+ class Configuration
4
+
5
+ class << self
6
+ attr_accessor :config_sets
7
+
8
+ def for(account)
9
+ self.config_sets ||= {}
10
+ if account.nil?
11
+ raise Emarsys::AccountRequired unless Emarsys.allow_default_configuration
12
+ account = :default
13
+ end
14
+ account_sym = account.to_sym
15
+ if self.config_sets[account_sym].nil?
16
+ raise Emarsys::AccountNotConfigured
17
+ end
18
+ self.config_sets[account_sym]
19
+ end
20
+
21
+ def configure(account: :default)
22
+ self.config_sets ||= {}
23
+ account_sym = account.to_sym
24
+ self.config_sets[account_sym] ||= self.new
25
+ yield self.config_sets[account_sym]
26
+ end
27
+ end
28
+
29
+ # @!attribute api_endpoint
30
+ # @return [String] Base URL for emarsys URLs. default: https://api.emarsys.net/api/v2
31
+ # @!attribute api_password
32
+ # @return [String] API Username given by Emarsys
33
+ # @!attribute api_username
34
+ # @return [String] API Username given by Emarsys
35
+
36
+ attr_writer :api_endpoint, :api_username, :api_password
37
+
38
+ # Base URL for the Emarsys API
39
+ #
40
+ # @return [String] domain which should be used to query the API
41
+ def api_endpoint
42
+ @api_endpoint ||= 'https://api.emarsys.net/api/v2'
43
+ end
44
+
45
+ def api_username
46
+ @api_username or raise ArgumentError.new('api_username is not set')
47
+ end
48
+
49
+ def api_password
50
+ @api_password or raise ArgumentError.new('api_password is not set')
51
+ end
52
+
53
+ end
54
+ end
@@ -7,42 +7,46 @@ module Emarsys
7
7
 
8
8
  # Make a HTTP GET request
9
9
  #
10
+ # @param account [Symbol] Configuration account to use
10
11
  # @param method_name [String] The path, relative to Emarsys.api_endpoint
11
12
  # @param params [Hash] custom params hash
12
13
  # @return [Hash]
13
- def get(method_name, params)
14
+ def get(account, method_name, params)
14
15
  if params.empty?
15
- self.new.request 'get', method_name, params
16
+ self.new.request account, 'get', method_name, params
16
17
  else
17
- self.new.request 'get', [method_name, parameterize_params(params)].join("/"), {}
18
+ self.new.request account, 'get', [method_name, parameterize_params(params)].join("/"), {}
18
19
  end
19
20
  end
20
21
 
21
22
  # Make a HTTP POST request
22
23
  #
24
+ # @param account [Symbol] Configuration account to use
23
25
  # @param method_name [String] The path, relative to Emarsys.api_endpoint
24
26
  # @param params [Hash] custom params hash
25
27
  # @return [Hash]
26
- def post(method_name, params)
27
- self.new.request 'post', method_name, params
28
+ def post(account, method_name, params)
29
+ self.new.request account, 'post', method_name, params
28
30
  end
29
31
 
30
32
  # Make a HTTP PUT request
31
33
  #
34
+ # @param account [Symbol] Configuration account to use
32
35
  # @param method_name [String] The path, relative to Emarsys.api_endpoint
33
36
  # @param params [Hash] custom params hash
34
37
  # @return [Hash]
35
- def put(method_name, params)
36
- self.new.request 'put', method_name, params
38
+ def put(account, method_name, params)
39
+ self.new.request account, 'put', method_name, params
37
40
  end
38
41
 
39
42
  # Make a HTTP DELETE request
40
43
  #
44
+ # @param account [Symbol] Configuration account to use
41
45
  # @param method_name [String] The path, relative to Emarsys.api_endpoint
42
46
  # @param params [Hash] custom params hash
43
47
  # @return [Hash]
44
- def delete(method_name, params)
45
- self.new.request 'delete', method_name, params
48
+ def delete(account, method_name, params)
49
+ self.new.request account, 'delete', method_name, params
46
50
  end
47
51
 
48
52
  # Custom Parameterizer for Emarsys
@@ -64,24 +68,13 @@ module Emarsys
64
68
 
65
69
  # Make a HTTP request
66
70
  #
71
+ # @param account [Symbol] Configuration account to use
67
72
  # @param http_verb [String] Http method
68
73
  # @param method_name [String] The path, relative to Emarsys.api_endpoint
69
74
  # @param params [Hash] custom params hash
70
75
  # @return [Hash]
71
- def request(http_verb, method_name, params)
72
- response = Emarsys::Request.new(http_verb, method_name, params).send_request
73
- #hashiefy(response)
76
+ def request(account, http_verb, method_name, params)
77
+ response = Emarsys::Request.new(account, http_verb, method_name, params).send_request
74
78
  end
75
-
76
- # TODO: Not finally evaluated. Is Hashie necessary? Maybe use "real Data Objects instead"?
77
- # def hashiefy(response)
78
- # if response.is_a?(Array)
79
- # response.map!{|elem| Hashie::Mash.new(elem) }
80
- # elsif
81
- # Hashie::Mash.new(response)
82
- # else
83
- # response
84
- # end
85
- # end
86
79
  end
87
80
  end
@@ -12,8 +12,8 @@ module Emarsys
12
12
  # @return [Hash] List of conditions
13
13
  # @example
14
14
  # Emarsys::Condition.collection
15
- def collection
16
- get 'condition', {}
15
+ def collection(account: nil)
16
+ get account, 'condition', {}
17
17
  end
18
18
  end
19
19
 
@@ -16,9 +16,9 @@ module Emarsys
16
16
  # @example
17
17
  # Emarsys::Contact.create('app_id', 23, {:firstname => "Jon", :lastname => "Doe"})
18
18
  # Emarsys::Contact.create('3', 'john.doe@example.com', {'1' => "Jon", '2' => "Doe"})
19
- def create(key_id, key_value, params = {})
19
+ def create(key_id:, key_value:, params: {}, account: nil)
20
20
  transformed_key_id = transform_key_id(key_id)
21
- post "contact", params.merge!({'key_id' => transformed_key_id, transformed_key_id => key_value})
21
+ post account, "contact", params.merge!({'key_id' => transformed_key_id, transformed_key_id => key_value})
22
22
  end
23
23
 
24
24
  # Get the interal emarsys id of a contact. The given params are transformed to emarsys ids.
@@ -29,8 +29,8 @@ module Emarsys
29
29
  # @example
30
30
  # Emarsys::Contact.emarsys_id('email', 'john.dow@example.com')
31
31
  # Emarsys::Contact.emarsys_id(1, 'John')
32
- def emarsys_id(key_id, key_value)
33
- get "contact", {"#{transform_key_id(key_id).to_s}" => key_value}
32
+ def emarsys_id(key_id:, key_value:, account: nil)
33
+ get account, "contact", {"#{transform_key_id(key_id).to_s}" => key_value}
34
34
  end
35
35
 
36
36
  # Update a contact. The given params are transformed to emarsys ids.
@@ -43,10 +43,10 @@ module Emarsys
43
43
  # @example
44
44
  # Emarsys::Contact.update('app_id', 23, {:firstname => "Jon", :lastname => "Doe"})
45
45
  # Emarsys::Contact.update('3', 'john.doe@example.com', {'1' => "Jon", '2' => "Doe"}, true)
46
- def update(key_id, key_value, params = {}, create_if_not_exists = false)
46
+ def update(key_id:, key_value:, params: {}, create_if_not_exists: false, account: nil)
47
47
  path = "contact#{create_if_not_exists ? '/?create_if_not_exists=1' : ''}"
48
48
  transformed_key_id = transform_key_id(key_id)
49
- put path, params.merge!({'key_id' => transformed_key_id, transformed_key_id => key_value})
49
+ put account, path, params.merge!({'key_id' => transformed_key_id, transformed_key_id => key_value})
50
50
  end
51
51
 
52
52
  # Batch creation of contacts.
@@ -59,12 +59,8 @@ module Emarsys
59
59
  # {:app_id => 2, :firstname => "Jane", :lastname => "Doe"}
60
60
  # )
61
61
  #
62
- # TODO params should be parameterized with field mappings
63
- def create_batch(key_id, params = [])
64
- converted_params = params.map do |p|
65
- Emarsys::ParamsConverter.new(p).convert_to_ids
66
- end
67
- post "contact", {'key_id' => transform_key_id(key_id), 'contacts' => converted_params}
62
+ def create_batch(key_id:, params: [], account: nil)
63
+ post account, "contact", {'key_id' => transform_key_id(key_id), 'contacts' => batch_params(params)}
68
64
  end
69
65
 
70
66
  # Batch update of contacts.
@@ -80,22 +76,19 @@ module Emarsys
80
76
  # true
81
77
  # )
82
78
  #
83
- def update_batch(key_id, params = [], create_if_not_exists = false)
79
+ def update_batch(key_id:, params: [], create_if_not_exists: false, account: nil)
84
80
  path = "contact#{create_if_not_exists ? '/?create_if_not_exists=1' : ''}"
85
- converted_params = params.map do |p|
86
- Emarsys::ParamsConverter.new(p).convert_to_ids
87
- end
88
- put path, {'key_id' => transform_key_id(key_id), 'contacts' => converted_params}
81
+ put account, path, {'key_id' => transform_key_id(key_id), 'contacts' => batch_params(params)}
89
82
  end
90
83
 
91
84
  # Get list of emails send to a contact
92
85
  #
93
- # @param contact_ids_array [array] Array of contact ids
86
+ # @param contacts [array] Array of contact ids
94
87
  # @return [Hash] result data
95
88
  # @example
96
89
  # Emarsys::Contact.contact_history([1,2,3]
97
- def contact_history(contact_ids_array)
98
- post "contact/getcontacthistory", {'contacts' => contact_ids_array}
90
+ def contact_history(contacts:, account: nil)
91
+ post account, "contact/getcontacthistory", {'contacts' => contacts}
99
92
  end
100
93
 
101
94
  # Get contact data by custom search
@@ -105,11 +98,11 @@ module Emarsys
105
98
  # @param fields [array] requested fields. If empty, all are considered
106
99
  # @return [Hash] result data
107
100
  # @example
108
- # Emarsys::Contact.search('3', ['john.doe@example.com'], [1,2,3]
101
+ # Emarsys::Contact.search('3', ['john.doe@example.com'], [1,2,3])
109
102
  #
110
103
  # TODO transform fields to numeric fields
111
- def search(key_id, key_values = [], fields = [])
112
- post "contact/getdata", {'keyId' => key_id, 'keyValues' => key_values, 'fields' => fields}
104
+ def search(key_id:, key_values:, fields: [], account: nil)
105
+ post account, "contact/getdata", {'keyId' => key_id, 'keyValues' => key_values, 'fields' => fields}
113
106
  end
114
107
 
115
108
  # Exports the selected fields of contacts whoch registered in the specified time range
@@ -118,8 +111,12 @@ module Emarsys
118
111
  # @return [Hash] result data
119
112
  # @example
120
113
  # Emarsys::Contact.export_registrations(distribution_method: 'local', time_range: ["2013-01-01","2013-12-31"], contact_fields: [1,2,3])
121
- def export_registrations(params = {})
122
- post "contact/getregistrations", params
114
+ def export_registrations(distribution_method:, time_range:, contact_fields:, account: nil)
115
+ post account, "contact/getregistrations", {
116
+ distribution_method: distribution_method,
117
+ time_range: time_range,
118
+ contact_fields: contact_fields
119
+ }
123
120
  end
124
121
 
125
122
  # @private
@@ -128,6 +125,11 @@ module Emarsys
128
125
  matching_attributes.nil? ? key_id : matching_attributes[:id]
129
126
  end
130
127
 
128
+ # @private
129
+ def batch_params(params = [])
130
+ params.map { |p| Emarsys::ParamsConverter.new(p).convert_to_ids }
131
+ end
132
+
131
133
  end
132
134
  end
133
135
  end
@@ -12,8 +12,8 @@ module Emarsys
12
12
  # @return [Hash] List of contact_lists
13
13
  # @example
14
14
  # Emarsys::ContactList.collection
15
- def collection
16
- get 'contactlist', {}
15
+ def collection(account: nil)
16
+ get account, 'contactlist', {}
17
17
  end
18
18
 
19
19
  # Create a new contact list
@@ -25,22 +25,22 @@ module Emarsys
25
25
  # @return [Hash] internal id of the contact list
26
26
  # @example
27
27
  # Emarsys::ContactList.create(key_id: "3", name: 'Test-Liste', description: 'Something')
28
- def create(params = {})
29
- post "contactlist", params
28
+ def create(account: nil, **params)
29
+ post account, "contactlist", params
30
30
  end
31
31
 
32
32
  # Add a contacts to a specific contact list
33
33
  #
34
34
  # This cannot be an instance method, because the API does not allow to retrieve a single resource. How crappy is that?
35
- def add_contacts(contact_list_id, key_id, external_ids = [])
36
- post "contactlist/#{contact_list_id}/add", {'key_id' => key_id, 'external_ids' => external_ids}
35
+ def add_contacts(id, key_id:, external_ids: [], account: nil)
36
+ post account, "contactlist/#{id}/add", {'key_id' => key_id, 'external_ids' => external_ids}
37
37
  end
38
38
 
39
39
  # Remove contacts from a specific contact list
40
40
  #
41
41
  # This cannot be an instance method, because the API does not allow to retrieve a single resource. How crappy is that?
42
- def remove_contacts(contact_list_id, key_id, external_ids = [])
43
- post "contactlist/#{contact_list_id}/remove", {'key_id' => key_id, 'external_ids' => external_ids}
42
+ def remove_contacts(id, key_id:, external_ids: [], account: nil)
43
+ post account, "contactlist/#{id}/remove", {'key_id' => key_id, 'external_ids' => external_ids}
44
44
  end
45
45
 
46
46
  end
@@ -17,8 +17,8 @@ module Emarsys
17
17
  # Emarsys::Email.collection
18
18
  # Emarsys::Email.collection(:status => 3)
19
19
  # Emarsys::Email.collection(:contactlist => 5)
20
- def collection(params = {})
21
- get 'email', params
20
+ def collection(account: nil, **params)
21
+ get account, 'email', params
22
22
  end
23
23
 
24
24
  # Get Email attirbutes of a specific email
@@ -27,8 +27,8 @@ module Emarsys
27
27
  # @return [Hash] Attributes hash
28
28
  # @example
29
29
  # Emarsys::Email.resource(1)
30
- def resource(id)
31
- get "email/#{id}", {}
30
+ def resource(id, account: nil)
31
+ get account, "email/#{id}", {}
32
32
  end
33
33
 
34
34
  # Create a new email campaign
@@ -53,8 +53,8 @@ module Emarsys
53
53
  # subject: 'Test Subject', :email_category: 3, segment: 1121, contactlist: 0,
54
54
  # html_source: '<h1>Test</h1>', text_source: 'Test'
55
55
  # )
56
- def create(params = {})
57
- post "email", params
56
+ def create(account: nil, **params)
57
+ post account, "email", params
58
58
  end
59
59
 
60
60
  # Launches an email
@@ -66,8 +66,8 @@ module Emarsys
66
66
  # @return [Hash] Result data
67
67
  # @example
68
68
  # Emarsys::Email.launch(1)
69
- def launch(id, params = {})
70
- post "email/#{id}/launch", params
69
+ def launch(id, account: nil, **params)
70
+ post account, "email/#{id}/launch", params
71
71
  end
72
72
 
73
73
  # Preview an email
@@ -77,8 +77,8 @@ module Emarsys
77
77
  # @return [Hash] Result data
78
78
  # @example
79
79
  # Emarsys::Email.preview(1)
80
- def preview(id, version = 'html')
81
- post "email/#{id}/preview", {:version => version}
80
+ def preview(id, version: 'html', account: nil)
81
+ post account, "email/#{id}/preview", {:version => version}
82
82
  end
83
83
 
84
84
  # View response summary of an email
@@ -87,8 +87,8 @@ module Emarsys
87
87
  # @return [Hash] Result data
88
88
  # @example
89
89
  # Emarsys::Email.response_summary(1)
90
- def response_summary(id)
91
- get "email/#{id}/responsesummary", {}
90
+ def response_summary(id, account: nil)
91
+ get account, "email/#{id}/responsesummary", {}
92
92
  end
93
93
 
94
94
  # Instruct emarsys to send a test mail
@@ -103,8 +103,8 @@ module Emarsys
103
103
  # @return [Hash] Result data
104
104
  # @example
105
105
  # Emarsys::Email.send_test_mail(1, {:recipientlist => 'john.doe@example.com;jane.doe@example.com'})
106
- def send_test_mail(id, params = {})
107
- post "email/#{id}/sendtestmail", params
106
+ def send_test_mail(id, account: nil, **params)
107
+ post account, "email/#{id}/sendtestmail", params
108
108
  end
109
109
 
110
110
  # Returns the delivery status of an email
@@ -116,12 +116,12 @@ module Emarsys
116
116
  # @return [Hash] Result data
117
117
  # @example
118
118
  # Emarsys::Email.delivery_status(1)
119
- def delivery_status(id, params = {})
120
- post "email/#{id}/getdeliverystatus", params
119
+ def delivery_status(id, account: nil, **params)
120
+ post account, "email/#{id}/getdeliverystatus", params
121
121
  end
122
122
 
123
123
  # TODO POST /getlaunchesofemail
124
- def email_launches(id)
124
+ def email_launches(id, account: nil)
125
125
  raise "Not implemented yet"
126
126
  end
127
127
 
@@ -143,7 +143,7 @@ module Emarsys
143
143
  # ['trackable_links'],
144
144
  # [5, 8, 13]
145
145
  # )
146
- def export_responses(distribution_method, time_range, contact_fields, sources, analysis_fields, params = {})
146
+ def export_responses(distribution_method:, time_range:, contact_fields:, sources:, analysis_fields:, account: nil, **params)
147
147
  params.merge!(
148
148
  :distribution_method => distribution_method,
149
149
  :time_range => time_range,
@@ -151,7 +151,7 @@ module Emarsys
151
151
  :sources => sources,
152
152
  :analysis_fields => analysis_fields
153
153
  )
154
- post "email/getresponses", params
154
+ post account, "email/getresponses", params
155
155
  end
156
156
  end
157
157
  end
@@ -12,8 +12,8 @@ module Emarsys
12
12
  # @return [Hash] List of email_categories
13
13
  # @example
14
14
  # Emarsys::EmailCategory.collection
15
- def collection
16
- get 'emailcategory', {}
15
+ def collection(account: nil)
16
+ get account, 'emailcategory', {}
17
17
  end
18
18
 
19
19
  end