fuelsdk 0.0.4 → 0.0.5
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.
- data/lib/fuelsdk.rb +2 -224
- data/lib/fuelsdk/client.rb +21 -37
- data/lib/fuelsdk/objects.rb +252 -52
- data/lib/fuelsdk/soap.rb +3 -12
- data/lib/fuelsdk/utils.rb +11 -0
- data/lib/fuelsdk/version.rb +1 -1
- data/samples/sample-AddSubscriberToList.rb +6 -2
- data/samples/sample-CreateDataExtensions.rb +5 -2
- data/samples/sample-dataextension.rb +42 -25
- data/spec/objects_helper_spec.rb +17 -10
- data/spec/objects_spec.rb +371 -0
- metadata +3 -2
data/lib/fuelsdk/soap.rb
CHANGED
@@ -54,7 +54,7 @@ module FuelSDK
|
|
54
54
|
definition = raw.body[raw.body.keys.first][:object_definition]
|
55
55
|
_props = definition[:properties]
|
56
56
|
_props.each do |p|
|
57
|
-
@retrievable << p[:name] if p[:is_retrievable]
|
57
|
+
@retrievable << p[:name] if p[:is_retrievable] and (p[:name] != 'DataRetentionPeriod')
|
58
58
|
@updatable << p[:name] if p[:is_updatable]
|
59
59
|
@required << p[:name] if p[:is_required]
|
60
60
|
@properties << p[:name]
|
@@ -125,7 +125,7 @@ module FuelSDK
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def soap_get object_type, properties=nil, filter=nil
|
128
|
-
if properties.nil?
|
128
|
+
if properties.nil? or properties.empty?
|
129
129
|
rsp = soap_describe object_type
|
130
130
|
if rsp.success?
|
131
131
|
properties = rsp.retrievable
|
@@ -169,15 +169,6 @@ module FuelSDK
|
|
169
169
|
soap_cud :delete, object_type, properties
|
170
170
|
end
|
171
171
|
|
172
|
-
def format_attributes attributes
|
173
|
-
attrs = []
|
174
|
-
attributes.each do |name, value|
|
175
|
-
attrs.push 'Name' => name, 'Value' => value
|
176
|
-
end
|
177
|
-
|
178
|
-
attrs
|
179
|
-
end
|
180
|
-
|
181
172
|
private
|
182
173
|
|
183
174
|
def soap_cud action, object_type, properties
|
@@ -191,7 +182,7 @@ module FuelSDK
|
|
191
182
|
p.each do |k, v|
|
192
183
|
if type_attrs.include? k
|
193
184
|
p.delete k
|
194
|
-
attrs =
|
185
|
+
attrs = FuelSDK.format_name_value_pairs k => v
|
195
186
|
formated_attrs.concat attrs
|
196
187
|
end
|
197
188
|
end
|
data/lib/fuelsdk/version.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'fuelsdk'
|
2
|
+
require_relative 'sample_helper'
|
2
3
|
|
3
4
|
begin
|
4
|
-
stubObj = ET_Client.new
|
5
|
+
stubObj = ET_Client.new auth
|
5
6
|
|
6
7
|
NewListName = "RubySDKList"
|
7
8
|
|
@@ -19,6 +20,7 @@ begin
|
|
19
20
|
p 'Message: ' + postResponse.message.to_s
|
20
21
|
p 'Result Count: ' + postResponse.results.length.to_s
|
21
22
|
p 'Results: ' + postResponse.results.inspect
|
23
|
+
raise 'Failure creating list' unless postResponse.success?
|
22
24
|
|
23
25
|
if postResponse.status then
|
24
26
|
|
@@ -31,6 +33,7 @@ begin
|
|
31
33
|
p 'Message: ' + AddSubResponse.message.to_s
|
32
34
|
p 'Result Count: ' + AddSubResponse.results.length.to_s
|
33
35
|
p 'Results: ' + AddSubResponse.results.inspect
|
36
|
+
raise 'Failure adding user to list' unless AddSubResponse.success?
|
34
37
|
|
35
38
|
# Delete List
|
36
39
|
p '>>> Delete List'
|
@@ -43,6 +46,7 @@ begin
|
|
43
46
|
p 'Message: ' + deleteResponse.message.to_s
|
44
47
|
p 'Results Length: ' + deleteResponse.results.length.to_s
|
45
48
|
p 'Results: ' + deleteResponse.results.to_s
|
49
|
+
raise 'Failure deleting list' unless deleteResponse.success?
|
46
50
|
end
|
47
51
|
|
48
52
|
rescue => e
|
@@ -1,7 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'fuelsdk'
|
2
|
+
require_relative 'sample_helper'
|
2
3
|
|
3
4
|
begin
|
4
|
-
myclient = ET_Client.new
|
5
|
+
myclient = ET_Client.new auth
|
5
6
|
|
6
7
|
## Example using CreateDataExtensions() method
|
7
8
|
|
@@ -20,6 +21,8 @@ begin
|
|
20
21
|
p 'Message: ' + createDEResponse.message.to_s
|
21
22
|
p 'Results Length: ' + createDEResponse.results.length.to_s
|
22
23
|
p 'Results: ' + createDEResponse.results.to_s
|
24
|
+
raise 'Failure creating data extensions' unless createDEResponse.success?
|
25
|
+
raise 'Failure creating data extensions' unless createDEResponse.results.count == 2
|
23
26
|
|
24
27
|
# Cleaning up the newly created DEs
|
25
28
|
# Delete deOne
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'fuelsdk'
|
2
|
+
require_relative 'sample_helper'
|
3
|
+
require 'pry'
|
3
4
|
|
4
5
|
begin
|
5
|
-
stubObj = ET_Client.new
|
6
|
-
|
6
|
+
stubObj = ET_Client.new auth
|
7
7
|
|
8
8
|
# Get all of the DataExtensions in an Account
|
9
9
|
p '>>> Get all of the DataExtensions in an Account'
|
@@ -14,29 +14,31 @@ begin
|
|
14
14
|
p 'Retrieve Status: ' + getResponse.status.to_s
|
15
15
|
p 'Code: ' + getResponse.code.to_s
|
16
16
|
p 'Message: ' + getResponse.message.to_s
|
17
|
-
p 'MoreResults: ' + getResponse.
|
17
|
+
p 'MoreResults: ' + getResponse.more?.to_s
|
18
18
|
p 'RequestID: ' + getResponse.request_id.to_s
|
19
19
|
p 'Results Length: ' + getResponse.results.length.to_s
|
20
20
|
#p 'Results: ' + getResponse.results.to_s
|
21
|
+
raise 'Failure retrieving data extensions' unless getResponse.success?
|
21
22
|
|
22
23
|
# Specify a name for the data extension that will be used for testing
|
23
24
|
# Note: Name and CustomerKey will be the same value
|
24
25
|
# WARNING: Data Extension will be deleted so don't use the name of a
|
25
26
|
# production data extension
|
26
|
-
NameOfDE = "ThisWillBeDeleted-
|
27
|
-
|
27
|
+
NameOfDE = "ThisWillBeDeleted-Testz"
|
28
28
|
|
29
29
|
# Create Data Extension
|
30
30
|
p '>>> Create Data Extension'
|
31
31
|
de2 = ET_DataExtension.new
|
32
32
|
de2.authStub = stubObj
|
33
33
|
de2.props = {"Name" => NameOfDE,"CustomerKey" => NameOfDE}
|
34
|
-
de2.columns = [{"Name" => "Name", "FieldType" => "Text", "IsPrimaryKey" => "true", "MaxLength" => "100", "IsRequired" => "true"},
|
34
|
+
de2.columns = [{"Name" => "Name", "FieldType" => "Text", "IsPrimaryKey" => "true", "MaxLength" => "100", "IsRequired" => "true"},
|
35
|
+
{"Name" => "OtherField", "FieldType" => "Text"}]
|
35
36
|
postResponse = de2.post
|
36
37
|
p 'Post Status: ' + postResponse.status.to_s
|
37
38
|
p 'Code: ' + postResponse.code.to_s
|
38
39
|
p 'Message: ' + postResponse.message.to_s
|
39
40
|
p 'Results: ' + postResponse.results.inspect
|
41
|
+
raise 'Failure creating data extension' unless postResponse.success?
|
40
42
|
|
41
43
|
# Update DE to add new field
|
42
44
|
p '>>> Update DE to add new field'
|
@@ -49,8 +51,7 @@ begin
|
|
49
51
|
p 'Code: ' + patchResponse.code.to_s
|
50
52
|
p 'Message: ' + patchResponse.message.to_s
|
51
53
|
p 'Results: ' + patchResponse.results.inspect
|
52
|
-
|
53
|
-
|
54
|
+
raise 'Failure updating data extension' unless patchResponse.success?
|
54
55
|
|
55
56
|
# Retrieve all columns for data extension
|
56
57
|
p '>>> Retrieve all columns for data extension '
|
@@ -62,11 +63,12 @@ begin
|
|
62
63
|
p 'Retrieve Status: ' + getResponse.status.to_s
|
63
64
|
p 'Code: ' + getResponse.code.to_s
|
64
65
|
p 'Message: ' + getResponse.message.to_s
|
65
|
-
p 'MoreResults: ' + getResponse.
|
66
|
+
p 'MoreResults: ' + getResponse.more?.to_s
|
66
67
|
p 'RequestID: ' + getResponse.request_id.to_s
|
67
68
|
p 'Results Length: ' + getResponse.results.length.to_s
|
68
69
|
p 'Results: ' + getResponse.results.to_s
|
69
|
-
|
70
|
+
raise 'Failure retrieving data extension columns' unless getResponse.success?
|
71
|
+
raise 'Failure retrieving correct number of data extension columns' unless getResponse.results.count == 3
|
70
72
|
|
71
73
|
# Add a row to a data extension (using CustomerKey)
|
72
74
|
p '>>> Add a row to a data extension'
|
@@ -79,6 +81,7 @@ begin
|
|
79
81
|
p 'Code: ' + postResponse.code.to_s
|
80
82
|
p 'Message: ' + postResponse.message.to_s
|
81
83
|
p 'Results: ' + postResponse.results.inspect
|
84
|
+
raise 'Failure creating data extension row' unless postResponse.success?
|
82
85
|
|
83
86
|
# Add a row to a data extension (Using Name)
|
84
87
|
p '>>> Add a row to a data extension'
|
@@ -91,6 +94,7 @@ begin
|
|
91
94
|
p 'Code: ' + postResponse.code.to_s
|
92
95
|
p 'Message: ' + postResponse.message.to_s
|
93
96
|
p 'Results: ' + postResponse.results.inspect
|
97
|
+
raise 'Failure creating data extension row' unless postResponse.success?
|
94
98
|
|
95
99
|
# Retrieve all rows
|
96
100
|
p '>>> Retrieve all rows'
|
@@ -102,10 +106,12 @@ begin
|
|
102
106
|
p 'Retrieve Status: ' + getResponse.status.to_s
|
103
107
|
p 'Code: ' + getResponse.code.to_s
|
104
108
|
p 'Message: ' + getResponse.message.to_s
|
105
|
-
p 'MoreResults: ' + getResponse.
|
109
|
+
p 'MoreResults: ' + getResponse.more?.to_s
|
106
110
|
p 'RequestID: ' + getResponse.request_id.to_s
|
107
111
|
p 'Results Length: ' + getResponse.results.length.to_s
|
108
112
|
p 'Results: ' + getResponse.results.to_s
|
113
|
+
raise 'Failure retrieving data extension rows' unless getResponse.success?
|
114
|
+
raise 'Failure retrieving correct number of data extension rows' unless getResponse.results.count == 2
|
109
115
|
|
110
116
|
# Update a row in a data extension
|
111
117
|
p '>>> Update a row in a data extension'
|
@@ -113,11 +119,12 @@ begin
|
|
113
119
|
de4.authStub = stubObj
|
114
120
|
de4.CustomerKey = NameOfDE
|
115
121
|
de4.props = {"Name" => "MAC3", "OtherField" => "UPDATED!"}
|
116
|
-
|
117
|
-
p 'Patch Status: ' +
|
118
|
-
p 'Code: ' +
|
119
|
-
p 'Message: ' +
|
120
|
-
p 'Results: ' +
|
122
|
+
patchResponse = de4.patch
|
123
|
+
p 'Patch Status: ' + patchResponse.status.to_s
|
124
|
+
p 'Code: ' + patchResponse.code.to_s
|
125
|
+
p 'Message: ' + patchResponse.message.to_s
|
126
|
+
p 'Results: ' + patchResponse.results.inspect
|
127
|
+
raise 'Failure updating data extension row' unless patchResponse.success?
|
121
128
|
|
122
129
|
# Retrieve only updated row
|
123
130
|
p '>>> Retrieve only updated row'
|
@@ -130,10 +137,11 @@ begin
|
|
130
137
|
p 'Retrieve Status: ' + getResponse.status.to_s
|
131
138
|
p 'Code: ' + getResponse.code.to_s
|
132
139
|
p 'Message: ' + getResponse.message.to_s
|
133
|
-
p 'MoreResults: ' + getResponse.
|
140
|
+
p 'MoreResults: ' + getResponse.more?.to_s
|
134
141
|
p 'RequestID: ' + getResponse.request_id.to_s
|
135
142
|
p 'Results Length: ' + getResponse.results.length.to_s
|
136
143
|
p 'Results: ' + getResponse.results.to_s
|
144
|
+
raise 'Failure retrieving data extension rows' unless getResponse.success?
|
137
145
|
|
138
146
|
# Delete a row from a data extension
|
139
147
|
p '>>> Delete a row from a data extension'
|
@@ -146,6 +154,7 @@ begin
|
|
146
154
|
p 'Code: ' + deleteResponse.code.to_s
|
147
155
|
p 'Message: ' + deleteResponse.message.to_s
|
148
156
|
p 'Results: ' + deleteResponse.results.inspect
|
157
|
+
raise 'Failure deleting data extension row' unless deleteResponse.success?
|
149
158
|
|
150
159
|
# Delete a Data Extension
|
151
160
|
p '>>> Delete a Data Extension'
|
@@ -157,10 +166,11 @@ begin
|
|
157
166
|
p 'Code: ' + delResponse.code.to_s
|
158
167
|
p 'Message: ' + delResponse.message.to_s
|
159
168
|
p 'Results: ' + delResponse.results.inspect
|
169
|
+
raise 'Failure deleting data extension' unless deleteResponse.success?
|
160
170
|
|
161
171
|
=begin
|
162
|
-
# Retrieve lots of rows with
|
163
|
-
p '>>> Retrieve lots of rows with
|
172
|
+
# Retrieve lots of rows with more?
|
173
|
+
p '>>> Retrieve lots of rows with more?'
|
164
174
|
row = ET_DataExtension::Row.new()
|
165
175
|
row.authStub = stubObj
|
166
176
|
row.Name = "zipstolong"
|
@@ -169,18 +179,19 @@ begin
|
|
169
179
|
p 'Retrieve Status: ' + getResponse.status.to_s
|
170
180
|
p 'Code: ' + getResponse.code.to_s
|
171
181
|
p 'Message: ' + getResponse.message.to_s
|
172
|
-
p 'MoreResults: ' + getResponse.
|
182
|
+
p 'MoreResults: ' + getResponse.more?.to_s
|
173
183
|
p 'RequestID: ' + getResponse.request_id.to_s
|
174
184
|
p 'Results Length: ' + getResponse.results.length.to_s
|
175
185
|
#p 'Results: ' + getResponse.results.to_s
|
186
|
+
raise 'Failure retrieving data extension rows' unless getResponse.success?
|
176
187
|
|
177
|
-
while getResponse.
|
178
|
-
p '>>> Continue Retrieve lots of rows with
|
188
|
+
while getResponse.more? do
|
189
|
+
p '>>> Continue Retrieve lots of rows with more?'
|
179
190
|
getResponse = row.getMoreResults
|
180
191
|
p 'Retrieve Status: ' + getResponse.status.to_s
|
181
192
|
p 'Code: ' + getResponse.code.to_s
|
182
193
|
p 'Message: ' + getResponse.message.to_s
|
183
|
-
p 'MoreResults: ' + getResponse.
|
194
|
+
p 'MoreResults: ' + getResponse.more?.to_s
|
184
195
|
p 'RequestID: ' + getResponse.request_id.to_s
|
185
196
|
p 'Results Length: ' + getResponse.results.length.to_s
|
186
197
|
end
|
@@ -189,4 +200,10 @@ begin
|
|
189
200
|
rescue => e
|
190
201
|
p "Caught exception: #{e.message}"
|
191
202
|
p e.backtrace
|
203
|
+
|
204
|
+
de5 = ET_DataExtension.new
|
205
|
+
de5.authStub = stubObj
|
206
|
+
de5.props = {"Name" => NameOfDE,"CustomerKey" => NameOfDE}
|
207
|
+
de5.delete
|
208
|
+
|
192
209
|
end
|
data/spec/objects_helper_spec.rb
CHANGED
@@ -1,25 +1,32 @@
|
|
1
1
|
|
2
|
+
# Everything will be readable so test for shared from Read behavior
|
2
3
|
shared_examples_for 'Soap Read Object' do
|
3
|
-
|
4
|
-
it { should respond_to
|
4
|
+
# begin backwards compat
|
5
|
+
it { should respond_to :props= }
|
6
|
+
it { should respond_to :authStub= }
|
7
|
+
# end
|
8
|
+
it { should respond_to :id }
|
9
|
+
it { should respond_to :properties }
|
10
|
+
it { should respond_to :client }
|
11
|
+
it { should respond_to :filter }
|
12
|
+
it { should respond_to :info }
|
13
|
+
it { should respond_to :get }
|
5
14
|
end
|
6
15
|
|
7
16
|
shared_examples_for 'Soap CUD Object' do
|
8
|
-
it { should respond_to
|
9
|
-
it { should respond_to
|
10
|
-
it { should respond_to
|
17
|
+
it { should respond_to :post }
|
18
|
+
it { should respond_to :patch }
|
19
|
+
it { should respond_to :delete }
|
11
20
|
end
|
12
21
|
|
13
22
|
shared_examples_for 'Soap Object' do
|
14
|
-
it { should respond_to(:id) }
|
15
23
|
it_behaves_like 'Soap Read Object'
|
16
24
|
it_behaves_like 'Soap CUD Object'
|
17
25
|
end
|
18
26
|
|
19
27
|
shared_examples_for 'Soap Read Only Object' do
|
20
|
-
it { should respond_to(:id) }
|
21
28
|
it_behaves_like 'Soap Read Object'
|
22
|
-
it { should_not respond_to
|
23
|
-
it { should_not respond_to
|
24
|
-
it { should_not respond_to
|
29
|
+
it { should_not respond_to :post }
|
30
|
+
it { should_not respond_to :patch }
|
31
|
+
it { should_not respond_to :delete }
|
25
32
|
end
|
data/spec/objects_spec.rb
CHANGED
@@ -1,6 +1,29 @@
|
|
1
1
|
require 'spec_helper.rb'
|
2
2
|
require 'objects_helper_spec.rb'
|
3
3
|
|
4
|
+
describe FuelSDK::Objects::Base do
|
5
|
+
|
6
|
+
let(:object) { FuelSDK::Objects::Base.new }
|
7
|
+
subject{ object }
|
8
|
+
|
9
|
+
describe '#properties' do
|
10
|
+
it 'is empty by default' do
|
11
|
+
expect(object.properties).to be_empty
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns item in array when item is not an array' do
|
15
|
+
object.properties = {'name' => 'value'}
|
16
|
+
expect(object.properties).to eq([{'name' => 'value'}])
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns array when assigned array' do
|
20
|
+
object.properties = [{'name' => 'value'}]
|
21
|
+
expect(object.properties).to eq([{'name' => 'value'}])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
4
27
|
describe FuelSDK::BounceEvent do
|
5
28
|
|
6
29
|
let(:object) { FuelSDK::BounceEvent.new }
|
@@ -100,6 +123,354 @@ describe FuelSDK::Subscriber do
|
|
100
123
|
its(:id){ should eq 'Subscriber' }
|
101
124
|
end
|
102
125
|
|
126
|
+
describe FuelSDK::DataExtension::Column do
|
127
|
+
|
128
|
+
let(:object) { FuelSDK::DataExtension::Column.new }
|
129
|
+
subject{ object }
|
130
|
+
|
131
|
+
it_behaves_like 'Soap Read Only Object'
|
132
|
+
its(:id){ should eq 'DataExtensionField' }
|
133
|
+
end
|
134
|
+
|
135
|
+
describe FuelSDK::DataExtension do
|
136
|
+
let(:object) { FuelSDK::DataExtension.new }
|
137
|
+
subject{ object }
|
138
|
+
|
139
|
+
it_behaves_like 'Soap Object'
|
140
|
+
its(:id){ should eq 'DataExtension' }
|
141
|
+
it { should respond_to :columns= }
|
142
|
+
it { should respond_to :fields }
|
143
|
+
it { should respond_to :fields= }
|
144
|
+
|
145
|
+
describe '#post' do
|
146
|
+
subject {
|
147
|
+
object.stub_chain(:client, :soap_post) do |id, properties|
|
148
|
+
[id, properties]
|
149
|
+
end
|
150
|
+
|
151
|
+
object
|
152
|
+
}
|
153
|
+
|
154
|
+
# maybe one day will make it smart enough to zip properties and fields if count is same?
|
155
|
+
it 'raises an error when it has a list of properties and fields' do
|
156
|
+
subject.fields = [{'Name' => 'Name'}]
|
157
|
+
subject.properties = [{'Name' => 'Some DE'}, {'Name' => 'Some DE'}]
|
158
|
+
expect{subject.post}.to raise_error(
|
159
|
+
'Unable to handle muliple DataExtension definitions and a field definition')
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'fields must be empty if not nil' do
|
163
|
+
subject.fields = []
|
164
|
+
subject.properties = [{'Name' => 'Some DE', 'fields' => [{'Name' => 'A field'}]}]
|
165
|
+
expect(subject.post).to eq(
|
166
|
+
[
|
167
|
+
'DataExtension',
|
168
|
+
[{
|
169
|
+
'Name' => 'Some DE',
|
170
|
+
'Fields' => {
|
171
|
+
'Field' => [{'Name' => 'A field'}]
|
172
|
+
}
|
173
|
+
}]
|
174
|
+
])
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'DataExtension can be created using properties and fields accessors' do
|
178
|
+
subject.fields = [{'Name' => 'A field'}]
|
179
|
+
subject.properties = {'Name' => 'Some DE'}
|
180
|
+
expect(subject.post).to eq(
|
181
|
+
[
|
182
|
+
'DataExtension',
|
183
|
+
[{
|
184
|
+
'Name' => 'Some DE',
|
185
|
+
'Fields' => {
|
186
|
+
'Field' => [{'Name' => 'A field'}]
|
187
|
+
}
|
188
|
+
}]
|
189
|
+
])
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'DataExtension fields can be apart of the DataExtention properties' do
|
193
|
+
subject.properties = {'Name' => 'Some DE', 'Fields' => {'Field' => [{'Name' => 'A field'}]}}
|
194
|
+
expect(subject.post).to eq(
|
195
|
+
[
|
196
|
+
'DataExtension',
|
197
|
+
[{
|
198
|
+
'Name' => 'Some DE',
|
199
|
+
'Fields' => {
|
200
|
+
'Field' => [{'Name' => 'A field'}]
|
201
|
+
}
|
202
|
+
}]
|
203
|
+
])
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'List of DataExtension definitions can be passed' do
|
207
|
+
subject.properties = [{'Name' => 'Some DE', 'Fields' => {'Field' => [{'Name' => 'A field'}]}},
|
208
|
+
{'Name' => 'Another DE', 'Fields' => {'Field' => [{'Name' => 'A second field'}]}}]
|
209
|
+
expect(subject.post).to eq(
|
210
|
+
[
|
211
|
+
'DataExtension',
|
212
|
+
[{
|
213
|
+
'Name' => 'Some DE',
|
214
|
+
'Fields' => {
|
215
|
+
'Field' => [{'Name' => 'A field'}]
|
216
|
+
}
|
217
|
+
},{
|
218
|
+
'Name' => 'Another DE',
|
219
|
+
'Fields' => {
|
220
|
+
'Field' => [{'Name' => 'A second field'}]
|
221
|
+
}
|
222
|
+
}]
|
223
|
+
])
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'DataExtension definitions will translate fields entry to correct format' do
|
227
|
+
subject.properties = {'Name' => 'Some DE', 'fields' => [{'Name' => 'A field'}]}
|
228
|
+
expect(subject.post).to eq(
|
229
|
+
[
|
230
|
+
'DataExtension',
|
231
|
+
[{
|
232
|
+
'Name' => 'Some DE',
|
233
|
+
'Fields' => {
|
234
|
+
'Field' => [{'Name' => 'A field'}]
|
235
|
+
}
|
236
|
+
}]
|
237
|
+
])
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'DataExtension definitions will translate columns entry to correct format' do
|
241
|
+
subject.properties = {'Name' => 'Some DE', 'columns' => [{'Name' => 'A field'}]}
|
242
|
+
expect(subject.post).to eq(
|
243
|
+
[
|
244
|
+
'DataExtension',
|
245
|
+
[{
|
246
|
+
'Name' => 'Some DE',
|
247
|
+
'Fields' => {
|
248
|
+
'Field' => [{'Name' => 'A field'}]
|
249
|
+
}
|
250
|
+
}]
|
251
|
+
])
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'supports columns attribute for a single DataExtension definition' do
|
255
|
+
subject.columns = [{'Name' => 'A field'}]
|
256
|
+
subject.properties = {'Name' => 'Some DE'}
|
257
|
+
expect(subject.post).to eq(
|
258
|
+
[
|
259
|
+
'DataExtension',
|
260
|
+
[{
|
261
|
+
'Name' => 'Some DE',
|
262
|
+
'Fields' => {
|
263
|
+
'Field' => [{'Name' => 'A field'}]
|
264
|
+
}
|
265
|
+
}]
|
266
|
+
])
|
267
|
+
end
|
268
|
+
|
269
|
+
describe 'fields are defined twice' do
|
270
|
+
it 'when defined in properties and by fields' do
|
271
|
+
subject.fields = [{'Name' => 'A field'}]
|
272
|
+
subject.properties = {'Name' => 'Some DE', 'Fields' => {'Field' => [{'Name' => 'A field'}]}}
|
273
|
+
expect{subject.post}.to raise_error 'Fields are defined in too many ways. Please only define once.'
|
274
|
+
end
|
275
|
+
it 'when defined in properties explicitly and with columns key' do
|
276
|
+
subject.properties = {'Name' => 'Some DE',
|
277
|
+
'columns' => [{'Name' => 'A fields'}],
|
278
|
+
'Fields' => {'Field' => [{'Name' => 'A field'}]
|
279
|
+
}}
|
280
|
+
expect{subject.post}.to raise_error 'Fields are defined in too many ways. Please only define once.'
|
281
|
+
end
|
282
|
+
it 'when defined in properties explicitly and with fields key' do
|
283
|
+
subject.properties = {'Name' => 'Some DE',
|
284
|
+
'fields' => [{'Name' => 'A fields'}],
|
285
|
+
'Fields' => {'Field' => [{'Name' => 'A field'}]
|
286
|
+
}}
|
287
|
+
expect{subject.post}.to raise_error 'Fields are defined in too many ways. Please only define once.'
|
288
|
+
end
|
289
|
+
it 'when defined in with fields and colums key' do
|
290
|
+
subject.properties = {'Name' => 'Some DE',
|
291
|
+
'fields' => [{'Name' => 'A fields'}],
|
292
|
+
'columns' => [{'Name' => 'A field'}]
|
293
|
+
}
|
294
|
+
expect{subject.post}.to raise_error 'Fields are defined in too many ways. Please only define once.'
|
295
|
+
end
|
296
|
+
it 'when defined in with fields key and accessor' do
|
297
|
+
subject.fields = [{'Name' => 'A field'}]
|
298
|
+
subject.properties = {'Name' => 'Some DE',
|
299
|
+
'fields' => [{'Name' => 'A fields'}]
|
300
|
+
}
|
301
|
+
expect{subject.post}.to raise_error 'Fields are defined in too many ways. Please only define once.'
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
describe '#patch' do
|
307
|
+
subject {
|
308
|
+
object.stub_chain(:client, :soap_patch) do |id, properties|
|
309
|
+
[id, properties]
|
310
|
+
end
|
311
|
+
|
312
|
+
object
|
313
|
+
}
|
314
|
+
|
315
|
+
it 'DataExtension can be created using properties and fields accessors' do
|
316
|
+
subject.fields = [{'Name' => 'A field'}]
|
317
|
+
subject.properties = {'Name' => 'Some DE'}
|
318
|
+
expect(subject.patch).to eq(
|
319
|
+
[
|
320
|
+
'DataExtension',
|
321
|
+
[{
|
322
|
+
'Name' => 'Some DE',
|
323
|
+
'Fields' => {
|
324
|
+
'Field' => [{'Name' => 'A field'}]
|
325
|
+
}
|
326
|
+
}]
|
327
|
+
])
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
describe FuelSDK::DataExtension::Row do
|
333
|
+
let(:object) { FuelSDK::DataExtension::Row.new }
|
334
|
+
subject{ object }
|
335
|
+
|
336
|
+
it_behaves_like 'Soap Object'
|
337
|
+
its(:id){ should eq 'DataExtensionObject' }
|
338
|
+
it { should respond_to :name }
|
339
|
+
it { should respond_to :name= }
|
340
|
+
it { should respond_to :customer_key }
|
341
|
+
it { should respond_to :customer_key= }
|
342
|
+
|
343
|
+
describe '#name' do
|
344
|
+
it 'raises error when missing both name and customer key' do
|
345
|
+
expect{ subject.name }.to raise_error('Unable to process DataExtension::Row '\
|
346
|
+
'request due to missing CustomerKey and Name')
|
347
|
+
end
|
348
|
+
|
349
|
+
it 'returns value' do
|
350
|
+
subject.name = 'name'
|
351
|
+
expect( subject.name ).to eq 'name'
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
describe '#customer_key' do
|
356
|
+
it 'raises error when missing both name and customer key' do
|
357
|
+
expect{ subject.customer_key }.to raise_error('Unable to process DataExtension::Row '\
|
358
|
+
'request due to missing CustomerKey and Name')
|
359
|
+
end
|
360
|
+
|
361
|
+
it 'returns value' do
|
362
|
+
subject.customer_key = 'key'
|
363
|
+
expect( subject.customer_key ).to eq 'key'
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
describe '#retrieve_required' do
|
368
|
+
it 'raises error when missing both name and customer key' do
|
369
|
+
expect{ subject.send(:retrieve_required)}.to raise_error('Unable to process DataExtension::Row '\
|
370
|
+
'request due to missing CustomerKey and Name')
|
371
|
+
expect{ subject.name }.to raise_error('Unable to process DataExtension::Row '\
|
372
|
+
'request due to missing CustomerKey and Name')
|
373
|
+
end
|
374
|
+
|
375
|
+
it 'updates missing' do
|
376
|
+
rsp = mock(FuelSDK::SoapResponse)
|
377
|
+
rsp.stub(:results).and_return([{:name => 'Products', :customer_key => 'ProductsKey'}])
|
378
|
+
rsp.stub(:success?).and_return true
|
379
|
+
|
380
|
+
subject.stub_chain(:client,:soap_get).and_return(rsp)
|
381
|
+
subject.name = 'Not Nil'
|
382
|
+
|
383
|
+
# this really wouldn't work this way. name shouldn't be updated since its whats being used for filter,
|
384
|
+
# but its a good test to show retrieve_required being fired
|
385
|
+
expect(subject.name).to eq 'Not Nil' # not fired
|
386
|
+
expect(subject.customer_key).to eq 'ProductsKey' # fired... stubbed get returns customer_key and name for update
|
387
|
+
expect(subject.name).to eq 'Products' # returned name
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
describe '#get' do
|
392
|
+
subject {
|
393
|
+
object.stub_chain(:client, :soap_get) do |id, properties, filter|
|
394
|
+
[id, properties, filter]
|
395
|
+
end
|
396
|
+
|
397
|
+
object
|
398
|
+
}
|
399
|
+
|
400
|
+
it 'passes id including name to super get' do
|
401
|
+
subject.name = 'Justin'
|
402
|
+
expect(subject.get).to eq(['DataExtensionObject[Justin]', [], nil])
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
describe '#post' do
|
407
|
+
subject {
|
408
|
+
object.stub_chain(:client, :soap_post) do |id, properties|
|
409
|
+
[id, properties]
|
410
|
+
end
|
411
|
+
|
412
|
+
object
|
413
|
+
}
|
414
|
+
|
415
|
+
it 'raises an error when missing both name and customer key' do
|
416
|
+
subject.properties = [{'Name' => 'Some DE'}, {'Name' => 'Some DE'}]
|
417
|
+
expect{subject.post}.to raise_error('Unable to process DataExtension::Row ' \
|
418
|
+
'request due to missing CustomerKey and Name')
|
419
|
+
end
|
420
|
+
|
421
|
+
it 'uses explicitly defined properties' do
|
422
|
+
subject.properties = [{'CustomerKey' => 'Subscribers',
|
423
|
+
'Properties' => {'Property' => [{'Name' => 'Name', 'Value' => 'Justin'}]}}]
|
424
|
+
expect(subject.post).to eq([
|
425
|
+
'DataExtensionObject', [{
|
426
|
+
'CustomerKey' => 'Subscribers',
|
427
|
+
'Properties' => {'Property' => [{'Name' => 'Name', 'Value' => 'Justin'}]}}]
|
428
|
+
])
|
429
|
+
end
|
430
|
+
|
431
|
+
it 'inserts customer key into properties when set using accessor' do
|
432
|
+
subject.customer_key = 'Subscribers'
|
433
|
+
subject.properties = [{'Properties' => {
|
434
|
+
'Property' => [{'Name' => 'Name', 'Value' => 'Justin'}]}}]
|
435
|
+
expect(subject.post).to eq([
|
436
|
+
'DataExtensionObject', [{
|
437
|
+
'CustomerKey' => 'Subscribers',
|
438
|
+
'Properties' => {'Property' => [{'Name' => 'Name', 'Value' => 'Justin'}]}}]
|
439
|
+
])
|
440
|
+
end
|
441
|
+
|
442
|
+
it 'uses name to get customer key for inseration' do
|
443
|
+
subject.name = 'Subscribers'
|
444
|
+
|
445
|
+
rsp = mock(FuelSDK::SoapResponse)
|
446
|
+
rsp.stub(:results).and_return([{:name => 'Products', :customer_key => 'ProductsKey'}])
|
447
|
+
rsp.stub(:success?).and_return true
|
448
|
+
|
449
|
+
subject.stub_chain(:client, :soap_get).and_return(rsp)
|
450
|
+
subject.properties = [{'Properties' => {
|
451
|
+
'Property' => [{'Name' => 'Name', 'Value' => 'Justin'}]}}]
|
452
|
+
|
453
|
+
expect(subject.post).to eq([
|
454
|
+
'DataExtensionObject', [{
|
455
|
+
'CustomerKey' => 'ProductsKey',
|
456
|
+
'Properties' => {'Property' => [{'Name' => 'Name', 'Value' => 'Justin'}]}}]
|
457
|
+
])
|
458
|
+
end
|
459
|
+
|
460
|
+
it 'correctly formats array property' do
|
461
|
+
subject.customer_key = 'Subscribers'
|
462
|
+
|
463
|
+
subject.properties = [{'Name' => 'Justin'}]
|
464
|
+
|
465
|
+
expect(subject.post).to eq([
|
466
|
+
'DataExtensionObject', [{
|
467
|
+
'CustomerKey' => 'Subscribers',
|
468
|
+
'Properties' => {'Property' => [{'Name' => 'Name', 'Value' => 'Justin'}]}}]
|
469
|
+
])
|
470
|
+
end
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
103
474
|
# verify backward compats
|
104
475
|
describe ET_Subscriber do
|
105
476
|
|