responsys-api 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +1 -0
- data/Gemfile +1 -1
- data/README.md +82 -10
- data/lib/responsys/api/all.rb +17 -0
- data/lib/responsys/api/campaign.rb +26 -0
- data/lib/responsys/api/client.rb +70 -0
- data/lib/responsys/api/folder.rb +25 -0
- data/lib/responsys/api/list.rb +39 -0
- data/lib/responsys/api/object/all.rb +11 -0
- data/lib/responsys/api/object/email_format.rb +23 -0
- data/lib/responsys/api/object/field.rb +20 -0
- data/lib/responsys/api/object/field_type.rb +23 -0
- data/lib/responsys/api/object/interact_object.rb +18 -0
- data/lib/responsys/api/object/list_merge_rule.rb +41 -0
- data/lib/responsys/api/object/optional_data.rb +23 -0
- data/lib/responsys/api/object/query_column.rb +23 -0
- data/lib/responsys/api/object/recipient.rb +30 -0
- data/lib/responsys/api/object/recipient_data.rb +21 -0
- data/lib/responsys/api/object/record.rb +19 -0
- data/lib/responsys/api/object/record_data.rb +31 -0
- data/lib/responsys/api/session.rb +30 -0
- data/lib/responsys/api/table.rb +49 -0
- data/lib/responsys/configuration.rb +3 -3
- data/lib/responsys/exceptions/all.rb +1 -0
- data/lib/responsys/exceptions/parameter_exception.rb +7 -0
- data/lib/responsys/helper.rb +78 -2
- data/lib/responsys/i18n/en.yml +20 -0
- data/lib/responsys/member.rb +80 -0
- data/lib/responsys_api.rb +11 -4
- data/responsys-api.gemspec +12 -9
- data/spec/api/campaign_spec.rb +27 -0
- data/spec/api/client_spec.rb +107 -0
- data/spec/api/list_spec.rb +71 -0
- data/spec/api/object/recipient_data_spec.rb +43 -0
- data/spec/api/object/recipient_spec.rb +68 -0
- data/spec/api/object/record_data_spec.rb +28 -0
- data/spec/api/table_spec.rb +111 -0
- data/spec/fixtures/vcr_cassettes/api/campaign/login.yml +940 -0
- data/spec/fixtures/vcr_cassettes/api/client/expired_session.yml +1030 -0
- data/spec/fixtures/vcr_cassettes/api/list/login.yml +982 -0
- data/spec/fixtures/vcr_cassettes/api/list/merge.yml +134 -0
- data/spec/fixtures/vcr_cassettes/api/list/retrieve.yml +46 -0
- data/spec/fixtures/vcr_cassettes/api/list/retrieve_single.yml +133 -0
- data/spec/fixtures/vcr_cassettes/api/list/retrieve_single_single.yml +45 -0
- data/spec/fixtures/vcr_cassettes/api/profile_extension/login.yml +982 -0
- data/spec/fixtures/vcr_cassettes/api/profile_extension/merge_profile_extension_records.yml +46 -0
- data/spec/fixtures/vcr_cassettes/api/profile_extension/retrieve_profile_extension_records.yml +45 -0
- data/spec/fixtures/vcr_cassettes/api/table/create.yml +45 -0
- data/spec/fixtures/vcr_cassettes/api/table/create_with_pk.yml +45 -0
- data/spec/fixtures/vcr_cassettes/api/table/delete.yml +45 -0
- data/spec/fixtures/vcr_cassettes/api/table/delete_with_pk.yml +45 -0
- data/spec/fixtures/vcr_cassettes/member/present1.yml +982 -0
- data/spec/fixtures/vcr_cassettes/member/present2.yml +45 -0
- data/spec/fixtures/vcr_cassettes/member/present3.yml +48 -0
- data/spec/fixtures/vcr_cassettes/member/present4.yml +48 -0
- data/spec/fixtures/vcr_cassettes/member/present5.yml +48 -0
- data/spec/fixtures/vcr_cassettes/member/retrieve_profile_extension.yml +87 -0
- data/spec/member_spec.rb +136 -0
- data/spec/spec_helper.rb +28 -2
- metadata +136 -19
- data/lib/responsys/responsys_api.rb +0 -41
- data/lib/savon/savon_api.rb +0 -22
- data/spec/responsys_api_spec.rb +0 -4
data/lib/responsys_api.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require "i18n"
|
2
|
+
|
3
|
+
I18n.load_path << File.expand_path("../responsys/i18n/en.yml", __FILE__)
|
4
|
+
I18n.locale = :en
|
5
|
+
I18n.enforce_available_locales = false
|
6
|
+
|
7
|
+
require "responsys/exceptions/all"
|
8
|
+
require "responsys/helper"
|
9
|
+
require "responsys/configuration"
|
10
|
+
require "responsys/api/client"
|
11
|
+
require "responsys/member"
|
data/responsys-api.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "responsys-api"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.4"
|
8
8
|
spec.authors = ["Dan DeMeyere", "Florian Lorrain", "Morgan Griggs", "Mike Rocco"]
|
9
|
-
spec.email = ["dan@thredup.com", "
|
10
|
-
spec.description =
|
11
|
-
spec.summary =
|
9
|
+
spec.email = ["dan@thredup.com", "florian.lorrain@thredup.com", "morgan@thredup.com", "michael.rocco@thredup.com"]
|
10
|
+
spec.description = "A gem to integrate with the Responsys SOAP API"
|
11
|
+
spec.summary = "Write a proper summary"
|
12
12
|
spec.homepage = "https://github.com/dandemeyere/responsys-api"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
@@ -17,9 +17,12 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "rubyntlm", "~> 0.4
|
21
|
-
spec.add_dependency "savon", "~> 2.6
|
20
|
+
spec.add_dependency "rubyntlm", "~> 0.4"
|
21
|
+
spec.add_dependency "savon", "~> 2.6"
|
22
|
+
spec.add_dependency "i18n", "~> 0.6"
|
22
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
-
spec.add_development_dependency "rake"
|
24
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "vcr", "~> 2.5"
|
27
|
+
spec.add_development_dependency "webmock", "~> 1.9"
|
25
28
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
require "responsys/api/client"
|
3
|
+
|
4
|
+
describe Responsys::Api::Campaign do
|
5
|
+
|
6
|
+
context "Trigger Message" do
|
7
|
+
before(:all) do
|
8
|
+
VCR.use_cassette("api/campaign/login") do
|
9
|
+
@client = Responsys::Api::Client.instance
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
@campaign = Responsys::Api::Object::InteractObject.new("fake","fake")
|
15
|
+
@recipient = Responsys::Api::Object::Recipient.new(emailAddress: 'fake@thredup.com')
|
16
|
+
@recipientData = Responsys::Api::Object::RecipientData.new(@recipient)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should pass api_method a message Hash" do
|
20
|
+
VCR.use_cassette("api/campaign/login") do
|
21
|
+
expect(@client).to receive(:api_method).with(anything, be_a_kind_of(Hash))
|
22
|
+
@client.trigger_message(@campaign, [@recipientData])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
require "responsys/api/client"
|
3
|
+
require "singleton"
|
4
|
+
|
5
|
+
describe Responsys::Api::Client do
|
6
|
+
|
7
|
+
context "expired session" do
|
8
|
+
before(:example) do
|
9
|
+
allow_any_instance_of(Responsys::Api::Client).to receive(:login).and_return(nil)
|
10
|
+
|
11
|
+
Responsys::Api::Client.instance.instance_variable_set(:@session_id, "fake_session_id")
|
12
|
+
Responsys::Api::Client.instance.instance_variable_set(:@jsession_id, HTTPI::Cookie.new("jsessionid=fakejsessionid; Path=/; HttpOnly"))
|
13
|
+
Responsys::Api::Client.instance.instance_variable_set(:@header, { SessionHeader: { sessionId: "fake_session_id" } })
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should ask for a new session" do
|
17
|
+
VCR.use_cassette("api/client/expired_session") do
|
18
|
+
expect_any_instance_of(Responsys::Api::Client).to receive(:login).exactly(1).times.and_call_original
|
19
|
+
result = Responsys::Api::Client.instance.api_method(:list_folders)
|
20
|
+
|
21
|
+
expect(result[:status]).to eq("ok")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should rerun the request with a new session id" do
|
26
|
+
VCR.use_cassette("api/client/expired_session") do
|
27
|
+
expect_any_instance_of(Responsys::Api::Client).to receive(:login).exactly(1).times.and_call_original
|
28
|
+
|
29
|
+
expect(Responsys::Api::Client.instance.header[:SessionHeader][:sessionId]).to eq("fake_session_id")
|
30
|
+
|
31
|
+
Responsys::Api::Client.instance.api_method(:list_folders)
|
32
|
+
|
33
|
+
expect(Responsys::Api::Client.instance.header[:SessionHeader][:sessionId]).to eq("5GXdGHHKOLqsf4ukCpwQYz3B0b")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
context "Authentication" do
|
40
|
+
let(:savon_client) { double("savon client") }
|
41
|
+
|
42
|
+
before(:context) do
|
43
|
+
@credentials = { username: "your_responsys_username", password: "your_responsys_password" }
|
44
|
+
end
|
45
|
+
|
46
|
+
after(:context) do
|
47
|
+
Singleton.__init__(Responsys::Api::Client)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should set the credentials" do
|
51
|
+
allow_any_instance_of(Responsys::Api::Client).to receive(:login).and_return(nil)
|
52
|
+
|
53
|
+
responsys = Responsys::Api::Client.instance
|
54
|
+
|
55
|
+
expect(responsys.credentials).to eq({ username: "your_responsys_username", password: "your_responsys_password" })
|
56
|
+
end
|
57
|
+
|
58
|
+
context "login" do
|
59
|
+
before(:example) do
|
60
|
+
response = double("response")
|
61
|
+
|
62
|
+
cookies = %w(fake_jsession_id)
|
63
|
+
body = {
|
64
|
+
login_response: {
|
65
|
+
result: {
|
66
|
+
session_id: "fake_session_id"
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
allow(response).to receive(:body).and_return(body)
|
72
|
+
allow(response).to receive(:http).and_return(double("cookies", cookies: cookies))
|
73
|
+
|
74
|
+
allow(Savon).to receive(:client).with({ wsdl: "https://wsxxxx.responsys.net/webservices/wsdl/ResponsysWS_Level1.wsdl", element_form_default: :qualified }).and_return(savon_client) #Avoid the verification of the wsdl
|
75
|
+
allow_any_instance_of(Responsys::Api::Client).to receive(:run).with("login", @credentials).and_return(response) #Verification of credentials
|
76
|
+
allow(savon_client).to receive(:call).with(:login, @credentials ).and_return(response) #Actual login call
|
77
|
+
|
78
|
+
Singleton.__init__(Responsys::Api::Client)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should set the session ids" do
|
82
|
+
instance = Responsys::Api::Client.instance #Get it
|
83
|
+
|
84
|
+
expect(instance.header).to eq({ SessionHeader: { sessionId: "fake_session_id" } }) #Test the ids are right
|
85
|
+
expect(instance.jsession_id).to eq("fake_jsession_id")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "logout" do
|
90
|
+
before(:example) do
|
91
|
+
allow(Savon).to receive(:client).with({ wsdl: "https://wsxxxx.responsys.net/webservices/wsdl/ResponsysWS_Level1.wsdl", element_form_default: :qualified }).and_return(savon_client) #Avoid the verification of the wsdl
|
92
|
+
allow_any_instance_of(Responsys::Api::Client).to receive(:login).and_return(nil) #Avoid credentials checking
|
93
|
+
|
94
|
+
Singleton.__init__(Responsys::Api::Client)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should logout" do
|
98
|
+
instance = Responsys::Api::Client.instance #Get it
|
99
|
+
|
100
|
+
allow(Responsys::Helper).to receive(:format_response_hash).with(any_args) #We dont want to parse the response
|
101
|
+
expect(savon_client).to receive(:call).with(:logout, anything) #Check the call is actually being done
|
102
|
+
|
103
|
+
instance.logout
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
|
3
|
+
describe Responsys::Api::List do
|
4
|
+
|
5
|
+
before(:context) do
|
6
|
+
@list = Responsys::Api::Object::InteractObject.new("another_test_folder", "test_list")
|
7
|
+
@query_column_email = Responsys::Api::Object::QueryColumn.new("EMAIL_ADDRESS")
|
8
|
+
@multiple_users_email = %w(user@email.com user2@email.com user3@email.com)
|
9
|
+
@user1_email = "user@email.com"
|
10
|
+
@user1_mobile = "0000000001"
|
11
|
+
@user2_mobile = "0000000000"
|
12
|
+
|
13
|
+
VCR.use_cassette("api/list/login") do
|
14
|
+
Responsys::Api::Client.instance.login
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "Retrieve info from list with multiple users" do
|
19
|
+
|
20
|
+
it "should get a ok status" do
|
21
|
+
VCR.use_cassette("api/list/retrieve") do
|
22
|
+
response = Responsys::Api::Client.instance.retrieve_list_members(@list, @query_column_email, %w(EMAIL_ADDRESS_ MOBILE_NUMBER_), @multiple_users_email)
|
23
|
+
|
24
|
+
expect(response[:status]).to eq("ok")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should get a value from the data" do
|
29
|
+
VCR.use_cassette("api/list/retrieve") do
|
30
|
+
response = Responsys::Api::Client.instance.retrieve_list_members(@list, @query_column_email, %w(EMAIL_ADDRESS_ MOBILE_NUMBER_), @multiple_users_email)
|
31
|
+
|
32
|
+
expect(response[:data][2][:EMAIL_ADDRESS_]).to eq("user2@email.com")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should get a nil value" do
|
37
|
+
VCR.use_cassette("api/list/retrieve") do
|
38
|
+
response = Responsys::Api::Client.instance.retrieve_list_members(@list, @query_column_email, %w(EMAIL_ADDRESS_ MOBILE_NUMBER_), @multiple_users_email)
|
39
|
+
|
40
|
+
expect(response[:data][1][:MOBILE_NUMBER_]).to be(nil)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return a single result" do
|
45
|
+
VCR.use_cassette("api/list/retrieve_single") do
|
46
|
+
response = Responsys::Api::Client.instance.retrieve_list_members(@list, @query_column_email, %w(EMAIL_ADDRESS_ MOBILE_NUMBER_), [@user1_email])
|
47
|
+
|
48
|
+
expect(response[:data][0][:EMAIL_ADDRESS_]).to eq(@user1_email)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should return a single field in a single record" do
|
53
|
+
VCR.use_cassette("api/list/retrieve_single_single") do
|
54
|
+
response = Responsys::Api::Client.instance.retrieve_list_members(@list, @query_column_email, %w(EMAIL_ADDRESS_), [@user1_email])
|
55
|
+
|
56
|
+
expect(response[:data][0][:EMAIL_ADDRESS_]).to eq(@user1_email)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "Merge list members" do
|
62
|
+
it "should reject no record" do
|
63
|
+
VCR.use_cassette("api/list/merge") do
|
64
|
+
data = [{ Email_Address_: @user1_email, Mobile_Number_: @user1_mobile }, { Mobile_Number_: @user2_mobile, Customer_ID_: "" }]
|
65
|
+
response = Responsys::Api::Client.instance.merge_list_members(@list, Responsys::Api::Object::RecordData.new(data), merge_rule = Responsys::Api::Object::ListMergeRule.new(matchColumnName1: "Mobile_Number_"))
|
66
|
+
|
67
|
+
expect(response[:data][0][:result][:rejected_count].to_i).to eq(0)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
require "responsys/api/client"
|
3
|
+
|
4
|
+
describe Responsys::Api::Object::RecipientData do
|
5
|
+
|
6
|
+
|
7
|
+
context "new RecipientData" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@recipient = Responsys::Api::Object::Recipient.new
|
11
|
+
@recipient_data = Responsys::Api::Object::RecipientData.new(@recipient)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have a recipient attribute of type Recipient" do
|
15
|
+
expect(@recipient_data.recipient).to be_a(Responsys::Api::Object::Recipient)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have an optional_data attribute of type Array" do
|
19
|
+
expect(@recipient_data.optional_data).to be_a(Responsys::Api::Object::OptionalData)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
context "RecipientData to_api method" do
|
25
|
+
|
26
|
+
before(:each) do
|
27
|
+
@recipient = Responsys::Api::Object::Recipient.new
|
28
|
+
@recipient_data = Responsys::Api::Object::RecipientData.new(@recipient)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be of type Hash" do
|
32
|
+
expect(@recipient_data.to_api).to be_a(Hash)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have a recipient attribute of type Hash" do
|
36
|
+
expect(@recipient_data.to_api[:recipient]).to be_a(Hash)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should have an optionalData attribute of type Array" do
|
40
|
+
expect(@recipient_data.to_api[:optionalData]).to be_a(Hash)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
require "responsys/api/client"
|
3
|
+
|
4
|
+
describe Responsys::Api::Object::Recipient do
|
5
|
+
|
6
|
+
|
7
|
+
context "new recipient" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@recipient = Responsys::Api::Object::Recipient.new
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have list_name attribute of type InteractObject" do
|
14
|
+
expect(@recipient.list_name).to be_a(Responsys::Api::Object::InteractObject)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have recipient_id attribute" do
|
18
|
+
expect(@recipient.recipient_id).to be
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have customer_id attribute" do
|
22
|
+
expect(@recipient.customer_id).to be
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have email_address attribute" do
|
26
|
+
expect(@recipient.email_address).to be
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have mobile_number attribute" do
|
30
|
+
expect(@recipient.mobile_number).to be
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have email_format attribute of type EmailFormat" do
|
34
|
+
expect(@recipient.email_format).to be_a(Responsys::Api::Object::EmailFormat)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "recipient to_api" do
|
39
|
+
|
40
|
+
before(:each) do
|
41
|
+
@recipient = Responsys::Api::Object::Recipient.new
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should have listName attribute of type Hash" do
|
45
|
+
expect(@recipient.to_api[:listName]).to be_a(Hash)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should have recipientId attribute " do
|
49
|
+
expect(@recipient.to_api[:recipientId]).to be
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have customerId attribute " do
|
53
|
+
expect(@recipient.to_api[:customerId]).to be
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should have emailAddress attribute " do
|
57
|
+
expect(@recipient.to_api[:emailAddress]).to be
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should have mobileNumber attribute " do
|
61
|
+
expect(@recipient.to_api[:mobileNumber]).to be
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should have EmailFormat attribute of type String" do
|
65
|
+
expect(@recipient.to_api[:emailFormat]).to be_a(String)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
|
3
|
+
describe Responsys::Api::Object::RecordData do
|
4
|
+
|
5
|
+
context "Constructor params handling" do
|
6
|
+
before(:each) do
|
7
|
+
@data = [{ field1: "value11", field2: "value12" }, { field2: "value22", field3: "value23" }]
|
8
|
+
@field_names = [:field1, :field2, :field3]
|
9
|
+
@record1 = ["value11", "value12", ""]
|
10
|
+
@record2 = ["", "value22", "value23"]
|
11
|
+
|
12
|
+
@object = Responsys::Api::Object::RecordData.new(@data)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should handle transform the constructor params" do
|
16
|
+
expect(@object.field_names).to eq(@field_names)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should transform correctly the object to the api representation" do
|
20
|
+
expect(@object.to_api).to eq({ fieldNames: @field_names, records: [{ fieldValues: @record1 }, { fieldValues: @record2 }] })
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should raise an exception if the constructor parameter is not an array" do
|
24
|
+
expect{Responsys::Api::Object::RecordData.new("")}.to raise_exception(Responsys::Exceptions::ParameterException, "The data you provided is not an array")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "spec_helper.rb"
|
2
|
+
|
3
|
+
describe Responsys::Api::Table do
|
4
|
+
|
5
|
+
before(:example) do
|
6
|
+
@profile_extension = Responsys::Api::Object::InteractObject.new("another_test_folder", "test_profile_extension")
|
7
|
+
@query_column_riid = Responsys::Api::Object::QueryColumn.new("RIID")
|
8
|
+
@query_column_email = Responsys::Api::Object::QueryColumn.new("EMAIL_ADDRESS")
|
9
|
+
@fields = %w(RIID_ EMAIL_ADDRESS)
|
10
|
+
@user_riid = 398426
|
11
|
+
@user_email = "user2@email.com"
|
12
|
+
|
13
|
+
VCR.use_cassette("api/profile_extension/login") do
|
14
|
+
Responsys::Api::Client.instance.login
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "create table" do
|
19
|
+
before(:all) do
|
20
|
+
@table = Responsys::Api::Object::InteractObject.new("another_test_folder", "table_#{Time.now.to_i}")
|
21
|
+
@table_with_pk = Responsys::Api::Object::InteractObject.new("another_test_folder", "table_with_pk_#{Time.now.to_i}")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should create a table" do
|
25
|
+
VCR.use_cassette("api/table/create") do
|
26
|
+
fields = [
|
27
|
+
Responsys::Api::Object::Field.new("field1", Responsys::Api::Object::FieldType.new("STR500"), custom = false, data_extraction_key = false),
|
28
|
+
Responsys::Api::Object::Field.new("field2", Responsys::Api::Object::FieldType.new("NUMBER"), custom = false, data_extraction_key = false),
|
29
|
+
Responsys::Api::Object::Field.new("field3", Responsys::Api::Object::FieldType.new("TIMESTAMP"), custom = false, data_extraction_key = false),
|
30
|
+
]
|
31
|
+
response = Responsys::Api::Client.instance.create_table(@table, fields)
|
32
|
+
|
33
|
+
expect(response[:result]).to be(true)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should delete the previous table" do
|
38
|
+
VCR.use_cassette("api/table/delete") do
|
39
|
+
response = Responsys::Api::Client.instance.delete_table(@table)
|
40
|
+
|
41
|
+
expect(response[:result]).to be(true)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should create a table with pk" do
|
46
|
+
VCR.use_cassette("api/table/create_with_pk") do
|
47
|
+
fields = [
|
48
|
+
Responsys::Api::Object::Field.new("field1", Responsys::Api::Object::FieldType.new("STR500"), custom = false, data_extraction_key = false),
|
49
|
+
Responsys::Api::Object::Field.new("field2", Responsys::Api::Object::FieldType.new("NUMBER"), custom = false, data_extraction_key = false),
|
50
|
+
Responsys::Api::Object::Field.new("field3", Responsys::Api::Object::FieldType.new("TIMESTAMP"), custom = false, data_extraction_key = false),
|
51
|
+
]
|
52
|
+
response = Responsys::Api::Client.instance.create_table_with_pk(@table_with_pk, fields, %w(field1))
|
53
|
+
|
54
|
+
expect(response[:result]).to be(true)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should delete the previous table with pk" do
|
59
|
+
VCR.use_cassette("api/table/delete_with_pk") do
|
60
|
+
response = Responsys::Api::Client.instance.delete_table(@table_with_pk)
|
61
|
+
|
62
|
+
expect(response[:result]).to be(true)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "retrieve_profile_extension_records" do
|
68
|
+
|
69
|
+
it "should set the status to ok" do
|
70
|
+
VCR.use_cassette("api/profile_extension/retrieve_profile_extension_records") do
|
71
|
+
response = Responsys::Api::Client.instance.retrieve_profile_extension_records(@profile_extension, @query_column_riid, @fields, %W(#{@user_riid}))
|
72
|
+
|
73
|
+
expect(response[:status]).to eq("ok")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should return one record" do
|
78
|
+
VCR.use_cassette("api/profile_extension/retrieve_profile_extension_records") do
|
79
|
+
response = Responsys::Api::Client.instance.retrieve_profile_extension_records(@profile_extension, @query_column_riid, @fields, %W(#{@user_riid}))
|
80
|
+
|
81
|
+
expect(response[:data].length).to eq(1)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should return two key-value pairs" do
|
86
|
+
VCR.use_cassette("api/profile_extension/retrieve_profile_extension_records") do
|
87
|
+
response = Responsys::Api::Client.instance.retrieve_profile_extension_records(@profile_extension, @query_column_riid, @fields, %W(#{@user_riid}))
|
88
|
+
|
89
|
+
expect(response[:data][0].length).to eq(2)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should add (merge into) a profile extension member" do
|
94
|
+
VCR.use_cassette("api/profile_extension/merge_profile_extension_records") do
|
95
|
+
record_data = Responsys::Api::Object::RecordData.new([{EMAIL_ADDRESS_: @user_email, MONTHLY_PURCH: 3000}])
|
96
|
+
response = Responsys::Api::Client.instance.merge_into_profile_extension(@profile_extension, record_data, "EMAIL_ADDRESS", true)
|
97
|
+
|
98
|
+
expect(response[:status]).to eq("ok")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should delete a profile extension member" do
|
103
|
+
VCR.use_cassette("api/profile_extension/retrieve_profile_extension_records") do
|
104
|
+
response = Responsys::Api::Client.instance.delete_profile_extension_members(@profile_extension, @query_column_email, %W{#{@user_email}})
|
105
|
+
|
106
|
+
expect(response[:status]).to eq("ok")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|