emarsys 0.3.8 → 0.3.9
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.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/emarsys/data_objects/contact.rb +14 -1
- data/lib/emarsys/data_objects/event.rb +6 -4
- data/lib/emarsys/field_mapping.rb +19 -0
- data/lib/emarsys/params_converter.rb +3 -3
- data/lib/emarsys/version.rb +1 -1
- data/spec/emarsys/data_objects/contact_spec.rb +8 -0
- data/spec/emarsys/data_objects/event_spec.rb +6 -0
- data/spec/emarsys/field_mapping_spec.rb +61 -1
- data/spec/emarsys/params_converter_spec.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e155b83198c03cb4fea3ae86224908fd3a95e31d
|
4
|
+
data.tar.gz: 91c5aca80394f07dea3dd1bf43abb07398e795fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6f4a47b51d23e43ed2c5ba4c03a9e62cc47913134425dac1c172d4251c27f23e88f7ae50d8d32aaf02bad8f3f4161bdb11e823ad172d0c0c194e1ac744f25af
|
7
|
+
data.tar.gz: '082ae5439611b7b7d515664c6cd493cc18a7a8d17f108b4a0e2656600111f60a8164dcf36cc886ab4a7770a3ee48d3f586f89abbb37fa2c624b2869c156eff0a'
|
data/README.md
CHANGED
@@ -70,14 +70,14 @@ which that can be overwritten. It will be picked up automatically. E.g.:
|
|
70
70
|
|
71
71
|
```ruby
|
72
72
|
# Complete overwrite
|
73
|
-
Emarsys::FieldMapping
|
73
|
+
Emarsys::FieldMapping.set_attributes([
|
74
74
|
{:id => 0, :identifier => 'interests', :name => 'Interests'},
|
75
75
|
{:id => 1, :identifier => 'firstname', :name => 'First Name'},
|
76
76
|
{:id => 2, :identifier => 'lastname', :name => 'Last Name'},
|
77
|
-
]
|
77
|
+
])
|
78
78
|
|
79
79
|
# Add to the Mapping-Constant
|
80
|
-
Emarsys::FieldMapping
|
80
|
+
Emarsys::FieldMapping.add_attributes({:id => 100, :identifier => 'user_id', :name => "User-ID"})
|
81
81
|
```
|
82
82
|
|
83
83
|
All Emarsys predefined system fields are prefixed with an underscore, e.g. '_firstname' or '_revenue' in order to not
|
@@ -119,6 +119,19 @@ module Emarsys
|
|
119
119
|
post account, "contact/getdata", {'keyId' => key_id, 'keyValues' => key_values, 'fields' => fields}
|
120
120
|
end
|
121
121
|
|
122
|
+
# Query contacts by custom
|
123
|
+
#
|
124
|
+
# @param key_id [Integer, String] The key used to query
|
125
|
+
# @param key_value [String] Value of internal id field
|
126
|
+
# @param return_value [Integer, String] Value of internal id field
|
127
|
+
# @return [Hash] result data
|
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}
|
133
|
+
end
|
134
|
+
|
122
135
|
# Exports the selected fields of contacts whoch registered in the specified time range
|
123
136
|
#
|
124
137
|
# @param params [hash] hash of parameters according to emarsys API
|
@@ -135,7 +148,7 @@ module Emarsys
|
|
135
148
|
|
136
149
|
# @private
|
137
150
|
def transform_key_id(key_id)
|
138
|
-
matching_attributes = Emarsys::FieldMapping
|
151
|
+
matching_attributes = Emarsys::FieldMapping.attributes.find{|elem| elem[:identifier] == key_id.to_s}
|
139
152
|
matching_attributes.nil? ? key_id : matching_attributes[:id]
|
140
153
|
end
|
141
154
|
|
@@ -23,14 +23,16 @@ module Emarsys
|
|
23
23
|
# @param key_id [Integer, String] The identifer of the key field (e.g. 3 for 'email')
|
24
24
|
# @param external_id [String] The id of the given filed specified with key_id (e.g. 'test@example.com')
|
25
25
|
# @option data [Hash] data hash for transactional mails
|
26
|
+
# @option attachment [Array] array containing an attachment for transactional mails
|
26
27
|
# @return [Hash] Result data
|
27
28
|
# @example
|
28
29
|
# Emarsys::Event.trigger(2, 3, 'test@example.com')
|
29
30
|
# Emarsys::Event.trigger(2, 'user_id', 57687, {:global => {:name => "Special Name"}})
|
30
|
-
def trigger(id, key_id:, external_id:, data: {}, account: nil)
|
31
|
+
def trigger(id, key_id:, external_id:, data: {}, attachment: [], account: nil)
|
31
32
|
transformed_key_id = transform_key_id(key_id)
|
32
|
-
params = {:
|
33
|
-
params.merge!(:
|
33
|
+
params = { key_id: transformed_key_id, external_id: external_id }
|
34
|
+
params.merge!(data: data) if not data.empty?
|
35
|
+
params.merge!(attachment: attachment) if not attachment.empty?
|
34
36
|
post account, "event/#{id}/trigger", params
|
35
37
|
end
|
36
38
|
|
@@ -52,7 +54,7 @@ module Emarsys
|
|
52
54
|
|
53
55
|
# @private
|
54
56
|
def transform_key_id(key_id)
|
55
|
-
matching_attributes = Emarsys::FieldMapping
|
57
|
+
matching_attributes = Emarsys::FieldMapping.attributes.find{|elem| elem[:identifier] == key_id.to_s}
|
56
58
|
matching_attributes.nil? ? key_id : matching_attributes[:id]
|
57
59
|
end
|
58
60
|
end
|
@@ -53,4 +53,23 @@ module Emarsys::FieldMapping
|
|
53
53
|
{:id => 48, :identifier => '_date_of_first_registration', :name => 'Date of first registration'}
|
54
54
|
]
|
55
55
|
|
56
|
+
def self.attributes
|
57
|
+
return @custom_attributes if excluded_default_attributes?
|
58
|
+
return ATTRIBUTES.dup.concat(@custom_attributes) if @custom_attributes
|
59
|
+
ATTRIBUTES
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.set_attributes(attrs)
|
63
|
+
@exclude_default_attributes = true
|
64
|
+
@custom_attributes = [attrs].flatten
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.add_attributes(attrs)
|
68
|
+
@custom_attributes.concat([attrs].flatten)
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.excluded_default_attributes?
|
72
|
+
@exclude_default_attributes == true
|
73
|
+
end
|
74
|
+
|
56
75
|
end
|
@@ -15,7 +15,7 @@ module Emarsys
|
|
15
15
|
def convert_to_identifiers
|
16
16
|
new_hash = {}
|
17
17
|
params.each do |key, value|
|
18
|
-
matching_attributes = Emarsys::FieldMapping
|
18
|
+
matching_attributes = Emarsys::FieldMapping.attributes.find{|elem| elem[:id] == key.to_i && key.to_i != 0}
|
19
19
|
new_hash.merge!({ (matching_attributes.nil? ? key : matching_attributes[:identifier]) => value })
|
20
20
|
end
|
21
21
|
new_hash
|
@@ -26,7 +26,7 @@ module Emarsys
|
|
26
26
|
def convert_hash_to_ids
|
27
27
|
new_hash = {}
|
28
28
|
params.each do |key, value|
|
29
|
-
matching_attributes = Emarsys::FieldMapping
|
29
|
+
matching_attributes = Emarsys::FieldMapping.attributes.find{|elem| elem[:identifier] == key.to_s}
|
30
30
|
new_hash.merge!({ (matching_attributes.nil? ? key : matching_attributes[:id]) => value })
|
31
31
|
end
|
32
32
|
new_hash
|
@@ -35,7 +35,7 @@ module Emarsys
|
|
35
35
|
def convert_array_to_ids
|
36
36
|
new_array = []
|
37
37
|
params.each do |key|
|
38
|
-
matching_attributes = Emarsys::FieldMapping
|
38
|
+
matching_attributes = Emarsys::FieldMapping.attributes.find{|elem| elem[:identifier] == key.to_s}
|
39
39
|
new_array << (matching_attributes.nil? ? key : matching_attributes[:id])
|
40
40
|
end
|
41
41
|
new_array
|
data/lib/emarsys/version.rb
CHANGED
@@ -96,6 +96,14 @@ describe Emarsys::Contact do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
+
describe ".query" do
|
100
|
+
it "queries contact data based on search params" do
|
101
|
+
stub = stub_request(:get, "https://api.emarsys.net/api/v2/contact/query/?3=jane.doe@example.com&return=email").to_return(standard_return_body)
|
102
|
+
Emarsys::Contact.query(key_id: 3, key_value: 'jane.doe@example.com', return_value: 'email')
|
103
|
+
expect(stub).to have_been_requested.once
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
99
107
|
describe ".export_registrations" do
|
100
108
|
it "requests contact data export based on parameters" do
|
101
109
|
stub_params = {distribution_method: 'local', time_range: ["2013-01-01","2013-12-31"], contact_fields: [1,2,3]}
|
@@ -21,6 +21,12 @@ describe Emarsys::Event do
|
|
21
21
|
Emarsys::Event.trigger(123, key_id: 3, external_id: 'jane.doe@example.com', data: {'global' => {'my_placeholder' => 'Something'}})
|
22
22
|
expect(stub).to have_been_requested.once
|
23
23
|
end
|
24
|
+
|
25
|
+
it "requests event trigger with an attachment" do
|
26
|
+
stub = stub_request(:post, "https://api.emarsys.net/api/v2/event/123/trigger").with(:body => {'key_id' => 3, 'external_id' => "jane.doe@example.com", attachment: [ { filename: 'something.pdf', data: 'Something' } ]}.to_json).to_return(standard_return_body)
|
27
|
+
Emarsys::Event.trigger(123, key_id: 3, external_id: 'jane.doe@example.com', attachment: [ { filename: 'something.pdf', data: 'Something' } ])
|
28
|
+
expect(stub).to have_been_requested.once
|
29
|
+
end
|
24
30
|
end
|
25
31
|
|
26
32
|
describe ".trigger_multiple" do
|
@@ -8,7 +8,67 @@ describe Emarsys::FieldMapping do
|
|
8
8
|
|
9
9
|
it "defines constant ATTRBUTES as an array if hashes" do
|
10
10
|
expect(Emarsys::FieldMapping::ATTRIBUTES).to be_a(Array)
|
11
|
-
Emarsys::FieldMapping::ATTRIBUTES
|
11
|
+
expect(Emarsys::FieldMapping::ATTRIBUTES).to all(be_a(Hash))
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.attributes' do
|
15
|
+
describe 'backward-compatibility' do
|
16
|
+
it 'defines an array of hashes' do
|
17
|
+
expect(Emarsys::FieldMapping.attributes).to be_a(Array)
|
18
|
+
expect(Emarsys::FieldMapping.attributes).to all(be_a(Hash))
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns the content of ATTRIBUTES by default' do
|
22
|
+
attributes_stub = double('ATTRIBUTES')
|
23
|
+
stub_const('Emarsys::FieldMapping::ATTRIBUTES', attributes_stub)
|
24
|
+
|
25
|
+
expect(Emarsys::FieldMapping.attributes).to eq(attributes_stub)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '.set_attributes' do
|
31
|
+
it 'redefines attributes' do
|
32
|
+
attributes = [
|
33
|
+
{:id => 101, :identifier => 'foo', :name => 'Foo'},
|
34
|
+
{:id => 102, :identifier => 'bar', :name => 'Bar'}
|
35
|
+
]
|
36
|
+
|
37
|
+
Emarsys::FieldMapping.set_attributes(attributes)
|
38
|
+
expect(Emarsys::FieldMapping.attributes).to match_array(attributes)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'turns off use of default-predefined ATTRIBUTES' do
|
42
|
+
attributes_stub = double('ATTRIBUTES')
|
43
|
+
allow(attributes_stub).to receive(:<<).and_return(attributes_stub)
|
44
|
+
|
45
|
+
stub_const('Emarsys::FieldMapping::ATTRIBUTES', attributes_stub)
|
46
|
+
|
47
|
+
mapping_to_be_added = {
|
48
|
+
id: 2000, identifier: 'foo', name: 'Foo'
|
49
|
+
}
|
50
|
+
|
51
|
+
attributes = [
|
52
|
+
{:id => 101, :identifier => 'foo', :name => 'Foo'},
|
53
|
+
{:id => 102, :identifier => 'bar', :name => 'Bar'}
|
54
|
+
]
|
55
|
+
|
56
|
+
Emarsys::FieldMapping.set_attributes(attributes)
|
57
|
+
Emarsys::FieldMapping::ATTRIBUTES << mapping_to_be_added
|
58
|
+
|
59
|
+
expect(Emarsys::FieldMapping.attributes).to match_array(attributes)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '.add_attributes' do
|
64
|
+
it "merges attributes" do
|
65
|
+
attributes = [
|
66
|
+
{:id => 101, :identifier => 'foo', :name => 'Foo'},
|
67
|
+
{:id => 102, :identifier => 'bar', :name => 'Bar'}
|
68
|
+
]
|
69
|
+
Emarsys::FieldMapping.add_attributes(attributes)
|
70
|
+
expect(Emarsys::FieldMapping.attributes).to include(attributes[0], attributes[1])
|
71
|
+
end
|
12
72
|
end
|
13
73
|
|
14
74
|
end
|
@@ -9,7 +9,10 @@ describe Emarsys::ParamsConverter do
|
|
9
9
|
{:id => 1, :identifier => 'first_name', :name => 'First Name'},
|
10
10
|
{:id => 2, :identifier => 'last_name', :name => 'Last Name'},
|
11
11
|
]
|
12
|
-
|
12
|
+
|
13
|
+
allow(Emarsys::FieldMapping).to receive(:attributes).and_return(
|
14
|
+
attributes
|
15
|
+
)
|
13
16
|
end
|
14
17
|
|
15
18
|
describe 'with attributes' do
|
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.
|
4
|
+
version: 0.3.9
|
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-
|
11
|
+
date: 2018-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|