emarsys 0.2.3 → 0.3.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.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +32 -0
 - data/README.md +42 -38
 - data/lib/emarsys/client.rb +11 -5
 - data/lib/emarsys/configuration.rb +54 -0
 - data/lib/emarsys/data_object.rb +16 -23
 - data/lib/emarsys/data_objects/condition.rb +2 -2
 - data/lib/emarsys/data_objects/contact.rb +27 -25
 - data/lib/emarsys/data_objects/contact_list.rb +8 -8
 - data/lib/emarsys/data_objects/email.rb +19 -19
 - data/lib/emarsys/data_objects/email_category.rb +2 -2
 - data/lib/emarsys/data_objects/event.rb +8 -8
 - data/lib/emarsys/data_objects/export.rb +4 -4
 - data/lib/emarsys/data_objects/field.rb +5 -5
 - data/lib/emarsys/data_objects/file.rb +8 -8
 - data/lib/emarsys/data_objects/folder.rb +2 -2
 - data/lib/emarsys/data_objects/form.rb +2 -2
 - data/lib/emarsys/data_objects/language.rb +2 -2
 - data/lib/emarsys/data_objects/segment.rb +2 -2
 - data/lib/emarsys/data_objects/source.rb +6 -6
 - data/lib/emarsys/error.rb +4 -0
 - data/lib/emarsys/request.rb +9 -8
 - data/lib/emarsys/response.rb +9 -11
 - data/lib/emarsys/version.rb +1 -1
 - data/lib/emarsys.rb +6 -18
 - data/spec/emarsys/client_spec.rb +13 -9
 - data/spec/emarsys/configuration_spec.rb +22 -0
 - data/spec/emarsys/data_object_spec.rb +11 -11
 - data/spec/emarsys/data_objects/contact_spec.rb +12 -12
 - data/spec/emarsys/data_objects/email_launch_status_spec.rb +1 -1
 - data/spec/emarsys/data_objects/email_spec.rb +5 -5
 - data/spec/emarsys/data_objects/email_status_code_spec.rb +1 -1
 - data/spec/emarsys/data_objects/event_spec.rb +3 -3
 - data/spec/emarsys/data_objects/field_spec.rb +1 -1
 - data/spec/emarsys/data_objects/file_spec.rb +5 -5
 - data/spec/emarsys/data_objects/folder_spec.rb +1 -1
 - data/spec/emarsys/data_objects/source_spec.rb +1 -1
 - data/spec/emarsys/request_spec.rb +1 -1
 - data/spec/emarsys/response_spec.rb +17 -12
 - data/spec/emarsys_spec.rb +1 -7
 - data/spec/spec_helper.rb +1 -0
 - metadata +6 -2
 
| 
         @@ -13,13 +13,13 @@ module Emarsys 
     | 
|
| 
       13 
13 
     | 
    
         
             
                  # @return [Hash] List of events
         
     | 
| 
       14 
14 
     | 
    
         
             
                  # @example
         
     | 
| 
       15 
15 
     | 
    
         
             
                  #   Emarsys::Event.collection
         
     | 
| 
       16 
     | 
    
         
            -
                  def collection
         
     | 
| 
       17 
     | 
    
         
            -
                    get 'event', {}
         
     | 
| 
      
 16 
     | 
    
         
            +
                  def collection(account: nil)
         
     | 
| 
      
 17 
     | 
    
         
            +
                    get account, 'event', {}
         
     | 
| 
       18 
18 
     | 
    
         
             
                  end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                  # Trigger an external event
         
     | 
| 
       21 
21 
     | 
    
         
             
                  #
         
     | 
| 
       22 
     | 
    
         
            -
                  # @param  
     | 
| 
      
 22 
     | 
    
         
            +
                  # @param id [Integer, String] The internal emarsys id
         
     | 
| 
       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
         
     | 
| 
         @@ -27,27 +27,27 @@ module Emarsys 
     | 
|
| 
       27 
27 
     | 
    
         
             
                  # @example
         
     | 
| 
       28 
28 
     | 
    
         
             
                  #   Emarsys::Event.trigger(2, 3, 'test@example.com')
         
     | 
| 
       29 
29 
     | 
    
         
             
                  #   Emarsys::Event.trigger(2, 'user_id', 57687, {:global => {:name => "Special Name"}})
         
     | 
| 
       30 
     | 
    
         
            -
                  def trigger( 
     | 
| 
      
 30 
     | 
    
         
            +
                  def trigger(id, key_id:, external_id:, data: {}, account: nil)
         
     | 
| 
       31 
31 
     | 
    
         
             
                    transformed_key_id = transform_key_id(key_id)
         
     | 
| 
       32 
32 
     | 
    
         
             
                    params = {:key_id => transformed_key_id, :external_id => external_id}
         
     | 
| 
       33 
33 
     | 
    
         
             
                    params.merge!(:data => data) if not data.empty?
         
     | 
| 
       34 
     | 
    
         
            -
                    post "event/#{ 
     | 
| 
      
 34 
     | 
    
         
            +
                    post account, "event/#{id}/trigger", params
         
     | 
| 
       35 
35 
     | 
    
         
             
                  end
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
37 
     | 
    
         
             
                  # Trigger an external event for multiple contacts
         
     | 
| 
       38 
38 
     | 
    
         
             
                  #
         
     | 
| 
       39 
     | 
    
         
            -
                  # @param  
     | 
| 
      
 39 
     | 
    
         
            +
                  # @param id [Integer, String] The internal emarsys id
         
     | 
| 
       40 
40 
     | 
    
         
             
                  # @param key_id [Integer, String] The identifer of the key field (e.g. 3 for 'email')
         
     | 
| 
       41 
41 
     | 
    
         
             
                  # @param contacts [Array, Hash] An array with hashes containing the contacts and optional data per contact
         
     | 
| 
       42 
42 
     | 
    
         
             
                  # @return [Hash] Result data
         
     | 
| 
       43 
43 
     | 
    
         
             
                  # @example
         
     | 
| 
       44 
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( 
     | 
| 
      
 45 
     | 
    
         
            +
                  def trigger_multiple(id, key_id:, contacts:, account: nil)
         
     | 
| 
       46 
46 
     | 
    
         
             
                    external_id = ""
         
     | 
| 
       47 
47 
     | 
    
         
             
                    transformed_key_id = transform_key_id(key_id)
         
     | 
| 
       48 
48 
     | 
    
         
             
                    params = {:key_id => transformed_key_id, :external_id => external_id, :data => nil}
         
     | 
| 
       49 
49 
     | 
    
         
             
                    params.merge!(:contacts => contacts)
         
     | 
| 
       50 
     | 
    
         
            -
                    post "event/#{ 
     | 
| 
      
 50 
     | 
    
         
            +
                    post account, "event/#{id}/trigger", params
         
     | 
| 
       51 
51 
     | 
    
         
             
                  end
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
       53 
53 
     | 
    
         
             
                  # @private
         
     | 
| 
         @@ -13,8 +13,8 @@ module Emarsys 
     | 
|
| 
       13 
13 
     | 
    
         
             
                  # @return [Hash] Result data
         
     | 
| 
       14 
14 
     | 
    
         
             
                  # @example
         
     | 
| 
       15 
15 
     | 
    
         
             
                  #   Emarsys::Export.resource(2)
         
     | 
| 
       16 
     | 
    
         
            -
                  def resource(id)
         
     | 
| 
       17 
     | 
    
         
            -
                    get "export/#{id}", {}
         
     | 
| 
      
 16 
     | 
    
         
            +
                  def resource(id, account: nil)
         
     | 
| 
      
 17 
     | 
    
         
            +
                    get account, "export/#{id}", {}
         
     | 
| 
       18 
18 
     | 
    
         
             
                  end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                  # Download export data
         
     | 
| 
         @@ -25,11 +25,11 @@ module Emarsys 
     | 
|
| 
       25 
25 
     | 
    
         
             
                  # @return [String] text/csv
         
     | 
| 
       26 
26 
     | 
    
         
             
                  # @example
         
     | 
| 
       27 
27 
     | 
    
         
             
                  #   Emarsys::Export.data(2)
         
     | 
| 
       28 
     | 
    
         
            -
                  def data(id, offset  
     | 
| 
      
 28 
     | 
    
         
            +
                  def data(id, offset: nil, limit: nil, account: nil)
         
     | 
| 
       29 
29 
     | 
    
         
             
                    params = {}
         
     | 
| 
       30 
30 
     | 
    
         
             
                    params.merge!(:offset => offset) if offset
         
     | 
| 
       31 
31 
     | 
    
         
             
                    params.merge!(:limit => limit) if limit
         
     | 
| 
       32 
     | 
    
         
            -
                    get "export/#{id}/data", params
         
     | 
| 
      
 32 
     | 
    
         
            +
                    get account, "export/#{id}/data", params
         
     | 
| 
       33 
33 
     | 
    
         
             
                  end
         
     | 
| 
       34 
34 
     | 
    
         
             
                end
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
         @@ -15,12 +15,12 @@ module Emarsys 
     | 
|
| 
       15 
15 
     | 
    
         
             
                  # @example
         
     | 
| 
       16 
16 
     | 
    
         
             
                  #   Emarsys::Field.collection
         
     | 
| 
       17 
17 
     | 
    
         
             
                  #   Emarsys::Field.collection(:translate => 'en')
         
     | 
| 
       18 
     | 
    
         
            -
                  def collection( 
     | 
| 
      
 18 
     | 
    
         
            +
                  def collection(account: nil, **params)
         
     | 
| 
       19 
19 
     | 
    
         
             
                    params = params.stringify_keys
         
     | 
| 
       20 
20 
     | 
    
         
             
                    if params['translate']
         
     | 
| 
       21 
     | 
    
         
            -
                      get "field/translate/#{params['translate'].to_s}", {}
         
     | 
| 
      
 21 
     | 
    
         
            +
                      get account, "field/translate/#{params['translate'].to_s}", {}
         
     | 
| 
       22 
22 
     | 
    
         
             
                    else
         
     | 
| 
       23 
     | 
    
         
            -
                      get 'field', {}
         
     | 
| 
      
 23 
     | 
    
         
            +
                      get account, 'field', {}
         
     | 
| 
       24 
24 
     | 
    
         
             
                    end
         
     | 
| 
       25 
25 
     | 
    
         
             
                  end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
         @@ -30,8 +30,8 @@ module Emarsys 
     | 
|
| 
       30 
30 
     | 
    
         
             
                  # @return [Hash] Result Data
         
     | 
| 
       31 
31 
     | 
    
         
             
                  # @example
         
     | 
| 
       32 
32 
     | 
    
         
             
                  #   Emarsys::Field.choice(3)
         
     | 
| 
       33 
     | 
    
         
            -
                  def choice(id)
         
     | 
| 
       34 
     | 
    
         
            -
                    get "field/#{id}/choice", {}
         
     | 
| 
      
 33 
     | 
    
         
            +
                  def choice(id, account: nil)
         
     | 
| 
      
 34 
     | 
    
         
            +
                    get account, "field/#{id}/choice", {}
         
     | 
| 
       35 
35 
     | 
    
         
             
                  end
         
     | 
| 
       36 
36 
     | 
    
         
             
                end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
         @@ -15,23 +15,23 @@ module Emarsys 
     | 
|
| 
       15 
15 
     | 
    
         
             
                  # @example
         
     | 
| 
       16 
16 
     | 
    
         
             
                  #   Emarsys::File.collection
         
     | 
| 
       17 
17 
     | 
    
         
             
                  #   Emarsys::File.collection(:folder => 3)
         
     | 
| 
       18 
     | 
    
         
            -
                  def collection( 
     | 
| 
       19 
     | 
    
         
            -
                    get 'file', params
         
     | 
| 
      
 18 
     | 
    
         
            +
                  def collection(account: nil, **params)
         
     | 
| 
      
 19 
     | 
    
         
            +
                    get account, 'file', params
         
     | 
| 
       20 
20 
     | 
    
         
             
                  end
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
                  # Upload a file to the media database
         
     | 
| 
       23 
23 
     | 
    
         
             
                  #
         
     | 
| 
       24 
24 
     | 
    
         
             
                  # @param filename [String] The filename
         
     | 
| 
       25 
     | 
    
         
            -
                  # @param  
     | 
| 
       26 
     | 
    
         
            -
                  # @param  
     | 
| 
      
 25 
     | 
    
         
            +
                  # @param file [String] Base64 encoded version of the file
         
     | 
| 
      
 26 
     | 
    
         
            +
                  # @param folder [Integer, String] optinal folder to out te file into
         
     | 
| 
       27 
27 
     | 
    
         
             
                  # @return [Hash] Result data
         
     | 
| 
       28 
28 
     | 
    
         
             
                  # @example
         
     | 
| 
       29 
29 
     | 
    
         
             
                  #   Emarsys::File.create("my_file.jpg", "asdhkajsh...")
         
     | 
| 
       30 
30 
     | 
    
         
             
                  #   Emarsys::File.create("my_file.jpg", "asdhkajsh...", 3)
         
     | 
| 
       31 
     | 
    
         
            -
                  def create(filename 
     | 
| 
       32 
     | 
    
         
            -
                    params = {:filename => filename, :file =>  
     | 
| 
       33 
     | 
    
         
            -
                    params.merge!( 
     | 
| 
       34 
     | 
    
         
            -
                    post 'file', params
         
     | 
| 
      
 31 
     | 
    
         
            +
                  def create(filename:, file:, folder: nil, account: nil)
         
     | 
| 
      
 32 
     | 
    
         
            +
                    params = {:filename => filename, :file => file}
         
     | 
| 
      
 33 
     | 
    
         
            +
                    params.merge!(:folder => folder) unless folder.nil?
         
     | 
| 
      
 34 
     | 
    
         
            +
                    post account, 'file', params
         
     | 
| 
       35 
35 
     | 
    
         
             
                  end
         
     | 
| 
       36 
36 
     | 
    
         
             
                end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
         @@ -12,8 +12,8 @@ module Emarsys 
     | 
|
| 
       12 
12 
     | 
    
         
             
                  # @return [Hash] List of sources
         
     | 
| 
       13 
13 
     | 
    
         
             
                  # @example
         
     | 
| 
       14 
14 
     | 
    
         
             
                  #   Emarsys::Source.collection
         
     | 
| 
       15 
     | 
    
         
            -
                  def collection
         
     | 
| 
       16 
     | 
    
         
            -
                    get 'source', {}
         
     | 
| 
      
 15 
     | 
    
         
            +
                  def collection(account: nil)
         
     | 
| 
      
 16 
     | 
    
         
            +
                    get account, 'source', {}
         
     | 
| 
       17 
17 
     | 
    
         
             
                  end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                  # Create a new source
         
     | 
| 
         @@ -22,8 +22,8 @@ module Emarsys 
     | 
|
| 
       22 
22 
     | 
    
         
             
                  # @return [Hash] Result data
         
     | 
| 
       23 
23 
     | 
    
         
             
                  # @example
         
     | 
| 
       24 
24 
     | 
    
         
             
                  #   Emarsys::Source.create("My new source")
         
     | 
| 
       25 
     | 
    
         
            -
                  def create(name)
         
     | 
| 
       26 
     | 
    
         
            -
                    post 'source/create', {:name => name}
         
     | 
| 
      
 25 
     | 
    
         
            +
                  def create(name:, account: nil)
         
     | 
| 
      
 26 
     | 
    
         
            +
                    post account, 'source/create', {:name => name}
         
     | 
| 
       27 
27 
     | 
    
         
             
                  end
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
29 
     | 
    
         
             
                  # Destroy a specific source
         
     | 
| 
         @@ -32,8 +32,8 @@ module Emarsys 
     | 
|
| 
       32 
32 
     | 
    
         
             
                  # @return [Hash] Result data
         
     | 
| 
       33 
33 
     | 
    
         
             
                  # @example
         
     | 
| 
       34 
34 
     | 
    
         
             
                  #   Emarsys::Source.destroy(2)
         
     | 
| 
       35 
     | 
    
         
            -
                  def destroy(id)
         
     | 
| 
       36 
     | 
    
         
            -
                    delete "source/#{id}", {}
         
     | 
| 
      
 35 
     | 
    
         
            +
                  def destroy(id, account: nil)
         
     | 
| 
      
 36 
     | 
    
         
            +
                    delete account, "source/#{id}", {}
         
     | 
| 
       37 
37 
     | 
    
         
             
                  end
         
     | 
| 
       38 
38 
     | 
    
         | 
| 
       39 
39 
     | 
    
         
             
                end
         
     | 
    
        data/lib/emarsys/error.rb
    CHANGED
    
    
    
        data/lib/emarsys/request.rb
    CHANGED
    
    | 
         @@ -2,41 +2,42 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            module Emarsys
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
              class Request
         
     | 
| 
       5 
     | 
    
         
            -
                attr_accessor :http_verb, :path, :params
         
     | 
| 
      
 5 
     | 
    
         
            +
                attr_accessor :http_verb, :path, :params, :account
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
                def initialize(http_verb, path, params = {})
         
     | 
| 
      
 7 
     | 
    
         
            +
                def initialize(account, http_verb, path, params = {})
         
     | 
| 
       8 
8 
     | 
    
         
             
                  self.path = path
         
     | 
| 
       9 
9 
     | 
    
         
             
                  self.http_verb = http_verb
         
     | 
| 
       10 
10 
     | 
    
         
             
                  self.params = params
         
     | 
| 
      
 11 
     | 
    
         
            +
                  self.account = account
         
     | 
| 
       11 
12 
     | 
    
         
             
                end
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
       13 
14 
     | 
    
         
             
                def send_request
         
     | 
| 
       14 
15 
     | 
    
         
             
                  case http_verb.to_sym
         
     | 
| 
       15 
16 
     | 
    
         
             
                  when :post
         
     | 
| 
       16 
17 
     | 
    
         
             
                    RestClient.post(emarsys_uri, converted_params.to_json, :content_type => :json, :x_wsse => client.x_wsse_string) do |response, request, result, &block|
         
     | 
| 
       17 
     | 
    
         
            -
                      Emarsys::Response.new(response) 
     | 
| 
      
 18 
     | 
    
         
            +
                      Emarsys::Response.new(response)
         
     | 
| 
       18 
19 
     | 
    
         
             
                    end
         
     | 
| 
       19 
20 
     | 
    
         
             
                  when :put
         
     | 
| 
       20 
21 
     | 
    
         
             
                    RestClient.put emarsys_uri, converted_params.to_json, :content_type => :json, :x_wsse => client.x_wsse_string do |response, request, result, &block|
         
     | 
| 
       21 
     | 
    
         
            -
                      Emarsys::Response.new(response) 
     | 
| 
      
 22 
     | 
    
         
            +
                      Emarsys::Response.new(response)
         
     | 
| 
       22 
23 
     | 
    
         
             
                    end
         
     | 
| 
       23 
24 
     | 
    
         
             
                  when :delete
         
     | 
| 
       24 
25 
     | 
    
         
             
                    RestClient.delete(emarsys_uri, :content_type => :json, :x_wsse => client.x_wsse_string) do |response, request, result, &block|
         
     | 
| 
       25 
     | 
    
         
            -
                      Emarsys::Response.new(response) 
     | 
| 
      
 26 
     | 
    
         
            +
                      Emarsys::Response.new(response)
         
     | 
| 
       26 
27 
     | 
    
         
             
                    end
         
     | 
| 
       27 
28 
     | 
    
         
             
                  else
         
     | 
| 
       28 
29 
     | 
    
         
             
                    RestClient.get(emarsys_uri, :content_type => :json, :x_wsse => client.x_wsse_string) do |response, request, result, &block|
         
     | 
| 
       29 
     | 
    
         
            -
                      Emarsys::Response.new(response) 
     | 
| 
      
 30 
     | 
    
         
            +
                      Emarsys::Response.new(response)
         
     | 
| 
       30 
31 
     | 
    
         
             
                    end
         
     | 
| 
       31 
32 
     | 
    
         
             
                  end
         
     | 
| 
       32 
33 
     | 
    
         
             
                end
         
     | 
| 
       33 
34 
     | 
    
         | 
| 
       34 
35 
     | 
    
         
             
                def client
         
     | 
| 
       35 
     | 
    
         
            -
                  Emarsys::Client.new
         
     | 
| 
      
 36 
     | 
    
         
            +
                  Emarsys::Client.new(account)
         
     | 
| 
       36 
37 
     | 
    
         
             
                end
         
     | 
| 
       37 
38 
     | 
    
         | 
| 
       38 
39 
     | 
    
         
             
                def emarsys_uri
         
     | 
| 
       39 
     | 
    
         
            -
                  [ 
     | 
| 
      
 40 
     | 
    
         
            +
                  [client.endpoint, @path].join('/')
         
     | 
| 
       40 
41 
     | 
    
         
             
                end
         
     | 
| 
       41 
42 
     | 
    
         | 
| 
       42 
43 
     | 
    
         
             
                def converted_params
         
     | 
    
        data/lib/emarsys/response.rb
    CHANGED
    
    | 
         @@ -13,20 +13,18 @@ module Emarsys 
     | 
|
| 
       13 
13 
     | 
    
         
             
                    self.text = json['replyText']
         
     | 
| 
       14 
14 
     | 
    
         
             
                    self.data = json['data']
         
     | 
| 
       15 
15 
     | 
    
         
             
                  end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
       16 
17 
     | 
    
         
             
                  self.status = response.code if response.respond_to?(:code)
         
     | 
| 
       17 
     | 
    
         
            -
                end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                    raise Emarsys::BadRequest.new(code, text, status)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  if code != 0
         
     | 
| 
      
 20 
     | 
    
         
            +
                    if status == 401
         
     | 
| 
      
 21 
     | 
    
         
            +
                      raise Emarsys::Unauthorized.new(code, text, status)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    elsif status == 429
         
     | 
| 
      
 23 
     | 
    
         
            +
                      raise Emarsys::TooManyRequests.new(code, text, status)
         
     | 
| 
      
 24 
     | 
    
         
            +
                    else
         
     | 
| 
      
 25 
     | 
    
         
            +
                      raise Emarsys::BadRequest.new(code, text, status)
         
     | 
| 
      
 26 
     | 
    
         
            +
                    end
         
     | 
| 
       28 
27 
     | 
    
         
             
                  end
         
     | 
| 
       29 
28 
     | 
    
         
             
                end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
29 
     | 
    
         
             
              end
         
     | 
| 
       32 
30 
     | 
    
         
             
            end
         
     | 
    
        data/lib/emarsys/version.rb
    CHANGED
    
    
    
        data/lib/emarsys.rb
    CHANGED
    
    | 
         @@ -4,6 +4,7 @@ require 'json' 
     | 
|
| 
       4 
4 
     | 
    
         
             
            require 'rest_client'
         
     | 
| 
       5 
5 
     | 
    
         
             
            require 'uri'
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
      
 7 
     | 
    
         
            +
            require 'emarsys/configuration'
         
     | 
| 
       7 
8 
     | 
    
         
             
            require 'emarsys/client'
         
     | 
| 
       8 
9 
     | 
    
         
             
            require 'emarsys/country'
         
     | 
| 
       9 
10 
     | 
    
         
             
            require 'emarsys/data_object'
         
     | 
| 
         @@ -36,27 +37,14 @@ require "emarsys/version" 
     | 
|
| 
       36 
37 
     | 
    
         
             
            # Ruby toolkit for the Emarsys API
         
     | 
| 
       37 
38 
     | 
    
         
             
            module Emarsys
         
     | 
| 
       38 
39 
     | 
    
         
             
              class << self
         
     | 
| 
      
 40 
     | 
    
         
            +
                extend Forwardable
         
     | 
| 
       39 
41 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
                 
     | 
| 
       41 
     | 
    
         
            -
                #   @return [String] Base URL for emarsys URLs. default: https://api.emarsys.net/api/v2
         
     | 
| 
       42 
     | 
    
         
            -
                # @!attribute api_password
         
     | 
| 
       43 
     | 
    
         
            -
                #   @return [String] API Username given by Emarsys
         
     | 
| 
       44 
     | 
    
         
            -
                # @!attribute api_username
         
     | 
| 
       45 
     | 
    
         
            -
                #   @return [String] API Username given by Emarsys
         
     | 
| 
      
 42 
     | 
    
         
            +
                attr_accessor :allow_default_configuration
         
     | 
| 
       46 
43 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
                 
     | 
| 
      
 44 
     | 
    
         
            +
                def_delegators :configuration, :configure
         
     | 
| 
       48 
45 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
                 
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                # @return [String] domain which should be used to query the API
         
     | 
| 
       52 
     | 
    
         
            -
                def api_endpoint
         
     | 
| 
       53 
     | 
    
         
            -
                  @api_endpoint ||= 'https://api.emarsys.net/api/v2'
         
     | 
| 
      
 46 
     | 
    
         
            +
                def configuration
         
     | 
| 
      
 47 
     | 
    
         
            +
                  @configuration ||= Emarsys::Configuration
         
     | 
| 
       54 
48 
     | 
    
         
             
                end
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
                # Set configuration options using a block
         
     | 
| 
       57 
     | 
    
         
            -
                def configure
         
     | 
| 
       58 
     | 
    
         
            -
                  yield self
         
     | 
| 
       59 
     | 
    
         
            -
                end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
49 
     | 
    
         
             
              end
         
     | 
| 
       62 
50 
     | 
    
         
             
            end
         
     | 
    
        data/spec/emarsys/client_spec.rb
    CHANGED
    
    | 
         @@ -4,23 +4,27 @@ describe Emarsys::Client do 
     | 
|
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
              describe 'configs for username and password' do
         
     | 
| 
       6 
6 
     | 
    
         
             
                it 'inherits username from module' do
         
     | 
| 
       7 
     | 
    
         
            -
                  allow(Emarsys).to receive(:api_username).and_return("my_username")
         
     | 
| 
       8 
7 
     | 
    
         
             
                  expect(Emarsys::Client.new.username).to eq("my_username")
         
     | 
| 
       9 
8 
     | 
    
         
             
                end
         
     | 
| 
       10 
9 
     | 
    
         | 
| 
       11 
10 
     | 
    
         
             
                it 'inherits password from module' do
         
     | 
| 
       12 
     | 
    
         
            -
                  allow(Emarsys).to receive(:api_password).and_return("my_password")
         
     | 
| 
       13 
11 
     | 
    
         
             
                  expect(Emarsys::Client.new.password).to eq("my_password")
         
     | 
| 
       14 
12 
     | 
    
         
             
                end
         
     | 
| 
       15 
13 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                 
     | 
| 
       17 
     | 
    
         
            -
                   
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
                context 'missing values' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 16 
     | 
    
         
            +
                    Emarsys.configure do |config|
         
     | 
| 
      
 17 
     | 
    
         
            +
                      config.api_username = nil
         
     | 
| 
      
 18 
     | 
    
         
            +
                      config.api_password = nil
         
     | 
| 
      
 19 
     | 
    
         
            +
                    end
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
                  it 'raises error if api_username is not set' do
         
     | 
| 
      
 22 
     | 
    
         
            +
                    expect{Emarsys::Client.new.username}.to raise_error(ArgumentError, 'api_username is not set')
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
       20 
24 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                   
     | 
| 
      
 25 
     | 
    
         
            +
                  it 'raises error if api_password is not set' do
         
     | 
| 
      
 26 
     | 
    
         
            +
                    expect{Emarsys::Client.new.password}.to raise_error(ArgumentError, 'api_password is not set')
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
       24 
28 
     | 
    
         
             
                end
         
     | 
| 
       25 
29 
     | 
    
         
             
              end
         
     | 
| 
       26 
30 
     | 
    
         | 
| 
         @@ -0,0 +1,22 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Emarsys::Configuration do
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              describe ".configure" do
         
     | 
| 
      
 6 
     | 
    
         
            +
                [:api_endpoint, :api_username, :api_password].each do |key|
         
     | 
| 
      
 7 
     | 
    
         
            +
                  it "sets the #{key.to_s.gsub('_', ' ')}" do
         
     | 
| 
      
 8 
     | 
    
         
            +
                    Emarsys::Configuration.configure(account: :foo) do |config|
         
     | 
| 
      
 9 
     | 
    
         
            +
                      config.send("#{key}=", key)
         
     | 
| 
      
 10 
     | 
    
         
            +
                    end
         
     | 
| 
      
 11 
     | 
    
         
            +
                    expect(Emarsys::Configuration.for(:foo).__send__(key)).to eq key
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              describe ".api_endpoint getter" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                it "returns specific url as default value" do
         
     | 
| 
      
 18 
     | 
    
         
            +
                  Emarsys.configure { |c| c.api_endpoint = nil }
         
     | 
| 
      
 19 
     | 
    
         
            +
                  expect(Emarsys::Configuration.for(nil).api_endpoint).to eq('https://api.emarsys.net/api/v2')
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -5,34 +5,34 @@ describe Emarsys::DataObject do 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
                describe '.get' do
         
     | 
| 
       7 
7 
     | 
    
         
             
                  it "delegates to the instance request method" do
         
     | 
| 
       8 
     | 
    
         
            -
                    allow_any_instance_of(Emarsys::DataObject).to receive(:request).with('get', 'test_method', {}).and_return(nil)
         
     | 
| 
       9 
     | 
    
         
            -
                    Emarsys::DataObject.get('test_method', {})
         
     | 
| 
      
 8 
     | 
    
         
            +
                    allow_any_instance_of(Emarsys::DataObject).to receive(:request).with(nil, 'get', 'test_method', {}).and_return(nil)
         
     | 
| 
      
 9 
     | 
    
         
            +
                    Emarsys::DataObject.get(nil, 'test_method', {})
         
     | 
| 
       10 
10 
     | 
    
         
             
                  end
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
                  it "transfers params to specific emarsys params format" do
         
     | 
| 
       13 
     | 
    
         
            -
                    allow_any_instance_of(Emarsys::DataObject).to receive(:request).with('get', 'test_method/?a=1&b=2', {}).and_return(nil)
         
     | 
| 
       14 
     | 
    
         
            -
                    Emarsys::DataObject.get('test_method', {'a' => 1, 'b' => 2})
         
     | 
| 
      
 13 
     | 
    
         
            +
                    allow_any_instance_of(Emarsys::DataObject).to receive(:request).with(nil, 'get', 'test_method/?a=1&b=2', {}).and_return(nil)
         
     | 
| 
      
 14 
     | 
    
         
            +
                    Emarsys::DataObject.get(nil, '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 
     | 
    
         
            -
                    allow_any_instance_of(Emarsys::DataObject).to receive(:request).with('post', 'test_method', {}).and_return(nil)
         
     | 
| 
       21 
     | 
    
         
            -
                    Emarsys::DataObject.post('test_method', {})
         
     | 
| 
      
 20 
     | 
    
         
            +
                    allow_any_instance_of(Emarsys::DataObject).to receive(:request).with(nil, 'post', 'test_method', {}).and_return(nil)
         
     | 
| 
      
 21 
     | 
    
         
            +
                    Emarsys::DataObject.post(nil, '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 
     | 
    
         
            -
                    allow_any_instance_of(Emarsys::DataObject).to receive(:request).with('put', 'test_method', {}).and_return(nil)
         
     | 
| 
       28 
     | 
    
         
            -
                    Emarsys::DataObject.put('test_method', {})
         
     | 
| 
      
 27 
     | 
    
         
            +
                    allow_any_instance_of(Emarsys::DataObject).to receive(:request).with(nil, 'put', 'test_method', {}).and_return(nil)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    Emarsys::DataObject.put(nil, '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 
     | 
    
         
            -
                    allow_any_instance_of(Emarsys::DataObject).to receive(:request).with('delete', 'test_method', {}).and_return(nil)
         
     | 
| 
       35 
     | 
    
         
            -
                    Emarsys::DataObject.delete('test_method', {})
         
     | 
| 
      
 34 
     | 
    
         
            +
                    allow_any_instance_of(Emarsys::DataObject).to receive(:request).with(nil, 'delete', 'test_method', {}).and_return(nil)
         
     | 
| 
      
 35 
     | 
    
         
            +
                    Emarsys::DataObject.delete(nil, 'test_method', {})
         
     | 
| 
       36 
36 
     | 
    
         
             
                  end
         
     | 
| 
       37 
37 
     | 
    
         
             
                end
         
     | 
| 
       38 
38 
     | 
    
         | 
| 
         @@ -54,7 +54,7 @@ describe Emarsys::DataObject do 
     | 
|
| 
       54 
54 
     | 
    
         | 
| 
       55 
55 
     | 
    
         
             
                it "provides a simple #request that delegates to Emarsys::Request" do
         
     | 
| 
       56 
56 
     | 
    
         
             
                  allow_any_instance_of(Emarsys::Request).to receive(:send_request).and_return(nil)
         
     | 
| 
       57 
     | 
    
         
            -
                  data_object.request('get', 'test_method', {})
         
     | 
| 
      
 57 
     | 
    
         
            +
                  data_object.request(nil, 'get', 'test_method', {})
         
     | 
| 
       58 
58 
     | 
    
         
             
                end
         
     | 
| 
       59 
59 
     | 
    
         
             
              end
         
     | 
| 
       60 
60 
     | 
    
         
             
            end
         
     | 
| 
         @@ -5,7 +5,7 @@ describe Emarsys::Contact do 
     | 
|
| 
       5 
5 
     | 
    
         
             
                it "requests contact creation with parameters" do
         
     | 
| 
       6 
6 
     | 
    
         
             
                  stub_params = {1 => 'John', 2 => "Doe"}
         
     | 
| 
       7 
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 
     | 
    
         
            -
                  Emarsys::Contact.create(3, "john.doe@example.com", stub_params)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  Emarsys::Contact.create(key_id: 3, key_value: "john.doe@example.com", params: stub_params)
         
     | 
| 
       9 
9 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       10 
10 
     | 
    
         
             
                end
         
     | 
| 
       11 
11 
     | 
    
         
             
              end
         
     | 
| 
         @@ -13,7 +13,7 @@ describe Emarsys::Contact do 
     | 
|
| 
       13 
13 
     | 
    
         
             
              describe ".emarsys_id" do
         
     | 
| 
       14 
14 
     | 
    
         
             
                it "requests emarsys_id of a contact" do
         
     | 
| 
       15 
15 
     | 
    
         
             
                  stub = stub_request(:get, "https://api.emarsys.net/api/v2/contact/?3=jane.doe@example.com").to_return(standard_return_body)
         
     | 
| 
       16 
     | 
    
         
            -
                  Emarsys::Contact.emarsys_id(3, 'jane.doe@example.com')
         
     | 
| 
      
 16 
     | 
    
         
            +
                  Emarsys::Contact.emarsys_id(key_id: 3, key_value: 'jane.doe@example.com')
         
     | 
| 
       17 
17 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       18 
18 
     | 
    
         
             
                end
         
     | 
| 
       19 
19 
     | 
    
         
             
              end
         
     | 
| 
         @@ -22,13 +22,13 @@ describe Emarsys::Contact do 
     | 
|
| 
       22 
22 
     | 
    
         
             
                it "requests contact update with parameters" do
         
     | 
| 
       23 
23 
     | 
    
         
             
                  stub_params = {1 => 'Jane', 2 => "Doe"}
         
     | 
| 
       24 
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 
     | 
    
         
            -
                  Emarsys::Contact.update(3, 'jane.doe@example.com', stub_params)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  Emarsys::Contact.update(key_id: 3, key_value: 'jane.doe@example.com', params: stub_params)
         
     | 
| 
       26 
26 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       27 
27 
     | 
    
         
             
                end
         
     | 
| 
       28 
28 
     | 
    
         
             
                it "may create non-existing contact" do
         
     | 
| 
       29 
29 
     | 
    
         
             
                  stub_params = {1 => 'Jane', 2 => "Doe"}
         
     | 
| 
       30 
30 
     | 
    
         
             
                  stub = stub_request(:put, "https://api.emarsys.net/api/v2/contact/?create_if_not_exists=1").with(:body => stub_params.merge!({'key_id' => 3, 3 => 'jane.doe@example.com'}).to_json).to_return(standard_return_body)
         
     | 
| 
       31 
     | 
    
         
            -
                  Emarsys::Contact.update(3, 'jane.doe@example.com', stub_params, true)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  Emarsys::Contact.update(key_id: 3, key_value: 'jane.doe@example.com', params: stub_params, create_if_not_exists: true)
         
     | 
| 
       32 
32 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       33 
33 
     | 
    
         
             
                end
         
     | 
| 
       34 
34 
     | 
    
         
             
              end
         
     | 
| 
         @@ -37,14 +37,14 @@ describe Emarsys::Contact do 
     | 
|
| 
       37 
37 
     | 
    
         
             
                it "requests contact batch creation with parameters" do
         
     | 
| 
       38 
38 
     | 
    
         
             
                  stub_params = [{1 => 'Jane', 2 => "Doe"}, {1 => 'Paul', 2 => 'Tester'}]
         
     | 
| 
       39 
39 
     | 
    
         
             
                  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)
         
     | 
| 
       40 
     | 
    
         
            -
                  Emarsys::Contact.create_batch(3, stub_params)
         
     | 
| 
      
 40 
     | 
    
         
            +
                  Emarsys::Contact.create_batch(key_id: 3, params: stub_params)
         
     | 
| 
       41 
41 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       42 
42 
     | 
    
         
             
                end
         
     | 
| 
       43 
43 
     | 
    
         
             
                it "transforms identifiers to IDs for each contact parameter set" do
         
     | 
| 
       44 
44 
     | 
    
         
             
                  given_params = [{'_firstname' => 'Jane', '_lastname' => "Doe"}, {'_firstname' => 'Paul', '_lastname' => 'Tester'}]
         
     | 
| 
       45 
45 
     | 
    
         
             
                  expected_params = [{1 => 'Jane', 2 => "Doe"}, {1 => 'Paul', 2 => 'Tester'}]
         
     | 
| 
       46 
46 
     | 
    
         
             
                  stub = stub_request(:post, "https://api.emarsys.net/api/v2/contact").with(:body => {'key_id' => 3, 'contacts' => expected_params}.to_json).to_return(standard_return_body)
         
     | 
| 
       47 
     | 
    
         
            -
                  Emarsys::Contact.create_batch('_email', given_params)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  Emarsys::Contact.create_batch(key_id: '_email', params: given_params)
         
     | 
| 
       48 
48 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       49 
49 
     | 
    
         
             
                end
         
     | 
| 
       50 
50 
     | 
    
         
             
              end
         
     | 
| 
         @@ -53,20 +53,20 @@ describe Emarsys::Contact do 
     | 
|
| 
       53 
53 
     | 
    
         
             
                it "requests contact batch update with parameters" do
         
     | 
| 
       54 
54 
     | 
    
         
             
                  stub_params = [{1 => 'Jane', 2 => "Doe"}, {1 => 'Paul', 2 => 'Tester'}]
         
     | 
| 
       55 
55 
     | 
    
         
             
                  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)
         
     | 
| 
       56 
     | 
    
         
            -
                  Emarsys::Contact.update_batch(3, stub_params)
         
     | 
| 
      
 56 
     | 
    
         
            +
                  Emarsys::Contact.update_batch(key_id: 3, params: stub_params)
         
     | 
| 
       57 
57 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       58 
58 
     | 
    
         
             
                end
         
     | 
| 
       59 
59 
     | 
    
         
             
                it "transforms identifiers to IDs for each contact parameter set" do
         
     | 
| 
       60 
60 
     | 
    
         
             
                  given_params = [{'_firstname' => 'Jane', '_lastname' => "Doe"}, {'_firstname' => 'Paul', '_lastname' => 'Tester'}]
         
     | 
| 
       61 
61 
     | 
    
         
             
                  expected_params = [{1 => 'Jane', 2 => "Doe"}, {1 => 'Paul', 2 => 'Tester'}]
         
     | 
| 
       62 
62 
     | 
    
         
             
                  stub = stub_request(:put, "https://api.emarsys.net/api/v2/contact").with(:body => {'key_id' => 3, 'contacts' => expected_params}.to_json).to_return(standard_return_body)
         
     | 
| 
       63 
     | 
    
         
            -
                  Emarsys::Contact.update_batch('_email', given_params)
         
     | 
| 
      
 63 
     | 
    
         
            +
                  Emarsys::Contact.update_batch(key_id: '_email', params: given_params)
         
     | 
| 
       64 
64 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       65 
65 
     | 
    
         
             
                end
         
     | 
| 
       66 
66 
     | 
    
         
             
                it "may create non-existing contacts" do
         
     | 
| 
       67 
67 
     | 
    
         
             
                  stub_params = [{1 => 'Jane', 2 => "Doe"}, {1 => 'Paul', 2 => 'Tester'}]
         
     | 
| 
       68 
68 
     | 
    
         
             
                  stub = stub_request(:put, "https://api.emarsys.net/api/v2/contact/?create_if_not_exists=1").with(:body => {'key_id' => 3, 'contacts' => stub_params}.to_json).to_return(standard_return_body)
         
     | 
| 
       69 
     | 
    
         
            -
                  Emarsys::Contact.update_batch(3, stub_params, true)
         
     | 
| 
      
 69 
     | 
    
         
            +
                  Emarsys::Contact.update_batch(key_id: 3, params: stub_params, create_if_not_exists: true)
         
     | 
| 
       70 
70 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       71 
71 
     | 
    
         
             
                end
         
     | 
| 
       72 
72 
     | 
    
         
             
              end
         
     | 
| 
         @@ -75,7 +75,7 @@ describe Emarsys::Contact do 
     | 
|
| 
       75 
75 
     | 
    
         
             
                it "requests contact histories" do
         
     | 
| 
       76 
76 
     | 
    
         
             
                  stub_params = [1,2,3]
         
     | 
| 
       77 
77 
     | 
    
         
             
                  stub = stub_request(:post, "https://api.emarsys.net/api/v2/contact/getcontacthistory").with(:body => {'contacts' => stub_params}.to_json).to_return(standard_return_body)
         
     | 
| 
       78 
     | 
    
         
            -
                  Emarsys::Contact.contact_history(stub_params)
         
     | 
| 
      
 78 
     | 
    
         
            +
                  Emarsys::Contact.contact_history(contacts: stub_params)
         
     | 
| 
       79 
79 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       80 
80 
     | 
    
         
             
                end
         
     | 
| 
       81 
81 
     | 
    
         
             
              end
         
     | 
| 
         @@ -83,7 +83,7 @@ describe Emarsys::Contact do 
     | 
|
| 
       83 
83 
     | 
    
         
             
              describe ".search" do
         
     | 
| 
       84 
84 
     | 
    
         
             
                it "requests contact data based on search params" do
         
     | 
| 
       85 
85 
     | 
    
         
             
                  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)
         
     | 
| 
       86 
     | 
    
         
            -
                  Emarsys::Contact.search('3', ['jane.doe@example.com'])
         
     | 
| 
      
 86 
     | 
    
         
            +
                  Emarsys::Contact.search(key_id: '3', key_values: ['jane.doe@example.com'])
         
     | 
| 
       87 
87 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       88 
88 
     | 
    
         
             
                end
         
     | 
| 
       89 
89 
     | 
    
         
             
              end
         
     | 
| 
         @@ -100,6 +100,6 @@ describe Emarsys::Contact do 
     | 
|
| 
       100 
100 
     | 
    
         | 
| 
       101 
101 
     | 
    
         | 
| 
       102 
102 
     | 
    
         
             
              def contact_history(contact_ids_array)
         
     | 
| 
       103 
     | 
    
         
            -
                post "contact/getcontacthistory", {'contacts' => contact_ids_array}
         
     | 
| 
      
 103 
     | 
    
         
            +
                post account, "contact/getcontacthistory", {'contacts' => contact_ids_array}
         
     | 
| 
       104 
104 
     | 
    
         
             
              end
         
     | 
| 
       105 
105 
     | 
    
         
             
            end
         
     | 
| 
         @@ -58,9 +58,9 @@ describe Emarsys::Email do 
     | 
|
| 
       58 
58 
     | 
    
         
             
                end
         
     | 
| 
       59 
59 
     | 
    
         | 
| 
       60 
60 
     | 
    
         
             
                it "requests an email launch with parameters" do
         
     | 
| 
       61 
     | 
    
         
            -
                  stub_params = {: 
     | 
| 
      
 61 
     | 
    
         
            +
                  stub_params = {schedule: "2013-12-01 23:00:00", time_zone: "Europe/Berlin"}
         
     | 
| 
       62 
62 
     | 
    
         
             
                  stub = stub_request(:post, "https://api.emarsys.net/api/v2/email/123/launch").with(:body => stub_params.to_json).to_return(standard_return_body)
         
     | 
| 
       63 
     | 
    
         
            -
                  Emarsys::Email.launch(123,  
     | 
| 
      
 63 
     | 
    
         
            +
                  Emarsys::Email.launch(123, schedule: "2013-12-01 23:00:00", time_zone: "Europe/Berlin")
         
     | 
| 
       64 
64 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       65 
65 
     | 
    
         
             
                end
         
     | 
| 
       66 
66 
     | 
    
         
             
              end
         
     | 
| 
         @@ -69,16 +69,16 @@ describe Emarsys::Email do 
     | 
|
| 
       69 
69 
     | 
    
         
             
                it "requests an email preview" do
         
     | 
| 
       70 
70 
     | 
    
         
             
                  stub_params = {:version => 'html'}
         
     | 
| 
       71 
71 
     | 
    
         
             
                  stub = stub_request(:post, "https://api.emarsys.net/api/v2/email/123/preview").with(:body => stub_params.to_json).to_return(standard_return_body)
         
     | 
| 
       72 
     | 
    
         
            -
                  Emarsys::Email.preview(123, 'html')
         
     | 
| 
      
 72 
     | 
    
         
            +
                  Emarsys::Email.preview(123, version: 'html')
         
     | 
| 
       73 
73 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       74 
74 
     | 
    
         
             
                end
         
     | 
| 
       75 
75 
     | 
    
         
             
              end
         
     | 
| 
       76 
76 
     | 
    
         | 
| 
       77 
77 
     | 
    
         
             
              describe ".send_test_mail" do
         
     | 
| 
       78 
78 
     | 
    
         
             
                it "requests an email test sending with custom recipient list" do
         
     | 
| 
       79 
     | 
    
         
            -
                  stub_params = {: 
     | 
| 
      
 79 
     | 
    
         
            +
                  stub_params = {recipientlist: 'john.doe@example.com;jane.doe@example.com'}
         
     | 
| 
       80 
80 
     | 
    
         
             
                  stub = stub_request(:post, "https://api.emarsys.net/api/v2/email/123/sendtestmail").with(:body => stub_params.to_json).to_return(standard_return_body)
         
     | 
| 
       81 
     | 
    
         
            -
                  Emarsys::Email.send_test_mail(123,  
     | 
| 
      
 81 
     | 
    
         
            +
                  Emarsys::Email.send_test_mail(123, recipientlist: 'john.doe@example.com;jane.doe@example.com')
         
     | 
| 
       82 
82 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       83 
83 
     | 
    
         
             
                end
         
     | 
| 
       84 
84 
     | 
    
         
             
              end
         
     | 
| 
         @@ -12,13 +12,13 @@ describe Emarsys::Event do 
     | 
|
| 
       12 
12 
     | 
    
         
             
              describe ".trigger" do
         
     | 
| 
       13 
13 
     | 
    
         
             
                it "requests event trigger with parameters" do
         
     | 
| 
       14 
14 
     | 
    
         
             
                  stub = stub_request(:post, "https://api.emarsys.net/api/v2/event/123/trigger").with(:body => {'key_id' => 3, 'external_id' => "jane.doe@example.com"}.to_json).to_return(standard_return_body)
         
     | 
| 
       15 
     | 
    
         
            -
                  Emarsys::Event.trigger(123, 3, 'jane.doe@example.com')
         
     | 
| 
      
 15 
     | 
    
         
            +
                  Emarsys::Event.trigger(123, key_id: 3, external_id: 'jane.doe@example.com')
         
     | 
| 
       16 
16 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       17 
17 
     | 
    
         
             
                end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                it "requests event trigger with additional data parameters" do
         
     | 
| 
       20 
20 
     | 
    
         
             
                  stub = stub_request(:post, "https://api.emarsys.net/api/v2/event/123/trigger").with(:body => {'key_id' => 3, 'external_id' => "jane.doe@example.com", :data => {'global' => {'my_placeholder' => 'Something'}}}.to_json).to_return(standard_return_body)
         
     | 
| 
       21 
     | 
    
         
            -
                  Emarsys::Event.trigger(123, 3, 'jane.doe@example.com', {'global' => {'my_placeholder' => 'Something'}})
         
     | 
| 
      
 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 
24 
     | 
    
         
             
              end
         
     | 
| 
         @@ -26,7 +26,7 @@ describe Emarsys::Event do 
     | 
|
| 
       26 
26 
     | 
    
         
             
              describe ".trigger_multiple" do
         
     | 
| 
       27 
27 
     | 
    
         
             
                it "requests event trigger with parameters" do
         
     | 
| 
       28 
28 
     | 
    
         
             
                  stub = stub_request(:post, "https://api.emarsys.net/api/v2/event/123/trigger").with(:body => {'key_id' => 3, 'external_id' => "", :data => nil, :contacts => [{'external_id' => "jane.doe@example.com"}]}.to_json).to_return(standard_return_body)
         
     | 
| 
       29 
     | 
    
         
            -
                  Emarsys::Event.trigger_multiple(123,3,[{'external_id' => 'jane.doe@example.com'}])
         
     | 
| 
      
 29 
     | 
    
         
            +
                  Emarsys::Event.trigger_multiple(123, key_id: 3, contacts: [{'external_id' => 'jane.doe@example.com'}])
         
     | 
| 
       30 
30 
     | 
    
         
             
                  expect(stub).to have_been_requested.once
         
     | 
| 
       31 
31 
     | 
    
         
             
                end
         
     | 
| 
       32 
32 
     | 
    
         
             
              end
         
     |