emarsys 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +8 -0
  3. data/Gemfile +0 -6
  4. data/README.md +118 -64
  5. data/emarsys.gemspec +3 -1
  6. data/lib/emarsys/client.rb +7 -9
  7. data/lib/emarsys/country.rb +220 -0
  8. data/lib/emarsys/data_object.rb +12 -3
  9. data/lib/emarsys/data_objects/condition.rb +2 -1
  10. data/lib/emarsys/data_objects/contact.rb +3 -2
  11. data/lib/emarsys/data_objects/contact_list.rb +2 -1
  12. data/lib/emarsys/data_objects/email.rb +2 -1
  13. data/lib/emarsys/data_objects/email_category.rb +2 -1
  14. data/lib/emarsys/data_objects/email_launch_status.rb +2 -1
  15. data/lib/emarsys/data_objects/email_status_code.rb +2 -1
  16. data/lib/emarsys/data_objects/event.rb +18 -1
  17. data/lib/emarsys/data_objects/export.rb +2 -1
  18. data/lib/emarsys/data_objects/field.rb +2 -1
  19. data/lib/emarsys/data_objects/file.rb +2 -1
  20. data/lib/emarsys/data_objects/folder.rb +2 -1
  21. data/lib/emarsys/data_objects/form.rb +2 -1
  22. data/lib/emarsys/data_objects/language.rb +2 -1
  23. data/lib/emarsys/data_objects/segment.rb +2 -1
  24. data/lib/emarsys/data_objects/source.rb +2 -1
  25. data/lib/emarsys/error.rb +2 -1
  26. data/lib/emarsys/extensions.rb +2 -1
  27. data/lib/emarsys/field_mapping.rb +2 -1
  28. data/lib/emarsys/params_converter.rb +2 -1
  29. data/lib/emarsys/request.rb +2 -1
  30. data/lib/emarsys/response.rb +2 -1
  31. data/lib/emarsys/version.rb +2 -1
  32. data/lib/emarsys.rb +5 -3
  33. data/spec/emarsys/client_spec.rb +25 -24
  34. data/spec/emarsys/country_spec.rb +22 -0
  35. data/spec/emarsys/data_object_spec.rb +14 -9
  36. data/spec/emarsys/data_objects/condition_spec.rb +4 -2
  37. data/spec/emarsys/data_objects/contact_list_spec.rb +4 -2
  38. data/spec/emarsys/data_objects/contact_spec.rb +17 -17
  39. data/spec/emarsys/data_objects/email_category_spec.rb +4 -2
  40. data/spec/emarsys/data_objects/email_spec.rb +31 -21
  41. data/spec/emarsys/data_objects/event_spec.rb +16 -6
  42. data/spec/emarsys/data_objects/export_spec.rb +4 -2
  43. data/spec/emarsys/data_objects/field_spec.rb +10 -4
  44. data/spec/emarsys/data_objects/file_spec.rb +11 -7
  45. data/spec/emarsys/data_objects/folder_spec.rb +7 -3
  46. data/spec/emarsys/data_objects/form_spec.rb +4 -2
  47. data/spec/emarsys/data_objects/language_spec.rb +4 -2
  48. data/spec/emarsys/data_objects/segment_spec.rb +4 -2
  49. data/spec/emarsys/data_objects/source_spec.rb +8 -6
  50. data/spec/emarsys/field_mapping_spec.rb +4 -4
  51. data/spec/emarsys/params_converter_spec.rb +2 -2
  52. data/spec/emarsys/request_spec.rb +2 -2
  53. data/spec/emarsys/response_spec.rb +5 -5
  54. data/spec/emarsys_spec.rb +2 -2
  55. data/spec/spec_helper.rb +2 -4
  56. metadata +48 -25
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f8428e2c40d3634ec723d6344c78b04ecc42ef4
4
+ data.tar.gz: 1e68cfc41427960d604cc562ceb05a7a30b2cdf5
5
+ SHA512:
6
+ metadata.gz: 683eba0ca8b1166136a8943e8a9381c6d58f563899f020cc60fb063bc0febcc62919e7b2c61e5ca48f2f9e604a9abc08d179c85ec0bc236e97cbf4fced9fad07
7
+ data.tar.gz: c680377e2abe42b2e03f70c46bbe5446669825438db4776a5f1d4ce8c496aa951a5dffa74b09a83909eee8abca251e4bdcf98c739a05133d2776f214bbf4f165
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache:
4
+ bundler: true
5
+ rvm:
6
+ - jruby-9.0.5.0
7
+ - 2.2.2
8
+ - 2.3.1
data/Gemfile CHANGED
@@ -2,10 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in emarsys.gemspec
4
4
 
5
- group :test do
6
- gem 'rspec', '~> 2.13.0'
7
- gem 'webmock', '~> 1.9.0'
8
- end
9
-
10
-
11
5
  gemspec
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # emarsys-rb
1
+ # emarsys-rb [![Build Status](https://travis-ci.org/Absolventa/emarsys-rb.svg?branch=master)](https://travis-ci.org/Absolventa/emarsys-rb)
2
2
 
3
3
  Simple Ruby wrapper for the Emarsys API.
4
4
 
@@ -23,38 +23,58 @@ This gem tries to work around this by letting you specify a field mapping consta
23
23
  * Return values differ from method to method due to the way the Emarsys API is implemented.
24
24
  Thus, a Hash as a return value or an Array of Hashes was choosen as the global return object. Basically it is a parsed JSON response.
25
25
  * Please refer to the Emarsys API documentation for detailed information on parameters, return values or error codes.
26
+ * The list of available countries is defined by Emarsys, and uses internal Emarsys-specific IDs. A utility class is
27
+ provided to map [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 "ISO 3166-1 alpha-2") data (aka 2-letter country codes) to internal Emarsys country IDs.
26
28
 
27
29
  ## Configuration and Setup
28
30
  ### Authentication
29
31
 
30
32
  Authenticate with the api credentials provided by your Emarsys account manager.
31
33
 
32
- Emarsys.configure do |c|
33
- c.api_username = 'my_username'
34
- c.api_password = 'my_password'
35
- # OPTIONAL, defaults to https://suite5.emarsys.net/api/v2
36
- c.api_endpoint = 'https://www.emarsys.net/api/v2'
37
- end
34
+ ```ruby
35
+ Emarsys.configure do |c|
36
+ c.api_username = 'my_username'
37
+ c.api_password = 'my_password'
38
+ # OPTIONAL, defaults to https://api.emarsys.net/api/v2
39
+ c.api_endpoint = 'https://suite5.emarsys.net/api/v2'
40
+ end
41
+ ```
38
42
 
39
43
  ### Field Mapping
40
44
 
41
- As said before, Emarsys loves IDs. For using an APi, they are evil. This Gem provides
45
+ As said before, Emarsys loves IDs. For using an API, they are evil. This gem provides
42
46
  an easy way to adjust the individual field settings. Internally a Ruby Mapping Constant is used,
43
47
  which that can be overwritten. It will be picked up automatically. E.g.:
44
48
 
45
- # Complete overwrite
46
- Emarsys::FieldMapping::ATTRIBUTES = [
47
- {:id => 0, :identifier => 'interests', :name => 'Interests'},
48
- {:id => 1, :identifier => 'firstname', :name => 'First Name'},
49
- {:id => 2, :identifier => 'lastname', :name => 'Last Name'},
50
- ]
49
+ ```ruby
50
+ # Complete overwrite
51
+ Emarsys::FieldMapping::ATTRIBUTES = [
52
+ {:id => 0, :identifier => 'interests', :name => 'Interests'},
53
+ {:id => 1, :identifier => 'firstname', :name => 'First Name'},
54
+ {:id => 2, :identifier => 'lastname', :name => 'Last Name'},
55
+ ]
51
56
 
52
- # Add to the Mapping-Constant
53
- Emarsys::FieldMapping::ATTRIBUTES << {:id => 100, :identifier => 'user_id', :name => "User-ID"}
57
+ # Add to the Mapping-Constant
58
+ Emarsys::FieldMapping::ATTRIBUTES << {:id => 100, :identifier => 'user_id', :name => "User-ID"}
59
+ ```
54
60
 
55
61
  All Emarsys predefined system fields are prefixed with an underscore, e.g. '_firstname' or '_revenue' in order to not
56
62
  clash with individual mappings.
57
63
 
64
+ ### Mapping Country IDs from ISO country codes
65
+
66
+ A utility method is provided to map to Emarsys internal country IDs from ISO 3166-1 alpha-2 two-letter country codes. You can pass a symbol or a string, and case is ignored.
67
+
68
+ ```ruby
69
+ >> Emarsys::Country.from_iso('GB')
70
+ => {:id=>184, :name=>"United Kingdom"}
71
+
72
+ >> Emarsys::Country.from_iso(:af)
73
+ => {:id=>1, :name=>"Afghanistan"}
74
+
75
+ >> Emarsys::Country.from_iso('us')
76
+ => {:id=>185, :name=>"United States of America"}
77
+ ```
58
78
 
59
79
  ## Interacting with the API
60
80
 
@@ -62,100 +82,134 @@ You can interact with the API on the provided data objects:
62
82
 
63
83
  #### Condition
64
84
 
65
- # Get all conditions
66
- Emarsys::Condition.collection
85
+ ```ruby
86
+ # Get all conditions
87
+ Emarsys::Condition.collection
88
+ ```
67
89
 
68
90
  #### Contact
69
91
 
70
- # Create a contact with custom key_field (one example with mapped identifier, one without)
71
- Emarsys::Contact.create('user_id', 10, {firstname: "Jane", lastname: "Doe", email: "jane.doe@example.com"})
72
- Emarsys::Contact.create(4980, 10, {1 => "Jane", 2 => "Doe", 3 => "jane.doe@example.com"})
92
+ ```ruby
93
+ # Create a contact with custom key_field (one example with mapped identifier, one without)
94
+ Emarsys::Contact.create('user_id', 10, {firstname: "Jane", lastname: "Doe", email: "jane.doe@example.com"})
95
+ Emarsys::Contact.create(4980, 10, {1 => "Jane", 2 => "Doe", 3 => "jane.doe@example.com"})
73
96
 
74
- # Update a contact with key_field (one example with mapped identifier, one without)
75
- Emarsys::Contact.update('email', "jane.doe@example.com", {firstname: "John", lastname: "Doe"})
76
- Emarsys::Contact.update(3, "jane.doe@example.com", {1 => "John", 2 => "Doe"})
97
+ # Update a contact with key_field (one example with mapped identifier, one without)
98
+ Emarsys::Contact.update('email', "jane.doe@example.com", {firstname: "John", lastname: "Doe"})
99
+ Emarsys::Contact.update(3, "jane.doe@example.com", {1 => "John", 2 => "Doe"})
100
+ ```
77
101
 
78
102
  #### ContactList
79
103
 
80
- # Get all contact_lists
81
- Emarsys::ContactList.collection
104
+ ```ruby
105
+ # Get all contact_lists
106
+ Emarsys::ContactList.collection
82
107
 
83
- # Create a contact list
84
- Emarsys::ContactList.create
108
+ # Create a contact list
109
+ Emarsys::ContactList.create
110
+ ```
85
111
 
86
112
  #### Emails
87
113
 
88
- # Get all email campaigns, optional filter
89
- Emarsys::Email.collection
90
- Emarsys::Email.collection(status: 3)
114
+ ```ruby
115
+ # Get all email campaigns, optional filter
116
+ Emarsys::Email.collection
117
+ Emarsys::Email.collection(status: 3)
91
118
 
92
- # Get a single email resource
93
- Emarsys::Email.resource(1)
119
+ # Get a single email resource
120
+ Emarsys::Email.resource(1)
94
121
 
95
- # Create a new email campaign
96
- Emarsys::Email.create({})
122
+ # Create a new email campaign
123
+ Emarsys::Email.create({})
97
124
 
98
- Emarsys::Email.launch({})
125
+ Emarsys::Email.launch({})
126
+ ```
99
127
 
100
128
  #### Event
101
129
 
102
- Emarsys::Event.collection
130
+ ```ruby
131
+ Emarsys::Event.collection
103
132
 
104
- # Trigger a custom event
105
- Emarsys::Event.trigger(65, 3, ["test@example.com"])
133
+ # Trigger a custom event
134
+ Emarsys::Event.trigger(65, 3, ["test@example.com"])
106
135
 
107
- # Trigger a custom event which actually sends a mail
108
- # (Emarsys way to send transactional mails with placeholders)
109
- Emarsys::Event.trigger(2, 3, 'test@example.com', {:global => {:my_placeholder => "some content"}})
136
+ # Trigger a custom event which actually sends a mail
137
+ # (Emarsys way to send transactional mails with placeholders)
138
+ Emarsys::Event.trigger(2, 3, 'test@example.com', {:global => {:my_placeholder => "some content"}})
139
+ ```
110
140
 
111
141
  #### Export
112
142
 
113
- Emarsys::Export.resource(1)
143
+ ```ruby
144
+ Emarsys::Export.resource(1)
145
+ ```
114
146
 
115
147
  #### Field
116
148
 
117
- Emarsys::Field.collection
118
- Emarsys::Field.choice(1)
149
+ ```ruby
150
+ Emarsys::Field.collection
151
+ Emarsys::Field.choice(1)
152
+ ```
119
153
 
120
154
  #### Folder
121
155
 
122
- # Get all forms, optional filter parameters
123
- Emarsys::Folder.collection
124
- Emarsys::Folder.collection(:folder => 3)
156
+ ```ruby
157
+ # Get all forms, optional filter parameters
158
+ Emarsys::Folder.collection
159
+ Emarsys::Folder.collection(:folder => 3)
160
+ ```
125
161
 
126
162
  #### Form
127
163
 
128
- # Get all forms
129
- Emarsys::Form.collection
164
+ ```ruby
165
+ # Get all forms
166
+ Emarsys::Form.collection
167
+ ```
130
168
 
131
169
  #### Language
132
170
 
133
- # Get all languages
134
- Emarsys::Language.collection
171
+ ```ruby
172
+ # Get all languages
173
+ Emarsys::Language.collection
174
+ ```
135
175
 
136
176
  #### Segment
137
177
 
138
- # Get all segments
139
- Emarsys::Segment.collection
178
+ ```ruby
179
+ # Get all segments
180
+ Emarsys::Segment.collection
181
+ ```
140
182
 
141
183
  #### Source
142
184
 
143
- # Get all sources
144
- Emarsys::Source.collection
185
+ ```ruby
186
+ # Get all sources
187
+ Emarsys::Source.collection
145
188
 
146
- # Create a new source
147
- Emarsys::Source.create("New Source")
148
-
149
- # Destroy a source
150
- Emarsys::Source.destroy(123)
189
+ # Create a new source
190
+ Emarsys::Source.create("New Source")
151
191
 
192
+ # Destroy a source
193
+ Emarsys::Source.destroy(123)
194
+ ```
152
195
 
153
196
  Please refer to the code for detailed instructions of each method.
154
197
 
155
- ## Ruby Versions
156
198
 
157
- This gem was developed and tested with versions 1.9.3 and 2.0.0
199
+ ## Changelog
200
+
201
+ ### HEAD (not yet released)
202
+
203
+ ### v0.2.0
204
+ * Added country mapping ([#17](https://github.com/Absolventa/emarsys-rb/pull/17))
205
+ * Proper encoding of GET parameters ([#11](https://github.com/Absolventa/emarsys-rb/pull/11))
206
+ * Update default endpoint fom `suite5.emarsys.net/api/v2` to `api.emarsys.net/api/v2` ([#10](https://github.com/Absolventa/emarsys-rb/pull/10))
207
+ * Bugfixes in nonce header ([#5](https://github.com/Absolventa/emarsys-rb/pull/5) and [#19](https://github.com/Absolventa/emarsys-rb/pull/19))
208
+ * Trigger an external event for multiple contacts ([#3](https://github.com/Absolventa/emarsys-rb/pull/3))
209
+
210
+ ### v0.1.0
158
211
 
212
+ Initial version
159
213
 
160
214
  ## Contributing
161
215
 
@@ -168,4 +222,4 @@ This gem was developed and tested with versions 1.9.3 and 2.0.0
168
222
 
169
223
  ## Copyright
170
224
 
171
- Copyright (c) 2013 Daniel Schoppmann. See LICENSE.txt for details.
225
+ Copyright (c) 2013 Daniel Schoppmann. See LICENSE.txt for details.
data/emarsys.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["daniel.schoppmann@absolventa.de"]
11
11
  spec.description = %q{A Ruby library for interacting with the Emarsys API.}
12
12
  spec.summary = %q{Easy to use ruby library for Emarsys Marketing Suite.}
13
- spec.homepage = "http://www.absolventa.de"
13
+ spec.homepage = "https://github.com/Absolventa/emarsys-rb"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -22,4 +22,6 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec", ">= 3.5.0"
26
+ spec.add_development_dependency "webmock", "< 2.0"
25
27
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
  class Client
3
4
 
@@ -12,12 +13,9 @@ module Emarsys
12
13
  end
13
14
 
14
15
  def x_wsse_string
15
- string = 'UsernameToken '
16
- string += 'Username = "' + username + '", '
17
- string += 'PasswordDigest = "' + header_password_digest + '", '
18
- string += 'Nonce = "' + header_nonce + '", '
19
- string += 'Created = "' + header_created + '"'
20
- string
16
+ <<-STRING.strip
17
+ UsernameToken Username="#{username}", PasswordDigest="#{header_password_digest}", Nonce="#{header_nonce}", Created="#{header_created}"
18
+ STRING
21
19
  end
22
20
 
23
21
  def header_password_digest
@@ -25,11 +23,11 @@ module Emarsys
25
23
  end
26
24
 
27
25
  def header_nonce
28
- Digest::MD5.hexdigest(Time.new.to_i.to_s)
26
+ @header_nonce ||= Random::DEFAULT.bytes(16).each_byte.map { |b| sprintf("%02X",b) }.join
29
27
  end
30
28
 
31
29
  def header_created
32
- Time.new.strftime("%Y-%m-%d %H:%M:%S")
30
+ Time.now.utc.iso8601
33
31
  end
34
32
 
35
33
  def calculated_digest
@@ -37,4 +35,4 @@ module Emarsys
37
35
  end
38
36
 
39
37
  end
40
- end
38
+ end
@@ -0,0 +1,220 @@
1
+ # frozen_string_literal: true
2
+ module Emarsys
3
+ module Country
4
+
5
+ module_function
6
+
7
+ def from_iso(iso)
8
+ MAPPING[iso.to_s.upcase]
9
+ end
10
+
11
+ MAPPING = {
12
+ 'AF' => {id: 1, name: 'Afghanistan'},
13
+ 'AL' => {id: 2, name: 'Albania'},
14
+ 'DZ' => {id: 3, name: 'Algeria'},
15
+ 'AD' => {id: 4, name: 'Andorra'},
16
+ 'AO' => {id: 5, name: 'Angola'},
17
+ 'AG' => {id: 6, name: 'Antigua and Barbuda'},
18
+ 'AR' => {id: 7, name: 'Argentina'},
19
+ 'AM' => {id: 8, name: 'Armenia'},
20
+ 'AU' => {id: 9, name: 'Australia'},
21
+ 'AT' => {id: 10, name: 'Austria'},
22
+ 'AZ' => {id: 11, name: 'Azerbaijan'},
23
+ 'BS' => {id: 12, name: 'Bahamas'},
24
+ 'BH' => {id: 13, name: 'Bahrain'},
25
+ 'BD' => {id: 14, name: 'Bangladesh'},
26
+ 'BB' => {id: 15, name: 'Barbados'},
27
+ 'BY' => {id: 16, name: 'Belarus'},
28
+ 'BE' => {id: 17, name: 'Belgium'},
29
+ 'BZ' => {id: 18, name: 'Belize'},
30
+ 'BJ' => {id: 19, name: 'Benin'},
31
+ 'BT' => {id: 20, name: 'Bhutan'},
32
+ 'BO' => {id: 21, name: 'Bolivia'},
33
+ 'BA' => {id: 22, name: 'Bosnia and Herzegovina'},
34
+ 'BW' => {id: 23, name: 'Botswana'},
35
+ 'BR' => {id: 24, name: 'Brazil'},
36
+ 'BN' => {id: 25, name: 'Brunei Darussalam'},
37
+ 'BG' => {id: 26, name: 'Bulgaria'},
38
+ 'BF' => {id: 27, name: 'Burkina Faso'},
39
+ # id 28 is 'Burma' - instead, use Myanmar (120)
40
+ 'BI' => {id: 29, name: 'Burundi'},
41
+ 'KH' => {id: 30, name: 'Cambodia'},
42
+ 'CM' => {id: 31, name: 'Cameroon'},
43
+ 'CA' => {id: 32, name: 'Canada'},
44
+ 'CV' => {id: 33, name: 'Cape Verde'},
45
+ 'CF' => {id: 34, name: 'Central African Republic'},
46
+ 'TD' => {id: 35, name: 'Chad'},
47
+ 'CL' => {id: 36, name: 'Chile'},
48
+ 'CN' => {id: 37, name: 'China'},
49
+ 'CO' => {id: 38, name: 'Colombia'},
50
+ 'KM' => {id: 39, name: 'Comoros'},
51
+ 'CG' => {id: 40, name: 'Congo'},
52
+ 'CD' => {id: 41, name: 'Congo, Democratic Republic of the'},
53
+ 'CR' => {id: 42, name: 'Costa Rica'},
54
+ 'CI' => {id: 43, name: 'Cote d’Ivoire'},
55
+ 'HR' => {id: 44, name: 'Croatia'},
56
+ 'CU' => {id: 45, name: 'Cuba'},
57
+ 'CY' => {id: 46, name: 'Cyprus'},
58
+ 'CZ' => {id: 47, name: 'Czech Republic'},
59
+ 'DK' => {id: 48, name: 'Denmark'},
60
+ 'DJ' => {id: 49, name: 'Djibouti'},
61
+ 'DM' => {id: 50, name: 'Dominica'},
62
+ 'DO' => {id: 51, name: 'Dominican Republic'},
63
+ 'EC' => {id: 52, name: 'Ecuador'},
64
+ 'EG' => {id: 53, name: 'Egypt'},
65
+ 'SV' => {id: 54, name: 'El Salvador'},
66
+ 'GQ' => {id: 55, name: 'Equatorial Guinea'},
67
+ 'ER' => {id: 56, name: 'Eritrea'},
68
+ 'EE' => {id: 57, name: 'Estonia'},
69
+ 'ET' => {id: 58, name: 'Ethiopia'},
70
+ 'FJ' => {id: 59, name: 'Fiji'},
71
+ 'FI' => {id: 60, name: 'Finland'},
72
+ 'FR' => {id: 61, name: 'France'},
73
+ 'GA' => {id: 62, name: 'Gabon'},
74
+ 'GM' => {id: 63, name: 'Gambia, The'},
75
+ 'GE' => {id: 64, name: 'Georgia'},
76
+ 'DE' => {id: 65, name: 'Germany'},
77
+ 'GH' => {id: 66, name: 'Ghana'},
78
+ 'GR' => {id: 67, name: 'Greece'},
79
+ 'GD' => {id: 68, name: 'Grenada'},
80
+ 'GT' => {id: 69, name: 'Guatemala'},
81
+ 'GN' => {id: 70, name: 'Guinea'},
82
+ 'GW' => {id: 71, name: 'Guinea-Bissau'},
83
+ 'GY' => {id: 72, name: 'Guyana'},
84
+ 'HT' => {id: 73, name: 'Haiti'},
85
+ 'HN' => {id: 74, name: 'Honduras'},
86
+ 'HU' => {id: 75, name: 'Hungary'},
87
+ 'IS' => {id: 76, name: 'Iceland'},
88
+ 'IN' => {id: 77, name: 'India'},
89
+ 'ID' => {id: 78, name: 'Indonesia'},
90
+ 'IR' => {id: 79, name: 'Iran'},
91
+ 'IQ' => {id: 80, name: 'Iraq'},
92
+ 'IE' => {id: 81, name: 'Ireland'},
93
+ 'IL' => {id: 82, name: 'Israel'},
94
+ 'IT' => {id: 83, name: 'Italy'},
95
+ 'JM' => {id: 84, name: 'Jamaica'},
96
+ 'JP' => {id: 85, name: 'Japan'},
97
+ 'JO' => {id: 86, name: 'Jordan'},
98
+ 'KZ' => {id: 87, name: 'Kazakhstan'},
99
+ 'KE' => {id: 88, name: 'Kenya'},
100
+ 'KI' => {id: 89, name: 'Kiribati'},
101
+ 'KP' => {id: 90, name: 'Korea, North'},
102
+ 'KR' => {id: 91, name: 'Korea, South'},
103
+ 'KW' => {id: 92, name: 'Kuwait'},
104
+ 'KG' => {id: 93, name: 'Kyrgyzstan'},
105
+ 'LO' => {id: 94, name: 'Laos'},
106
+ 'LV' => {id: 95, name: 'Latvia'},
107
+ 'LB' => {id: 96, name: 'Lebanon'},
108
+ 'LS' => {id: 97, name: 'Lesotho'},
109
+ 'LR' => {id: 98, name: 'Liberia'},
110
+ 'LY' => {id: 99, name: 'Libya'},
111
+ 'LI' => {id: 100, name: 'Liechtenstein'},
112
+ 'LT' => {id: 101, name: 'Lithuania'},
113
+ 'LU' => {id: 102, name: 'Luxembourg'},
114
+ 'MK' => {id: 103, name: 'Macedonia'},
115
+ 'MG' => {id: 104, name: 'Madagascar'},
116
+ 'MW' => {id: 105, name: 'Malawi'},
117
+ 'MY' => {id: 106, name: 'Malaysia'},
118
+ 'MV' => {id: 107, name: 'Maldives'},
119
+ 'ML' => {id: 108, name: 'Mali'},
120
+ 'MT' => {id: 109, name: 'Malta'},
121
+ 'MH' => {id: 110, name: 'Marshall Islands'},
122
+ 'MR' => {id: 111, name: 'Mauritania'},
123
+ 'MU' => {id: 112, name: 'Mauritius'},
124
+ 'MX' => {id: 113, name: 'Mexico'},
125
+ 'MI' => {id: 114, name: 'Micronesia'},
126
+ 'MD' => {id: 115, name: 'Moldova'},
127
+ 'MC' => {id: 116, name: 'Monaco'},
128
+ 'MN' => {id: 117, name: 'Mongolia'},
129
+ 'MA' => {id: 118, name: 'Morocco'},
130
+ 'MZ' => {id: 119, name: 'Mozambique'},
131
+ 'MM' => {id: 120, name: 'Myanmar'},
132
+ 'NA' => {id: 121, name: 'Namibia'},
133
+ 'NR' => {id: 122, name: 'Nauru'},
134
+ 'NP' => {id: 123, name: 'Nepal'},
135
+ 'NL' => {id: 124, name: 'The Netherlands'},
136
+ 'NZ' => {id: 125, name: 'New Zealand'},
137
+ 'NI' => {id: 126, name: 'Nicaragua'},
138
+ 'NE' => {id: 127, name: 'Niger'},
139
+ 'NG' => {id: 128, name: 'Nigeria'},
140
+ 'NO' => {id: 129, name: 'Norway'},
141
+ 'OM' => {id: 130, name: 'Oman'},
142
+ 'PK' => {id: 131, name: 'Pakistan'},
143
+ 'PW' => {id: 132, name: 'Palau'},
144
+ 'PA' => {id: 134, name: 'Panama'},
145
+ 'PG' => {id: 135, name: 'Papua New Guinea'},
146
+ 'PU' => {id: 136, name: 'Paraguay'},
147
+ 'PE' => {id: 137, name: 'Peru'},
148
+ 'PH' => {id: 138, name: 'Philippines'},
149
+ 'PL' => {id: 139, name: 'Poland'},
150
+ 'PT' => {id: 140, name: 'Portugal'},
151
+ 'QA' => {id: 141, name: 'Qatar'},
152
+ 'RO' => {id: 142, name: 'Romania'},
153
+ 'RU' => {id: 143, name: 'Russia'},
154
+ 'RW' => {id: 144, name: 'Rwanda'},
155
+ 'KN' => {id: 145, name: 'St. Kitts and Nevis'},
156
+ 'LC' => {id: 146, name: 'St. Lucia'},
157
+ 'VC' => {id: 147, name: 'St. Vincent and The Grenadines'},
158
+ 'WS' => {id: 148, name: 'Samoa'},
159
+ 'SM' => {id: 149, name: 'San Marino'},
160
+ 'ST' => {id: 150, name: 'São Tomé and Príncipe'},
161
+ 'SA' => {id: 151, name: 'Saudi Arabia'},
162
+ 'SN' => {id: 152, name: 'Senegal'},
163
+ 'RS' => {id: 153, name: 'Serbia'},
164
+ 'SC' => {id: 154, name: 'Seychelles'},
165
+ 'SL' => {id: 155, name: 'Sierra Leone'},
166
+ 'SG' => {id: 156, name: 'Singapore'},
167
+ 'SK' => {id: 157, name: 'Slovakia'},
168
+ 'SI' => {id: 158, name: 'Slovenia'},
169
+ 'SB' => {id: 159, name: 'Solomon Islands'},
170
+ 'SO' => {id: 160, name: 'Somalia'},
171
+ 'ZA' => {id: 161, name: 'South Africa'},
172
+ 'ES' => {id: 162, name: 'Spain'},
173
+ 'LK' => {id: 163, name: 'Sri Lanka'},
174
+ 'SD' => {id: 164, name: 'Sudan'},
175
+ 'SR' => {id: 165, name: 'Suriname'},
176
+ 'SZ' => {id: 166, name: 'Swaziland'},
177
+ 'SE' => {id: 167, name: 'Sweden'},
178
+ 'CH' => {id: 168, name: 'Switzerland'},
179
+ 'SY' => {id: 169, name: 'Syria'},
180
+ 'TW' => {id: 170, name: 'Taiwan'},
181
+ 'TJ' => {id: 171, name: 'Tajikistan'},
182
+ 'TZ' => {id: 172, name: 'Tanzania'},
183
+ 'TH' => {id: 173, name: 'Thailand'},
184
+ 'TG' => {id: 174, name: 'Togo'},
185
+ 'TO' => {id: 175, name: 'Tonga'},
186
+ 'TT' => {id: 176, name: 'Trinidad and Tobago'},
187
+ 'TU' => {id: 177, name: 'Tunisia'},
188
+ 'TR' => {id: 178, name: 'Turkey'},
189
+ 'TM' => {id: 179, name: 'Turkmenistan'},
190
+ 'TV' => {id: 180, name: 'Tuvalu'},
191
+ 'UG' => {id: 181, name: 'Uganda'},
192
+ 'UA' => {id: 182, name: 'Ukraine'},
193
+ 'AE' => {id: 183, name: 'United Arab Emirates'},
194
+ 'GB' => {id: 184, name: 'United Kingdom'},
195
+ 'US' => {id: 185, name: 'United States of America'},
196
+ 'UY' => {id: 186, name: 'Uruguay'},
197
+ 'UZ' => {id: 187, name: 'Uzbekistan'},
198
+ 'VU' => {id: 188, name: 'Vanuatu'},
199
+ 'VA' => {id: 189, name: 'Vatican City'},
200
+ 'VE' => {id: 190, name: 'Venezuela'},
201
+ 'VN' => {id: 191, name: 'Vietnam'},
202
+ 'EH' => {id: 192, name: 'Western Sahara'},
203
+ 'YE' => {id: 193, name: 'Yemen'},
204
+ # id 194 is 'Yugoslavia', which hasn't existed since 1992
205
+ 'ZR' => {id: 195, name: 'Zaire'},
206
+ 'ZM' => {id: 196, name: 'Zambia'},
207
+ 'ZW' => {id: 197, name: 'Zimbabwe'},
208
+ 'GL' => {id: 198, name: 'Greenland'},
209
+ 'VI' => {id: 199, name: 'Virgin Islands'},
210
+ 'IC' => {id: 201, name: 'Canary Islands'},
211
+ 'ME' => {id: 202, name: 'Montenegro'},
212
+ 'GI' => {id: 203, name: 'Gibraltar'},
213
+ 'AN' => {id: 204, name: 'Netherlands Antilles'},
214
+ 'HK' => {id: 205, name: 'Hong Kong'},
215
+ 'MO' => {id: 206, name: 'Macau'},
216
+ 'TP' => {id: 258, name: 'East Timor'},
217
+ 'KO' => {id: 259, name: 'Kosovo'}
218
+ }
219
+ end
220
+ end
@@ -1,3 +1,4 @@
1
+ ## frozen_string_literal: true
1
2
  #require 'hashie'
2
3
 
3
4
  module Emarsys
@@ -47,9 +48,17 @@ module Emarsys
47
48
  # Custom Parameterizer for Emarsys
48
49
  #
49
50
  # @param params [Hash] custom params hash
50
- # @return [String] key => value is returned as key=value
51
+ # @return [String] {key1 => value1, key2 => value2 is returned as ?key1=value1&key2=value2
51
52
  def parameterize_params(params)
52
- params.inject(""){|string, (k, v)| string << "#{k}=#{v}"; string << "&"; string}[0..-2]
53
+ '?' + params.map{|k, v| "#{url_encode(k)}=#{url_encode(v)}"}.join('&')
54
+ end
55
+
56
+
57
+ private
58
+
59
+ # Encode params like Emarsys does
60
+ def url_encode(param)
61
+ ERB::Util.url_encode(param)
53
62
  end
54
63
  end
55
64
 
@@ -75,4 +84,4 @@ module Emarsys
75
84
  # end
76
85
  # end
77
86
  end
78
- end
87
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  # Methods for the Condition API
@@ -17,4 +18,4 @@ module Emarsys
17
18
  end
18
19
 
19
20
  end
20
- end
21
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  # Methods for the Contact API
@@ -29,7 +30,7 @@ module Emarsys
29
30
  # Emarsys::Contact.emarsys_id('email', 'john.dow@example.com')
30
31
  # Emarsys::Contact.emarsys_id(1, 'John')
31
32
  def emarsys_id(key_id, key_value)
32
- get "contact/#{transform_key_id(key_id).to_s}=#{key_value.to_s}", {}
33
+ get "contact", {"#{transform_key_id(key_id).to_s}" => key_value}
33
34
  end
34
35
 
35
36
  # Update a contact. The given params are transformed to emarsys ids.
@@ -118,4 +119,4 @@ module Emarsys
118
119
 
119
120
  end
120
121
  end
121
- end
122
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  # Methods for the ContactList API
@@ -44,4 +45,4 @@ module Emarsys
44
45
 
45
46
  end
46
47
  end
47
- end
48
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  # Methods for the Email API
@@ -130,4 +131,4 @@ module Emarsys
130
131
  end
131
132
  end
132
133
  end
133
- end
134
+ end