emarsys 0.3.9 → 0.4.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
- SHA1:
3
- metadata.gz: e155b83198c03cb4fea3ae86224908fd3a95e31d
4
- data.tar.gz: 91c5aca80394f07dea3dd1bf43abb07398e795fe
2
+ SHA256:
3
+ metadata.gz: b91da527fa70b69756d7dca70b153ec103be4c52ed2fc189b6d8eb6d4036637a
4
+ data.tar.gz: 1ac969e7acf008b6cc07ae032d3c8ce42b8cdcf398b61bb3b51db0ff14c18533
5
5
  SHA512:
6
- metadata.gz: f6f4a47b51d23e43ed2c5ba4c03a9e62cc47913134425dac1c172d4251c27f23e88f7ae50d8d32aaf02bad8f3f4161bdb11e823ad172d0c0c194e1ac744f25af
7
- data.tar.gz: '082ae5439611b7b7d515664c6cd493cc18a7a8d17f108b4a0e2656600111f60a8164dcf36cc886ab4a7770a3ee48d3f586f89abbb37fa2c624b2869c156eff0a'
6
+ metadata.gz: b512d98dc2a1acbb56a1e783fb00a6e3d915d58a66ea1c773b9c92ea444b4724734e004273ee72758b16179b10b304656a07ad56bd5bd406606fe0d9726c02a0
7
+ data.tar.gz: 955e9a9626883406b3e029929475dbf04971f3411b5c2112626f7faacd0796c7a0216caf9f1548587d686d4d5e54b1a3c29870fc5a376f7f94ef65673c04eb42
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  sudo: false
3
- cache:
4
- bundler: true
3
+ before_install:
4
+ - gem install bundler
5
5
  rvm:
6
- - jruby-9.0.5.0
7
- - 2.2.2
6
+ - jruby-9.2.11.0
8
7
  - 2.3.1
8
+ - 2.5.8
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.4.0
4
+
5
+ * Add supported segment endpoints and remove the deprecated one ([#64]https://github.com/Absolventa/emarsys-rb/pull/64)
6
+
7
+ ## v0.3.13
8
+
9
+ * Add method to delete ContactList by ID ([#63](https://github.com/Absolventa/emarsys-rb/pull/63))
10
+ * Use correct endpoint in ContactList.remove_contacts ([#62](https://github.com/Absolventa/emarsys-rb/pull/62))
11
+ * Improved Contact.query method ([#61](https://github.com/Absolventa/emarsys-rb/pull/61))
12
+
13
+ ## v0.3.12
14
+
15
+ * Documentation update for Segments (change to README only)
16
+
17
+ ## v0.3.11
18
+
19
+ * Add support for Segments API ([#58](https://github.com/Absolventa/emarsys-rb/pull/58))
20
+
21
+ ## v0.3.10
22
+
23
+ * Fix 'Invalid Password' error ([#55](https://github.com/Absolventa/emarsys-rb/pull/55))
24
+
25
+ ## v0.3.9
26
+
27
+ * Add 'query' support to Contact data object ([#53](https://github.com/Absolventa/emarsys-rb/pull/53))
28
+
29
+ ## v0.3.5 - v0.3.8
30
+
31
+ * Documentation TODO
32
+
3
33
  ## v0.3.4
4
34
 
5
35
  * Allow accessing of error code ([#35](https://github.com/Absolventa/emarsys-rb/pull/35))
data/README.md CHANGED
@@ -144,8 +144,12 @@ Emarsys::Contact.create(key_id: 4980, key_value: 10, params: {1 => "Jane", 2 =>
144
144
  # Update a contact with key_field (one example with mapped identifier, one without)
145
145
  Emarsys::Contact.update(key_id: 'email', key_value: "jane.doe@example.com", params: {firstname: "John", lastname: "Doe"})
146
146
  Emarsys::Contact.update(key_id: 3, key_value: "jane.doe@example.com", params: {1 => "John", 2 => "Doe"})
147
+
148
+ # Query contact information
149
+ Emarsys::Contact.query('3', 'john.doe@example.com', 'uid')
147
150
  ```
148
151
 
152
+
149
153
  #### ContactList
150
154
 
151
155
  ```ruby
@@ -154,6 +158,12 @@ Emarsys::ContactList.collection
154
158
 
155
159
  # Create a contact list
156
160
  Emarsys::ContactList.create
161
+
162
+ # Delete a contact list
163
+ Emarsys::ContactList.delete(123)
164
+
165
+ # List all contacts in a contact list
166
+ Emarsys::ContactList.contacts(123)
157
167
  ```
158
168
 
159
169
  #### Emails
@@ -227,6 +237,16 @@ Emarsys::Language.collection
227
237
  Emarsys::Segment.collection
228
238
  ```
229
239
 
240
+ ```ruby
241
+ # Run a segment for multiple contacts
242
+ Emarsys::Segment.run(123)
243
+ ```
244
+
245
+ ```ruby
246
+ # Check the status of a segment run
247
+ Emarsys::Segment.status('foo123')
248
+ ```
249
+
230
250
  #### Source
231
251
 
232
252
  ```ruby
@@ -17,11 +17,13 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
+ spec.required_ruby_version = '>= 2.3'
20
21
 
21
22
  spec.add_dependency "rest-client"
22
23
 
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "bundler", "~> 2.1.4"
24
25
  spec.add_development_dependency "rake"
25
26
  spec.add_development_dependency "rspec", ">= 3.5.0"
26
- spec.add_development_dependency "webmock", "< 2.0"
27
+ spec.add_development_dependency "webmock", "~> 2.3.2"
28
+ spec.add_development_dependency "timecop"
27
29
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require "base64"
3
+ require 'erb'
3
4
  require 'json'
4
5
  require 'rest_client'
5
6
  require 'uri'
@@ -34,7 +34,7 @@ module Emarsys
34
34
  end
35
35
 
36
36
  def header_created
37
- Time.now.utc.iso8601
37
+ @header_created ||= Time.now.utc.iso8601
38
38
  end
39
39
 
40
40
  def calculated_digest
@@ -121,15 +121,27 @@ module Emarsys
121
121
 
122
122
  # Query contacts by custom
123
123
  #
124
- # @param key_id [Integer, String] The key used to query
125
- # @param key_value [String] Value of internal id field
126
124
  # @param return_value [Integer, String] Value of internal id field
125
+ # @param account [String] The account to use
126
+ # @param opts [Mixed] Further symbols to pass down to the request
127
127
  # @return [Hash] result data
128
128
  # @example
129
- # Emarsys::Contact.query('3', 'john.doe@example.com', 'uid')
130
- #
131
- def query(key_id:, key_value:, return_value: , account: nil)
132
- get account, "contact/query", { key_id => key_value, 'return' => return_value}
129
+ # # Get all emails from the emarsys account
130
+ # Emarsys::Contact.query(return_value: 'email')
131
+ # # Get the ID of the account with a specific email
132
+ # Emarsys::Contact.query(key_id: '_email', key_value: 'john.doe@example.com', return_value: 'email')
133
+ # Emarsys::Contact.query(key_id: 3, key_value: 'jane.doe@example.com', return_value: 'email')
134
+ def query(return_value:, account: nil, **opts)
135
+ if opts.key?(:key_id) && opts.key?(:key_value)
136
+ id, value = [opts.delete(:key_id), opts.delete(:key_value)]
137
+ opts["#{transform_key_id(id).to_s}"] = value
138
+ end
139
+
140
+ opts = opts.each_with_object({}) do |(key, val), memo|
141
+ memo[key.to_s] = val
142
+ end
143
+
144
+ get account, 'contact/query', opts.merge('return' => return_value)
133
145
  end
134
146
 
135
147
  # Exports the selected fields of contacts whoch registered in the specified time range
@@ -16,6 +16,14 @@ module Emarsys
16
16
  get account, 'contactlist', {}
17
17
  end
18
18
 
19
+ # List contacts in a contact list
20
+ # Reference: https://dev.emarsys.com/v2/contact-lists/list-contacts-in-a-contact-list
21
+ #
22
+ # @param id [Integer] The contact list id
23
+ def contacts(id, account: nil)
24
+ get account, "contactlist/#{id}/", {}
25
+ end
26
+
19
27
  # Create a new contact list
20
28
  #
21
29
  # @param params [Hash] Contact list information to create
@@ -29,6 +37,16 @@ module Emarsys
29
37
  post account, "contactlist", params
30
38
  end
31
39
 
40
+ # Delete a contact list
41
+ #
42
+ # @param id [Integer] Internal contact list id
43
+
44
+ # @example
45
+ # Emarsys::ContactList.delete(751283429)
46
+ def delete(id, account: nil)
47
+ post account, "contactlist/#{id}/deletelist", {}
48
+ end
49
+
32
50
  # Add a contacts to a specific contact list
33
51
  #
34
52
  # This cannot be an instance method, because the API does not allow to retrieve a single resource. How crappy is that?
@@ -40,7 +58,7 @@ module Emarsys
40
58
  #
41
59
  # This cannot be an instance method, because the API does not allow to retrieve a single resource. How crappy is that?
42
60
  def remove_contacts(id, key_id:, external_ids: [], account: nil)
43
- post account, "contactlist/#{id}/remove", {'key_id' => key_id, 'external_ids' => external_ids}
61
+ post account, "contactlist/#{id}/delete", {'key_id' => key_id, 'external_ids' => external_ids}
44
62
  end
45
63
 
46
64
  end
@@ -16,6 +16,23 @@ module Emarsys
16
16
  get account, 'filter', {}
17
17
  end
18
18
 
19
+ # Run a Segment for Multiple Contacts
20
+ # Reference: https://dev.emarsys.com/v2/segments/run-a-contact-segment-batch
21
+ #
22
+ # @param id [Integer] the id of the segment
23
+ def run(id, account: nil)
24
+ path = "filter/#{id}/runs"
25
+ post account, path, {}
26
+ end
27
+
28
+ # Poll the Status of a Segment Run for Multiple Contacts
29
+ # Reference: https://dev.emarsys.com/v2/segments/poll-the-status-of-a-segment-run-for-multiple-contacts
30
+ #
31
+ # @param run_id [String] the id of the segment run, @see #run
32
+ def status(run_id, account: nil)
33
+ path = "filter/runs/#{run_id}"
34
+ get account, path, {}
35
+ end
19
36
  end
20
37
  end
21
38
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Emarsys
3
- VERSION = "0.3.9"
3
+ VERSION = "0.4.0"
4
4
  end
@@ -83,6 +83,15 @@ describe Emarsys::Client do
83
83
  it 'uses current timestamp format' do
84
84
  expect(Emarsys::Client.new.header_created).to eq(Time.now.utc.iso8601)
85
85
  end
86
+
87
+ it 'only generates time once' do
88
+ client = Emarsys::Client.new
89
+ header_created = Timecop.travel(Time.now - 10) do
90
+ client.header_created
91
+ end
92
+
93
+ expect(client.header_created).to eq(header_created)
94
+ end
86
95
  end
87
96
 
88
97
  describe '#calculated_digest' do
@@ -8,4 +8,11 @@ describe Emarsys::ContactList do
8
8
  ).to have_been_requested.once
9
9
  end
10
10
  end
11
+ describe ".contacts" do
12
+ it "requests all contacts in the given contact list" do
13
+ expect(
14
+ stub_get("contactlist/123/") { Emarsys::ContactList.contacts(123) }
15
+ ).to have_been_requested.once
16
+ end
17
+ end
11
18
  end
@@ -102,6 +102,18 @@ describe Emarsys::Contact do
102
102
  Emarsys::Contact.query(key_id: 3, key_value: 'jane.doe@example.com', return_value: 'email')
103
103
  expect(stub).to have_been_requested.once
104
104
  end
105
+
106
+ it "transforms the key_id correctly to its id" do
107
+ stub = stub_request(:get, "https://api.emarsys.net/api/v2/contact/query/?3=jane.doe@example.com&return=email").to_return(standard_return_body)
108
+ Emarsys::Contact.query(key_id: '_email', key_value: 'jane.doe@example.com', return_value: 'email')
109
+ expect(stub).to have_been_requested.once
110
+ end
111
+
112
+ it "allows to get all contacts" do
113
+ stub = stub_request(:get, "https://api.emarsys.net/api/v2/contact/query/?return=email").to_return(standard_return_body)
114
+ Emarsys::Contact.query(return_value: 'email')
115
+ expect(stub).to have_been_requested.once
116
+ end
105
117
  end
106
118
 
107
119
  describe ".export_registrations" do
@@ -7,5 +7,19 @@ describe Emarsys::Segment do
7
7
  stub_get("filter") { Emarsys::Segment.collection }
8
8
  ).to have_been_requested.once
9
9
  end
10
+ describe ".run" do
11
+ it "requests a run for a segment for multiple contacts" do
12
+ expect(
13
+ stub_post("filter/123/runs") { Emarsys::Segment.run(123) }
14
+ ).to have_been_requested.once
15
+ end
16
+ end
17
+ describe ".status" do
18
+ it "requests the status of the given segment run" do
19
+ expect(
20
+ stub_get("filter/runs/foo-333-bar") { Emarsys::Segment.status('foo-333-bar') }
21
+ ).to have_been_requested.once
22
+ end
23
+ end
10
24
  end
11
25
  end
@@ -59,7 +59,8 @@ describe Emarsys::Response do
59
59
  end
60
60
 
61
61
  describe 'error response' do
62
- let(:response_string) { "{\"replyCode\":1,\"replyText\":\"Something\",\"data\":1}" }
62
+ let(:reply_code) { 1 }
63
+ let(:response_string) { "{\"replyCode\":#{reply_code},\"replyText\":\"Something\",\"data\":1}" }
63
64
  let(:fake_response) { FakeResponse.new(response_string).extend(FakeResponse::JSON) }
64
65
  let(:response) { Emarsys::Response.new(fake_response) }
65
66
 
@@ -1,6 +1,7 @@
1
1
  require 'emarsys'
2
2
  require 'rspec'
3
3
  require 'webmock/rspec'
4
+ require 'timecop'
4
5
 
5
6
  WebMock.disable_net_connect!
6
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emarsys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schoppmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-20 00:00:00.000000000 Z
11
+ date: 2020-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.3'
33
+ version: 2.1.4
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.3'
40
+ version: 2.1.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +70,30 @@ dependencies:
70
70
  name: webmock
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "<"
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.3.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.3.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: timecop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: '2.0'
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "<"
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: '2.0'
96
+ version: '0'
83
97
  description: A Ruby library for interacting with the Emarsys API.
84
98
  email:
85
99
  - daniel.schoppmann@absolventa.de
@@ -163,15 +177,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - ">="
165
179
  - !ruby/object:Gem::Version
166
- version: '0'
180
+ version: '2.3'
167
181
  required_rubygems_version: !ruby/object:Gem::Requirement
168
182
  requirements:
169
183
  - - ">="
170
184
  - !ruby/object:Gem::Version
171
185
  version: '0'
172
186
  requirements: []
173
- rubyforge_project:
174
- rubygems_version: 2.5.2
187
+ rubygems_version: 3.0.3
175
188
  signing_key:
176
189
  specification_version: 4
177
190
  summary: Easy to use ruby library for Emarsys Marketing Suite.