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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  # Methods for the EmailCategory API
@@ -17,4 +18,4 @@ module Emarsys
17
18
 
18
19
  end
19
20
  end
20
- end
21
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  # Internal helper class for valid email launch status.
@@ -35,4 +36,4 @@ module Emarsys
35
36
  end
36
37
 
37
38
  end
38
- end
39
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  # Internal helper class for valid email status codes.
@@ -36,4 +37,4 @@ module Emarsys
36
37
  end
37
38
 
38
39
  end
39
- end
40
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  # Methods for the Event API
@@ -33,6 +34,22 @@ module Emarsys
33
34
  post "event/#{event_id}/trigger", params
34
35
  end
35
36
 
37
+ # Trigger an external event for multiple contacts
38
+ #
39
+ # @param event_id [Integer, String] The internal emarsys id
40
+ # @param key_id [Integer, String] The identifer of the key field (e.g. 3 for 'email')
41
+ # @param contacts [Array, Hash] An array with hashes containing the contacts and optional data per contact
42
+ # @return [Hash] Result data
43
+ # @example
44
+ # Emarsys::Event.trigger_multiple(2, 3, [{:external_id => "test@example.com"},{:external_id => "test2@example.com", :data => {:name => "Special Name"}}])
45
+ def trigger_multiple(event_id, key_id, contacts)
46
+ external_id = ""
47
+ transformed_key_id = transform_key_id(key_id)
48
+ params = {:key_id => transformed_key_id, :external_id => external_id, :data => nil}
49
+ params.merge!(:contacts => contacts)
50
+ post "event/#{event_id}/trigger", params
51
+ end
52
+
36
53
  # @private
37
54
  def transform_key_id(key_id)
38
55
  matching_attributes = Emarsys::FieldMapping::ATTRIBUTES.find{|elem| elem[:identifier] == key_id.to_s}
@@ -41,4 +58,4 @@ module Emarsys
41
58
  end
42
59
 
43
60
  end
44
- end
61
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  # Methods for the Export API
@@ -19,4 +20,4 @@ module Emarsys
19
20
 
20
21
  end
21
22
 
22
- end
23
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  # Methods for the Field API
@@ -36,4 +37,4 @@ module Emarsys
36
37
 
37
38
  end
38
39
 
39
- end
40
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  # Methods for the File API
@@ -36,4 +37,4 @@ module Emarsys
36
37
 
37
38
  end
38
39
 
39
- end
40
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  # Methods for the Folder API
@@ -21,4 +22,4 @@ module Emarsys
21
22
 
22
23
  end
23
24
 
24
- end
25
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  # Methods for the Form API
@@ -18,4 +19,4 @@ module Emarsys
18
19
  end
19
20
  end
20
21
 
21
- end
22
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  # Methods for the Lanugage API
@@ -17,4 +18,4 @@ module Emarsys
17
18
 
18
19
  end
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 Segment API
@@ -18,4 +19,4 @@ module Emarsys
18
19
  end
19
20
  end
20
21
 
21
- end
22
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  # Methods for the Source API
@@ -37,4 +38,4 @@ module Emarsys
37
38
 
38
39
  end
39
40
  end
40
- end
41
+ end
data/lib/emarsys/error.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
  # Custom error class for rescuing from Emarsys errors
3
4
  class Error < StandardError
@@ -21,4 +22,4 @@ module Emarsys
21
22
 
22
23
  # Raised when Emarsys returns a 500 HTTP status code
23
24
  class InternalServerError < Error; end
24
- end
25
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Hash
2
3
  def stringify_keys
3
4
  inject({}) do |options, (key, value)|
@@ -5,4 +6,4 @@ class Hash
5
6
  options
6
7
  end
7
8
  end
8
- end
9
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys::FieldMapping
2
3
 
3
4
  ATTRIBUTES = [
@@ -52,4 +53,4 @@ module Emarsys::FieldMapping
52
53
  {:id => 48, :identifier => '_date_of_first_registration', :name => 'Date of first registration'}
53
54
  ]
54
55
 
55
- end
56
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
  class ParamsConverter
3
4
 
@@ -26,4 +27,4 @@ module Emarsys
26
27
  end
27
28
 
28
29
  end
29
- end
30
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
 
3
4
  class Request
@@ -43,4 +44,4 @@ module Emarsys
43
44
  end
44
45
  end
45
46
 
46
- end
47
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
3
  class Response
3
4
  attr_accessor :code, :text, :data, :status
@@ -21,4 +22,4 @@ module Emarsys
21
22
  end
22
23
 
23
24
  end
24
- end
25
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Emarsys
2
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
3
4
  end
data/lib/emarsys.rb CHANGED
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  require "base64"
2
3
  require 'json'
3
4
  require 'rest_client'
4
5
  require 'uri'
5
6
 
6
7
  require 'emarsys/client'
8
+ require 'emarsys/country'
7
9
  require 'emarsys/data_object'
8
10
  require 'emarsys/error'
9
11
  require 'emarsys/extensions'
@@ -36,7 +38,7 @@ module Emarsys
36
38
  class << self
37
39
 
38
40
  # @!attribute api_endpoint
39
- # @return [String] Base URL for emarsys URLs. default: https://suite5.emarsys.net/api/v2
41
+ # @return [String] Base URL for emarsys URLs. default: https://api.emarsys.net/api/v2
40
42
  # @!attribute api_password
41
43
  # @return [String] API Username given by Emarsys
42
44
  # @!attribute api_username
@@ -48,7 +50,7 @@ module Emarsys
48
50
  #
49
51
  # @return [String] domain which should be used to query the API
50
52
  def api_endpoint
51
- @api_endpoint ||= 'https://suite5.emarsys.net/api/v2'
53
+ @api_endpoint ||= 'https://api.emarsys.net/api/v2'
52
54
  end
53
55
 
54
56
  # Set configuration options using a block
@@ -57,4 +59,4 @@ module Emarsys
57
59
  end
58
60
 
59
61
  end
60
- end
62
+ end
@@ -4,22 +4,22 @@ describe Emarsys::Client do
4
4
 
5
5
  describe 'configs for username and password' do
6
6
  it 'inherits username from module' do
7
- Emarsys.stub(:api_username).and_return("my_username")
7
+ allow(Emarsys).to receive(:api_username).and_return("my_username")
8
8
  expect(Emarsys::Client.new.username).to eq("my_username")
9
9
  end
10
10
 
11
11
  it 'inherits password from module' do
12
- Emarsys.stub(:api_password).and_return("my_password")
12
+ allow(Emarsys).to receive(:api_password).and_return("my_password")
13
13
  expect(Emarsys::Client.new.password).to eq("my_password")
14
14
  end
15
15
 
16
16
  it 'raises error if api_username is not set' do
17
- Emarsys.stub(:api_username).and_return(nil)
17
+ allow(Emarsys).to receive(:api_username).and_return(nil)
18
18
  expect{Emarsys::Client.new.username}.to raise_error(ArgumentError, 'Emarsys.api_username is not set')
19
19
  end
20
20
 
21
21
  it 'raises error if api_password is not set' do
22
- Emarsys.stub(:api_password).and_return(nil)
22
+ allow(Emarsys).to receive(:api_password).and_return(nil)
23
23
  expect{Emarsys::Client.new.password}.to raise_error(ArgumentError, 'Emarsys.api_password is not set')
24
24
  end
25
25
  end
@@ -27,54 +27,56 @@ describe Emarsys::Client do
27
27
  context 'client authentication' do
28
28
  describe '#x_wsse_string' do
29
29
  it 'builds x_wsse_string with specific format' do
30
- Emarsys::Client.any_instance.stub(:username).and_return("my_username")
31
- Emarsys::Client.any_instance.stub(:header_password_digest).and_return("12345689")
32
- Emarsys::Client.any_instance.stub(:header_nonce).and_return("some_header_nonce")
33
- Emarsys::Client.any_instance.stub(:header_created).and_return("2013-01-01")
30
+ allow_any_instance_of(Emarsys::Client).to receive(:username).and_return("my_username")
31
+ allow_any_instance_of(Emarsys::Client).to receive(:header_password_digest).and_return("12345689")
32
+ allow_any_instance_of(Emarsys::Client).to receive(:header_nonce).and_return("some_header_nonce")
33
+ allow_any_instance_of(Emarsys::Client).to receive(:header_created).and_return("2013-01-01")
34
34
  expect(Emarsys::Client.new.x_wsse_string).to eq(
35
- 'UsernameToken Username = "my_username", PasswordDigest = "12345689", Nonce = "some_header_nonce", Created = "2013-01-01"'
35
+ 'UsernameToken Username="my_username", PasswordDigest="12345689", Nonce="some_header_nonce", Created="2013-01-01"'
36
36
  )
37
37
  end
38
38
  end
39
39
 
40
40
  describe '#header_password_digest' do
41
41
  before :each do
42
- Emarsys::Client.any_instance.stub(:calculated_digest).and_return("something")
42
+ allow_any_instance_of(Emarsys::Client).to receive(:calculated_digest).and_return("something")
43
43
  end
44
44
 
45
45
  it 'encodes string with Base64' do
46
- Base64.should_receive(:encode64).with("something").and_return("something_base64_encoded")
46
+ expect(Base64).to receive(:encode64).with("something").and_return("something_base64_encoded")
47
47
  Emarsys::Client.new.header_password_digest
48
48
  end
49
49
 
50
50
  it 'strips of \n character' do
51
- Base64.should_receive(:encode64).with("something").and_return("something_base64_encoded\n")
51
+ expect(Base64).to receive(:encode64).with("something").and_return("something_base64_encoded\n")
52
52
  expect(Emarsys::Client.new.header_password_digest).to eq("something_base64_encoded")
53
53
  end
54
54
  end
55
55
 
56
56
  describe '#header_nonce' do
57
- it 'uses md5 hash auf current time (as integer)' do
58
- Time.any_instance.stub(:to_i).and_return(123456789)
59
- Digest::MD5.should_receive(:hexdigest).with("123456789").and_return("25f9e794323b453885f5181f1b624d0b")
60
- Emarsys::Client.new.header_nonce
57
+ it 'uses 16 random bytes to generate a 32 char hex string' do
58
+ expect(Emarsys::Client.new.header_nonce).to match(/^[0-9a-f]{32}$/i)
59
+ end
60
+
61
+ it 'only creates the nonce once' do
62
+ client = Emarsys::Client.new
63
+ nonce = client.header_nonce
64
+ expect(client.header_nonce).to eq nonce
61
65
  end
62
66
  end
63
67
 
64
68
  describe '#header_created' do
65
69
  it 'uses current timestamp format' do
66
- time = Time.parse("2013-01-01 01:00:01")
67
- Time.stub(:new).and_return(time)
68
- expect(Emarsys::Client.new.header_created).to eq("2013-01-01 01:00:01")
70
+ expect(Emarsys::Client.new.header_created).to eq(Time.now.utc.iso8601)
69
71
  end
70
72
  end
71
73
 
72
74
  describe '#calculated_digest' do
73
75
  it 'runs sha1 on header_nonce + header_created + password' do
74
- Emarsys::Client.any_instance.stub(:header_nonce).and_return("some_header_nonce")
75
- Emarsys::Client.any_instance.stub(:header_created).and_return("12345689")
76
- Emarsys::Client.any_instance.stub(:password).and_return("my_password")
77
- Digest::SHA1.should_receive(:hexdigest).with("some_header_nonce12345689my_password")
76
+ allow_any_instance_of(Emarsys::Client).to receive(:header_nonce).and_return("some_header_nonce")
77
+ allow_any_instance_of(Emarsys::Client).to receive(:header_created).and_return("12345689")
78
+ allow_any_instance_of(Emarsys::Client).to receive(:password).and_return("my_password")
79
+ expect(Digest::SHA1).to receive(:hexdigest).with("some_header_nonce12345689my_password")
78
80
  Emarsys::Client.new.calculated_digest
79
81
  end
80
82
  end
@@ -82,4 +84,3 @@ describe Emarsys::Client do
82
84
  end
83
85
 
84
86
  end
85
-
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Emarsys::Country do
4
+
5
+ describe 'from_iso' do
6
+ it 'maps ISO-3166-1 alpha-2 country code to equivalent Emarsys internal country ID' do
7
+ expect(Emarsys::Country.from_iso('AF')).to eq( { id: 1, name: 'Afghanistan'} )
8
+ end
9
+
10
+ it 'supports passing ISO country code as a symbol' do
11
+ expect(Emarsys::Country.from_iso(:AF)).to eq( { id: 1, name: 'Afghanistan'} )
12
+ end
13
+
14
+ it 'ignores case of the ISO country code' do
15
+ expect(Emarsys::Country.from_iso('aF')).to eq( { id: 1, name: 'Afghanistan'} )
16
+ end
17
+
18
+ it 'returns nil for an unknown/invalid code' do
19
+ expect(Emarsys::Country.from_iso('XY')).to eq nil
20
+ end
21
+ end
22
+ end
@@ -5,33 +5,33 @@ describe Emarsys::DataObject do
5
5
 
6
6
  describe '.get' do
7
7
  it "delegates to the instance request method" do
8
- Emarsys::DataObject.any_instance.should_receive(:request).with('get', 'test_method', {}).and_return(nil)
8
+ allow_any_instance_of(Emarsys::DataObject).to receive(:request).with('get', 'test_method', {}).and_return(nil)
9
9
  Emarsys::DataObject.get('test_method', {})
10
10
  end
11
11
 
12
12
  it "transfers params to specific emarsys params format" do
13
- Emarsys::DataObject.any_instance.should_receive(:request).with('get', 'test_method/a=1&b=2', {}).and_return(nil)
13
+ allow_any_instance_of(Emarsys::DataObject).to receive(:request).with('get', 'test_method/?a=1&b=2', {}).and_return(nil)
14
14
  Emarsys::DataObject.get('test_method', {'a' => 1, 'b' => 2})
15
15
  end
16
16
  end
17
17
 
18
18
  describe '.post' do
19
19
  it "delegates to the instance request method" do
20
- Emarsys::DataObject.any_instance.should_receive(:request).with('post', 'test_method', {}).and_return(nil)
20
+ allow_any_instance_of(Emarsys::DataObject).to receive(:request).with('post', 'test_method', {}).and_return(nil)
21
21
  Emarsys::DataObject.post('test_method', {})
22
22
  end
23
23
  end
24
24
 
25
25
  describe '.put' do
26
26
  it "delegates to the instance request method" do
27
- Emarsys::DataObject.any_instance.should_receive(:request).with('put', 'test_method', {}).and_return(nil)
27
+ allow_any_instance_of(Emarsys::DataObject).to receive(:request).with('put', 'test_method', {}).and_return(nil)
28
28
  Emarsys::DataObject.put('test_method', {})
29
29
  end
30
30
  end
31
31
 
32
32
  describe '.delete' do
33
33
  it "delegates to the instance request method" do
34
- Emarsys::DataObject.any_instance.should_receive(:request).with('delete', 'test_method', {}).and_return(nil)
34
+ allow_any_instance_of(Emarsys::DataObject).to receive(:request).with('delete', 'test_method', {}).and_return(nil)
35
35
  Emarsys::DataObject.delete('test_method', {})
36
36
  end
37
37
  end
@@ -39,7 +39,12 @@ describe Emarsys::DataObject do
39
39
  describe '.parameterize_params' do
40
40
  it "converts hash to params string" do
41
41
  params = {"a" => 1, "b" => 2, "c" => 3}
42
- expect(Emarsys::DataObject.parameterize_params(params)).to eq("a=1&b=2&c=3")
42
+ expect(Emarsys::DataObject.parameterize_params(params)).to eq("?a=1&b=2&c=3")
43
+ end
44
+
45
+ it "url_encodes params" do
46
+ params = {"email" => "best/email@mail.org"}
47
+ expect(Emarsys::DataObject.parameterize_params(params)).to eq("?email=best%2Femail%40mail.org")
43
48
  end
44
49
  end
45
50
  end
@@ -47,9 +52,9 @@ describe Emarsys::DataObject do
47
52
  context "as an instance" do
48
53
  let(:data_object) { Emarsys::DataObject.new }
49
54
 
50
- it "provides a simpel #request that delegates to Emarsys::Request" do
51
- Emarsys::Request.any_instance.should_receive(:send_request).and_return(nil)
55
+ it "provides a simple #request that delegates to Emarsys::Request" do
56
+ allow_any_instance_of(Emarsys::Request).to receive(:send_request).and_return(nil)
52
57
  data_object.request('get', 'test_method', {})
53
58
  end
54
59
  end
55
- end
60
+ end
@@ -3,7 +3,9 @@ require 'spec_helper'
3
3
  describe Emarsys::Condition do
4
4
  describe ".collection" do
5
5
  it "requests all conditions" do
6
- stub_get("condition") { Emarsys::Condition.collection }.should have_been_requested.once
6
+ expect(
7
+ stub_get("condition") { Emarsys::Condition.collection }
8
+ ).to have_been_requested.once
7
9
  end
8
10
  end
9
- end
11
+ end
@@ -3,7 +3,9 @@ require 'spec_helper'
3
3
  describe Emarsys::ContactList do
4
4
  describe ".collection" do
5
5
  it "requests all contactlists" do
6
- stub_get("contactlist") { Emarsys::ContactList.collection }.should have_been_requested.once
6
+ expect(
7
+ stub_get("contactlist") { Emarsys::ContactList.collection }
8
+ ).to have_been_requested.once
7
9
  end
8
10
  end
9
- end
11
+ end
@@ -4,70 +4,70 @@ describe Emarsys::Contact do
4
4
  describe ".create" do
5
5
  it "requests contact creation with parameters" do
6
6
  stub_params = {1 => 'John', 2 => "Doe"}
7
- stub = stub_request(:post, "https://suite5.emarsys.net/api/v2/contact").with(:body => stub_params.merge!({'key_id' => 3, 3 => 'john.doe@example.com'}).to_json).to_return(standard_return_body)
7
+ stub = stub_request(:post, "https://api.emarsys.net/api/v2/contact").with(:body => stub_params.merge!({'key_id' => 3, 3 => 'john.doe@example.com'}).to_json).to_return(standard_return_body)
8
8
  Emarsys::Contact.create(3, "john.doe@example.com", stub_params)
9
- stub.should have_been_requested.once
9
+ expect(stub).to have_been_requested.once
10
10
  end
11
11
  end
12
12
 
13
13
  describe ".emarsys_id" do
14
14
  it "requests emarsys_id of a contact" do
15
- stub = stub_request(:get, "https://suite5.emarsys.net/api/v2/contact/3=jane.doe@example.com").to_return(standard_return_body)
15
+ stub = stub_request(:get, "https://api.emarsys.net/api/v2/contact/?3=jane.doe@example.com").to_return(standard_return_body)
16
16
  Emarsys::Contact.emarsys_id(3, 'jane.doe@example.com')
17
- stub.should have_been_requested.once
17
+ expect(stub).to have_been_requested.once
18
18
  end
19
19
  end
20
20
 
21
21
  describe ".update" do
22
22
  it "requests contact update with parameters" do
23
23
  stub_params = {1 => 'Jane', 2 => "Doe"}
24
- stub = stub_request(:put, "https://suite5.emarsys.net/api/v2/contact").with(:body => stub_params.merge!({'key_id' => 3, 3 => 'jane.doe@example.com'}).to_json).to_return(standard_return_body)
24
+ stub = stub_request(:put, "https://api.emarsys.net/api/v2/contact").with(:body => stub_params.merge!({'key_id' => 3, 3 => 'jane.doe@example.com'}).to_json).to_return(standard_return_body)
25
25
  Emarsys::Contact.update(3, 'jane.doe@example.com', stub_params)
26
- stub.should have_been_requested.once
26
+ expect(stub).to have_been_requested.once
27
27
  end
28
28
  end
29
29
 
30
30
  describe ".create_batch" do
31
31
  it "requests contact batch creation with parameters" do
32
32
  stub_params = [{1 => 'Jane', 2 => "Doe"}, {1 => 'Paul', 2 => 'Tester'}]
33
- stub = stub_request(:post, "https://suite5.emarsys.net/api/v2/contact").with(:body => {'key_id' => 3, 'contacts' => stub_params}.to_json).to_return(standard_return_body)
33
+ stub = stub_request(:post, "https://api.emarsys.net/api/v2/contact").with(:body => {'key_id' => 3, 'contacts' => stub_params}.to_json).to_return(standard_return_body)
34
34
  Emarsys::Contact.create_batch(3, stub_params)
35
- stub.should have_been_requested.once
35
+ expect(stub).to have_been_requested.once
36
36
  end
37
37
  end
38
38
 
39
39
  describe ".update_batch" do
40
40
  it "requests contact batch update with parameters" do
41
41
  stub_params = [{1 => 'Jane', 2 => "Doe"}, {1 => 'Paul', 2 => 'Tester'}]
42
- stub = stub_request(:put, "https://suite5.emarsys.net/api/v2/contact").with(:body => {'key_id' => 3, 'contacts' => stub_params}.to_json).to_return(standard_return_body)
42
+ stub = stub_request(:put, "https://api.emarsys.net/api/v2/contact").with(:body => {'key_id' => 3, 'contacts' => stub_params}.to_json).to_return(standard_return_body)
43
43
  Emarsys::Contact.update_batch(3, stub_params)
44
- stub.should have_been_requested.once
44
+ expect(stub).to have_been_requested.once
45
45
  end
46
46
  end
47
47
 
48
48
  describe ".contact_history" do
49
49
  it "requests contact histories" do
50
50
  stub_params = [1,2,3]
51
- stub = stub_request(:post, "https://suite5.emarsys.net/api/v2/contact/getcontacthistory").with(:body => {'contacts' => stub_params}.to_json).to_return(standard_return_body)
51
+ stub = stub_request(:post, "https://api.emarsys.net/api/v2/contact/getcontacthistory").with(:body => {'contacts' => stub_params}.to_json).to_return(standard_return_body)
52
52
  Emarsys::Contact.contact_history(stub_params)
53
- stub.should have_been_requested.once
53
+ expect(stub).to have_been_requested.once
54
54
  end
55
55
  end
56
56
 
57
57
  describe ".search" do
58
58
  it "requests contact data based on search params" do
59
- stub = stub_request(:post, "https://suite5.emarsys.net/api/v2/contact/getdata").with(:body => {'keyId' => '3', 'keyValues' => ['jane.doe@example.com'], 'fields' => []}.to_json).to_return(standard_return_body)
59
+ stub = stub_request(:post, "https://api.emarsys.net/api/v2/contact/getdata").with(:body => {'keyId' => '3', 'keyValues' => ['jane.doe@example.com'], 'fields' => []}.to_json).to_return(standard_return_body)
60
60
  Emarsys::Contact.search('3', ['jane.doe@example.com'])
61
- stub.should have_been_requested.once
61
+ expect(stub).to have_been_requested.once
62
62
  end
63
63
  end
64
64
 
65
65
  describe ".export_registrations" do
66
66
  it "requests contact data export based on parameters" do
67
67
  stub_params = {distribution_method: 'local', time_range: ["2013-01-01","2013-12-31"], contact_fields: [1,2,3]}
68
- stub = stub_request(:post, "https://suite5.emarsys.net/api/v2/contact/getregistrations").with(:body => stub_params.to_json).to_return(standard_return_body)
68
+ stub = stub_request(:post, "https://api.emarsys.net/api/v2/contact/getregistrations").with(:body => stub_params.to_json).to_return(standard_return_body)
69
69
  Emarsys::Contact.export_registrations(stub_params)
70
- stub.should have_been_requested.once
70
+ expect(stub).to have_been_requested.once
71
71
  end
72
72
  end
73
73
 
@@ -76,4 +76,4 @@ describe Emarsys::Contact do
76
76
  def contact_history(contact_ids_array)
77
77
  post "contact/getcontacthistory", {'contacts' => contact_ids_array}
78
78
  end
79
- end
79
+ end
@@ -3,7 +3,9 @@ require 'spec_helper'
3
3
  describe Emarsys::EmailCategory do
4
4
  describe ".collection" do
5
5
  it "requests all email_categories" do
6
- stub_get("emailcategory") { Emarsys::EmailCategory.collection }.should have_been_requested.once
6
+ expect(
7
+ stub_get("emailcategory") { Emarsys::EmailCategory.collection }
8
+ ).to have_been_requested.once
7
9
  end
8
10
  end
9
- end
11
+ end