mailjet 1.5.4 → 1.8.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 +5 -5
 - data/README.md +298 -183
 - data/Rakefile +23 -14
 - data/lib/mailjet/configuration.rb +56 -4
 - data/lib/mailjet/connection.rb +68 -33
 - data/lib/mailjet/exception/errors.rb +94 -0
 - data/lib/mailjet/mailer.rb +45 -16
 - data/lib/mailjet/rack/endpoint.rb +2 -3
 - data/lib/mailjet/resource.rb +105 -72
 - data/lib/mailjet/resources/campaigndraft.rb +1 -1
 - data/lib/mailjet/resources/campaigndraft_detailcontent.rb +17 -1
 - data/lib/mailjet/resources/campaigndraft_schedule.rb +1 -1
 - data/lib/mailjet/resources/campaigndraft_send.rb +1 -1
 - data/lib/mailjet/resources/campaigndraft_status.rb +1 -1
 - data/lib/mailjet/resources/campaigndraft_test.rb +1 -1
 - data/lib/mailjet/resources/contact.rb +11 -2
 - data/lib/mailjet/resources/contact_getcontactslists.rb +17 -0
 - data/lib/mailjet/resources/contact_pii.rb +8 -0
 - data/lib/mailjet/resources/contactslist_csv.rb +8 -0
 - data/lib/mailjet/resources/csvimport.rb +0 -1
 - data/lib/mailjet/resources/listrecipient.rb +2 -1
 - data/lib/mailjet/resources/messagehistory.rb +16 -0
 - data/lib/mailjet/resources/messageinformation.rb +17 -0
 - data/lib/mailjet/resources/newsletter.rb +1 -2
 - data/lib/mailjet/resources/openinformation.rb +17 -0
 - data/lib/mailjet/resources/retrieve_errors_csv.rb +8 -0
 - data/lib/mailjet/resources/send.rb +1 -1
 - data/lib/mailjet/resources/statcounters.rb +33 -0
 - data/lib/mailjet/resources/statistics_linkclick.rb +12 -0
 - data/lib/mailjet/resources/template_detailcontent.rb +18 -2
 - data/lib/mailjet/version.rb +1 -1
 - data/lib/mailjet.rb +4 -6
 - metadata +25 -120
 - data/lib/mailjet/api_error.rb +0 -29
 - data/lib/mailjet/core_extensions/ostruct.rb +0 -9
 - data/lib/mailjet/gem_extensions/rest_client.rb +0 -19
 
    
        data/lib/mailjet/resource.rb
    CHANGED
    
    | 
         @@ -1,13 +1,9 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'mailjet/connection'
         
     | 
| 
       2 
     | 
    
         
            -
            require ' 
     | 
| 
       3 
     | 
    
         
            -
            require 'active_support 
     | 
| 
       4 
     | 
    
         
            -
            require 'active_support/core_ext/hash'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'yajl'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'active_support'
         
     | 
| 
       5 
4 
     | 
    
         
             
            require 'active_support/core_ext/string'
         
     | 
| 
       6 
     | 
    
         
            -
            require 'active_support/core_ext/ 
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
            require 'active_support/json/decoding'
         
     | 
| 
       9 
     | 
    
         
            -
            #require 'mail'
         
     | 
| 
       10 
     | 
    
         
            -
            require 'json'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'active_support/core_ext/hash/indifferent_access'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
       11 
7 
     | 
    
         | 
| 
       12 
8 
     | 
    
         | 
| 
       13 
9 
     | 
    
         
             
            # This option automatically transforms the date output by the API into something a bit more readable.
         
     | 
| 
         @@ -18,70 +14,90 @@ require 'json' 
     | 
|
| 
       18 
14 
     | 
    
         | 
| 
       19 
15 
     | 
    
         
             
            module Mailjet
         
     | 
| 
       20 
16 
     | 
    
         
             
              module Resource
         
     | 
| 
       21 
     | 
    
         
            -
                extend ActiveSupport::Concern
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
17 
     | 
    
         
             
                # define here available options for filtering
         
     | 
| 
       24 
18 
     | 
    
         
             
                OPTIONS = [:version, :url, :perform_api_call, :api_key, :secret_key]
         
     | 
| 
       25 
19 
     | 
    
         | 
| 
       26 
20 
     | 
    
         
             
                NON_JSON_URLS = ['v3/send/message'] # urls that don't accept JSON input
         
     | 
| 
      
 21 
     | 
    
         
            +
                DATA_URLS = ['plain', 'csv'] # url for send binary data , 'CSVError/text:csv'
         
     | 
| 
       27 
22 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
                included 
     | 
| 
       29 
     | 
    
         
            -
                   
     | 
| 
       30 
     | 
    
         
            -
                   
     | 
| 
      
 23 
     | 
    
         
            +
                def self.included(base)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  base.extend ClassMethods
         
     | 
| 
      
 25 
     | 
    
         
            +
                  base.class_eval do
         
     | 
| 
      
 26 
     | 
    
         
            +
                    cattr_accessor :resource_path, :public_operations, :read_only, :filters, :resourceprop, :read_only_attributes, :action, :non_json_urls, :version
         
     | 
| 
      
 27 
     | 
    
         
            +
                    cattr_writer :connection
         
     | 
| 
       31 
28 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                    class_variable_get(:@@connection) || default_connection(options)
         
     | 
| 
       34 
     | 
    
         
            -
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
                    self.read_only_attributes = []
         
     | 
| 
       35 
30 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                      options[:api_key] || Mailjet.config.api_key,
         
     | 
| 
       40 
     | 
    
         
            -
                      options[:secret_key] || Mailjet.config.secret_key,
         
     | 
| 
       41 
     | 
    
         
            -
                      public_operations: public_operations,
         
     | 
| 
       42 
     | 
    
         
            -
                      read_only: read_only,
         
     | 
| 
       43 
     | 
    
         
            -
                      perform_api_call: options[:perform_api_call])
         
     | 
| 
       44 
     | 
    
         
            -
                  end
         
     | 
| 
      
 31 
     | 
    
         
            +
                    def self.connection(options = {})
         
     | 
| 
      
 32 
     | 
    
         
            +
                      class_variable_get(:@@connection) || default_connection(options)
         
     | 
| 
      
 33 
     | 
    
         
            +
                    end
         
     | 
| 
       45 
34 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
      
 35 
     | 
    
         
            +
                    def self.default_connection(options = {})
         
     | 
| 
      
 36 
     | 
    
         
            +
                      Mailjet::Connection.new(
         
     | 
| 
      
 37 
     | 
    
         
            +
                        "#{options[:url]}/#{options[:version]}/#{resource_path}",
         
     | 
| 
      
 38 
     | 
    
         
            +
                        options[:api_key] || Mailjet.config.api_key,
         
     | 
| 
      
 39 
     | 
    
         
            +
                        options[:secret_key] || Mailjet.config.secret_key,
         
     | 
| 
      
 40 
     | 
    
         
            +
                        public_operations: public_operations,
         
     | 
| 
      
 41 
     | 
    
         
            +
                        read_only: read_only,
         
     | 
| 
      
 42 
     | 
    
         
            +
                        perform_api_call: options[:perform_api_call])
         
     | 
| 
      
 43 
     | 
    
         
            +
                    end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                    def self.default_headers
         
     | 
| 
      
 46 
     | 
    
         
            +
                      if NON_JSON_URLS.include?(self.resource_path) # don't use JSON if Send API
         
     | 
| 
      
 47 
     | 
    
         
            +
                        default_headers = { 'Accept' =>'application/json', 'Accept-Encoding' => 'deflate' }
         
     | 
| 
      
 48 
     | 
    
         
            +
                      elsif DATA_URLS.any? do |data_type|
         
     | 
| 
      
 49 
     | 
    
         
            +
                        default_headers = { 'Content-Type' => "text/#{data_type}" } if self.resource_path.include?(data_type)
         
     | 
| 
      
 50 
     | 
    
         
            +
                        end
         
     | 
| 
      
 51 
     | 
    
         
            +
                      else
         
     | 
| 
      
 52 
     | 
    
         
            +
                        # use JSON if *not* Send API
         
     | 
| 
      
 53 
     | 
    
         
            +
                        default_headers = {'Content-Type' =>'application/json', 'Accept' =>'application/json', 'Accept-Encoding' => 'deflate'}
         
     | 
| 
      
 54 
     | 
    
         
            +
                      end
         
     | 
| 
      
 55 
     | 
    
         
            +
                      return default_headers.merge!('User-Agent' => "mailjet-api-v3-ruby/#{Gem.loaded_specs["mailjet"].version}")
         
     | 
| 
       51 
56 
     | 
    
         
             
                    end
         
     | 
| 
       52 
     | 
    
         
            -
                    return default_headers.merge(user_agent: "mailjet-api-v3-ruby/#{Gem.loaded_specs["mailjet"].version}")
         
     | 
| 
       53 
57 
     | 
    
         
             
                  end
         
     | 
| 
       54 
58 
     | 
    
         
             
                end
         
     | 
| 
       55 
59 
     | 
    
         | 
| 
       56 
60 
     | 
    
         
             
                module ClassMethods
         
     | 
| 
       57 
61 
     | 
    
         
             
                  def first(params = {}, options = {})
         
     | 
| 
       58 
62 
     | 
    
         
             
                    all(params.merge!(limit: 1), options).first
         
     | 
| 
      
 63 
     | 
    
         
            +
                  rescue Mailjet::ApiError => error
         
     | 
| 
      
 64 
     | 
    
         
            +
                    raise error
         
     | 
| 
       59 
65 
     | 
    
         
             
                  end
         
     | 
| 
       60 
66 
     | 
    
         | 
| 
       61 
67 
     | 
    
         
             
                  def all(params = {}, options = {})
         
     | 
| 
       62 
68 
     | 
    
         
             
                    opts = define_options(options)
         
     | 
| 
       63 
69 
     | 
    
         
             
                    params = format_params(params)
         
     | 
| 
       64 
     | 
    
         
            -
                    response = connection(opts).get(default_headers.merge(params: params))
         
     | 
| 
       65 
     | 
    
         
            -
                    attribute_array = parse_api_json(response)
         
     | 
| 
      
 70 
     | 
    
         
            +
                    response = connection(opts).get(default_headers.merge!(params: params))
         
     | 
| 
      
 71 
     | 
    
         
            +
                    attribute_array = parse_api_json(response.body)
         
     | 
| 
       66 
72 
     | 
    
         
             
                    attribute_array.map{ |attributes| instanciate_from_api(attributes) }
         
     | 
| 
      
 73 
     | 
    
         
            +
                  rescue Mailjet::ApiError => error
         
     | 
| 
      
 74 
     | 
    
         
            +
                    raise error
         
     | 
| 
       67 
75 
     | 
    
         
             
                  end
         
     | 
| 
       68 
76 
     | 
    
         | 
| 
       69 
77 
     | 
    
         
             
                  def count(options = {})
         
     | 
| 
       70 
78 
     | 
    
         
             
                    opts = define_options(options)
         
     | 
| 
       71 
     | 
    
         
            -
                    response_json = connection(opts).get(default_headers.merge(params: {limit: 1, countrecords: 1}))
         
     | 
| 
       72 
     | 
    
         
            -
                    response_hash =  
     | 
| 
      
 79 
     | 
    
         
            +
                    response_json = connection(opts).get(default_headers.merge!(params: {limit: 1, countrecords: 1}))
         
     | 
| 
      
 80 
     | 
    
         
            +
                    response_hash = Yajl::Parser.parse(response_json.body)
         
     | 
| 
       73 
81 
     | 
    
         
             
                    response_hash['Total']
         
     | 
| 
      
 82 
     | 
    
         
            +
                  rescue Mailjet::ApiError => error
         
     | 
| 
      
 83 
     | 
    
         
            +
                    raise error
         
     | 
| 
       74 
84 
     | 
    
         
             
                  end
         
     | 
| 
       75 
85 
     | 
    
         | 
| 
       76 
86 
     | 
    
         
             
                  def find(id, job_id = nil, options = {})
         
     | 
| 
      
 87 
     | 
    
         
            +
                    normalized_id = if id.is_a? String
         
     | 
| 
      
 88 
     | 
    
         
            +
                      URI.encode_www_form_component(id)
         
     | 
| 
      
 89 
     | 
    
         
            +
                    else
         
     | 
| 
      
 90 
     | 
    
         
            +
                      id
         
     | 
| 
      
 91 
     | 
    
         
            +
                    end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
       77 
93 
     | 
    
         
             
                    # if action method, ammend url to appropriate id
         
     | 
| 
       78 
94 
     | 
    
         
             
                    opts = define_options(options)
         
     | 
| 
       79 
     | 
    
         
            -
                    self.resource_path = create_action_resource_path( 
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
                    attributes = parse_api_json(connection(opts)[ 
     | 
| 
      
 95 
     | 
    
         
            +
                    self.resource_path = create_action_resource_path(normalized_id, job_id) if self.action
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                    attributes = parse_api_json(connection(opts)[normalized_id].get(default_headers).body).first
         
     | 
| 
       82 
98 
     | 
    
         
             
                    instanciate_from_api(attributes)
         
     | 
| 
       83 
99 
     | 
    
         | 
| 
       84 
     | 
    
         
            -
                  rescue Mailjet:: 
     | 
| 
      
 100 
     | 
    
         
            +
                  rescue Mailjet::CommunicationError => e
         
     | 
| 
       85 
101 
     | 
    
         
             
                    if e.code == 404
         
     | 
| 
       86 
102 
     | 
    
         
             
                      nil
         
     | 
| 
       87 
103 
     | 
    
         
             
                    else
         
     | 
| 
         @@ -89,10 +105,18 @@ module Mailjet 
     | 
|
| 
       89 
105 
     | 
    
         
             
                    end
         
     | 
| 
       90 
106 
     | 
    
         
             
                  end
         
     | 
| 
       91 
107 
     | 
    
         | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
                  def find_by_id(id, options = {})
         
     | 
| 
      
 110 
     | 
    
         
            +
                    # if action method, ammend url to appropriate id
         
     | 
| 
      
 111 
     | 
    
         
            +
                    opts = define_options(options)
         
     | 
| 
      
 112 
     | 
    
         
            +
                    self.resource_path = create_action_resource_path(id) if self.action
         
     | 
| 
      
 113 
     | 
    
         
            +
                    connection(opts).get(default_headers)
         
     | 
| 
      
 114 
     | 
    
         
            +
                  end
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
       92 
116 
     | 
    
         
             
                  def create(attributes = {}, options = {})
         
     | 
| 
       93 
117 
     | 
    
         
             
                    # if action method, ammend url to appropriate id
         
     | 
| 
       94 
118 
     | 
    
         
             
                    opts = define_options(options)
         
     | 
| 
       95 
     | 
    
         
            -
                    self.resource_path = create_action_resource_path(attributes[:id]) if self.action
         
     | 
| 
      
 119 
     | 
    
         
            +
                    self.resource_path = create_action_resource_path(attributes[:id]) if (self.action and attributes[:id])
         
     | 
| 
       96 
120 
     | 
    
         
             
                    attributes.tap { |hs| hs.delete(:id) }
         
     | 
| 
       97 
121 
     | 
    
         | 
| 
       98 
122 
     | 
    
         
             
                    if Mailjet.config.default_from and self.resource_path == 'send/'
         
     | 
| 
         @@ -106,9 +130,8 @@ module Mailjet 
     | 
|
| 
       106 
130 
     | 
    
         | 
| 
       107 
131 
     | 
    
         
             
                    self.new(attributes).tap do |resource|
         
     | 
| 
       108 
132 
     | 
    
         
             
                      resource.save!(opts)
         
     | 
| 
       109 
     | 
    
         
            -
                      resource.persisted = true
         
     | 
| 
      
 133 
     | 
    
         
            +
                      resource.attributes[:persisted] = true
         
     | 
| 
       110 
134 
     | 
    
         
             
                    end
         
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
135 
     | 
    
         
             
                  end
         
     | 
| 
       113 
136 
     | 
    
         | 
| 
       114 
137 
     | 
    
         
             
                  def delete(id, options = {})
         
     | 
| 
         @@ -116,14 +139,25 @@ module Mailjet 
     | 
|
| 
       116 
139 
     | 
    
         
             
                     opts = define_options(options)
         
     | 
| 
       117 
140 
     | 
    
         
             
                     self.resource_path = create_action_resource_path(id) if self.action
         
     | 
| 
       118 
141 
     | 
    
         
             
                     connection(opts)[id].delete(default_headers)
         
     | 
| 
      
 142 
     | 
    
         
            +
                  rescue Mailjet::ApiError => error
         
     | 
| 
      
 143 
     | 
    
         
            +
                    raise error
         
     | 
| 
      
 144 
     | 
    
         
            +
                  end
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
                  def send_data(id, binary_data = nil, options = {})
         
     | 
| 
      
 147 
     | 
    
         
            +
                    opts = define_options(options)
         
     | 
| 
      
 148 
     | 
    
         
            +
                    self.resource_path = create_action_resource_path(id) if self.action
         
     | 
| 
      
 149 
     | 
    
         
            +
                    response = connection(opts).post(binary_data, default_headers.merge({'Content-Length' => "#{binary_data.size}", 'Transfer-Encoding' => 'chunked'}))
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
                    response_hash = response.respond_to?(:body) ? Yajl::Parser.parse(response.body) : Yajl::Parser.parse(response)
         
     | 
| 
      
 152 
     | 
    
         
            +
                    response_hash['ID'] ? response_hash['ID'] : response_hash
         
     | 
| 
       119 
153 
     | 
    
         
             
                  end
         
     | 
| 
       120 
154 
     | 
    
         | 
| 
       121 
155 
     | 
    
         
             
                  def instanciate_from_api(attributes = {})
         
     | 
| 
       122 
     | 
    
         
            -
                    self.new(attributes.merge(persisted: true))
         
     | 
| 
      
 156 
     | 
    
         
            +
                    self.new(attributes.merge!(persisted: true))
         
     | 
| 
       123 
157 
     | 
    
         
             
                  end
         
     | 
| 
       124 
158 
     | 
    
         | 
| 
       125 
159 
     | 
    
         
             
                  def parse_api_json(response_json)
         
     | 
| 
       126 
     | 
    
         
            -
                    response_hash =  
     | 
| 
      
 160 
     | 
    
         
            +
                    response_hash = Yajl::Parser.parse(response_json)
         
     | 
| 
       127 
161 
     | 
    
         | 
| 
       128 
162 
     | 
    
         
             
                    #Take the response from the API and put it through a method -- taken from the ActiveSupport library -- which converts
         
     | 
| 
       129 
163 
     | 
    
         
             
                    #the date-time from "2014-05-19T15:31:09Z" to "Mon, 19 May 2014 15:31:09 +0000" format.
         
     | 
| 
         @@ -138,17 +172,17 @@ module Mailjet 
     | 
|
| 
       138 
172 
     | 
    
         
             
                  end
         
     | 
| 
       139 
173 
     | 
    
         | 
| 
       140 
174 
     | 
    
         
             
                  def create_action_resource_path(id, job_id = nil)
         
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
      
 175 
     | 
    
         
            +
                    url_elements = self.resource_path.split("/")
         
     | 
| 
      
 176 
     | 
    
         
            +
                    url_elements.delete_at(url_elements.length-1) if url_elements.last.to_i > 0 #if there is a trailing number for the job id from last call, delete it
         
     | 
| 
       143 
177 
     | 
    
         | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
       146 
     | 
    
         
            -
             
     | 
| 
      
 178 
     | 
    
         
            +
                    if !(url_elements[1] == "contacts" && self.action == "managemanycontacts")
         
     | 
| 
      
 179 
     | 
    
         
            +
                      url_elements[2] = id.to_s
         
     | 
| 
      
 180 
     | 
    
         
            +
                    end
         
     | 
| 
       147 
181 
     | 
    
         | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
      
 182 
     | 
    
         
            +
                    url_elements << job_id.to_s if job_id #if job_id exists, amend it to end of the URI
         
     | 
| 
      
 183 
     | 
    
         
            +
                    url = url_elements.join("/")
         
     | 
| 
       150 
184 
     | 
    
         | 
| 
       151 
     | 
    
         
            -
             
     | 
| 
      
 185 
     | 
    
         
            +
                    return url
         
     | 
| 
       152 
186 
     | 
    
         
             
                  end
         
     | 
| 
       153 
187 
     | 
    
         | 
| 
       154 
188 
     | 
    
         | 
| 
         @@ -159,9 +193,9 @@ module Mailjet 
     | 
|
| 
       159 
193 
     | 
    
         
             
                    case data
         
     | 
| 
       160 
194 
     | 
    
         
             
                    when nil
         
     | 
| 
       161 
195 
     | 
    
         
             
                      nil
         
     | 
| 
       162 
     | 
    
         
            -
             
     | 
| 
      
 196 
     | 
    
         
            +
                    when /^(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[T \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?))$/
         
     | 
| 
       163 
197 
     | 
    
         
             
                      begin
         
     | 
| 
       164 
     | 
    
         
            -
                        DateTime. 
     | 
| 
      
 198 
     | 
    
         
            +
                        DateTime.iso8601(data)
         
     | 
| 
       165 
199 
     | 
    
         
             
                      rescue ArgumentError
         
     | 
| 
       166 
200 
     | 
    
         
             
                        data
         
     | 
| 
       167 
201 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -250,9 +284,9 @@ module Mailjet 
     | 
|
| 
       250 
284 
     | 
    
         
             
                  if opts[:perform_api_call] && !persisted?
         
     | 
| 
       251 
285 
     | 
    
         
             
                    # get attributes only for entity creation
         
     | 
| 
       252 
286 
     | 
    
         
             
                    self.attributes = if self.resource_path == 'send'
         
     | 
| 
       253 
     | 
    
         
            -
                       
     | 
| 
      
 287 
     | 
    
         
            +
                      Yajl::Parser.parse(response.body)
         
     | 
| 
       254 
288 
     | 
    
         
             
                    else
         
     | 
| 
       255 
     | 
    
         
            -
                      parse_api_json(response).first
         
     | 
| 
      
 289 
     | 
    
         
            +
                      parse_api_json(response.body).first
         
     | 
| 
       256 
290 
     | 
    
         
             
                    end
         
     | 
| 
       257 
291 
     | 
    
         
             
                  end
         
     | 
| 
       258 
292 
     | 
    
         | 
| 
         @@ -292,7 +326,7 @@ module Mailjet 
     | 
|
| 
       292 
326 
     | 
    
         
             
                  save(opts)
         
     | 
| 
       293 
327 
     | 
    
         
             
                end
         
     | 
| 
       294 
328 
     | 
    
         | 
| 
       295 
     | 
    
         
            -
                def delete 
     | 
| 
      
 329 
     | 
    
         
            +
                def delete
         
     | 
| 
       296 
330 
     | 
    
         
             
                  self.class.delete(id)
         
     | 
| 
       297 
331 
     | 
    
         
             
                end
         
     | 
| 
       298 
332 
     | 
    
         | 
| 
         @@ -309,12 +343,15 @@ module Mailjet 
     | 
|
| 
       309 
343 
     | 
    
         
             
                def formatted_payload
         
     | 
| 
       310 
344 
     | 
    
         
             
                  payload = attributes.reject { |k,v| v.blank? }
         
     | 
| 
       311 
345 
     | 
    
         
             
                  if persisted?
         
     | 
| 
       312 
     | 
    
         
            -
                    payload = payload.slice(*resourceprop)
         
     | 
| 
      
 346 
     | 
    
         
            +
                    payload = payload.slice(*resourceprop.map(&:to_s))
         
     | 
| 
      
 347 
     | 
    
         
            +
                      .except(*read_only_attributes.map(&:to_s))
         
     | 
| 
       313 
348 
     | 
    
         
             
                  end
         
     | 
| 
       314 
349 
     | 
    
         
             
                  payload = camelcase_keys(payload)
         
     | 
| 
       315 
350 
     | 
    
         
             
                  payload.tap { |hs| hs.delete("Persisted") }
         
     | 
| 
       316 
351 
     | 
    
         
             
                  payload.inject({}) do |h, (k, v)|
         
     | 
| 
       317 
     | 
    
         
            -
                     
     | 
| 
      
 352 
     | 
    
         
            +
                    if v.respond_to? :utc
         
     | 
| 
      
 353 
     | 
    
         
            +
                      v = v.utc.to_s
         
     | 
| 
      
 354 
     | 
    
         
            +
                    end
         
     | 
| 
       318 
355 
     | 
    
         
             
                    h.merge!({k => v})
         
     | 
| 
       319 
356 
     | 
    
         
             
                  end
         
     | 
| 
       320 
357 
     | 
    
         
             
                end
         
     | 
| 
         @@ -337,20 +374,16 @@ module Mailjet 
     | 
|
| 
       337 
374 
     | 
    
         | 
| 
       338 
375 
     | 
    
         
             
                def method_missing(method_symbol, *arguments) #:nodoc:
         
     | 
| 
       339 
376 
     | 
    
         
             
                  method_name = method_symbol.to_s
         
     | 
| 
       340 
     | 
    
         
            -
             
     | 
| 
       341 
     | 
    
         
            -
                     
     | 
| 
       342 
     | 
    
         
            -
                     
     | 
| 
       343 
     | 
    
         
            -
             
     | 
| 
       344 
     | 
    
         
            -
             
     | 
| 
       345 
     | 
    
         
            -
             
     | 
| 
       346 
     | 
    
         
            -
                     
     | 
| 
       347 
     | 
    
         
            -
                  else
         
     | 
| 
       348 
     | 
    
         
            -
                    return attributes[method_name] if attributes.include?(method_name)
         
     | 
| 
       349 
     | 
    
         
            -
                    # not set right now but we know about it
         
     | 
| 
       350 
     | 
    
         
            -
                    # return nil if known_attributes.include?(method_name)
         
     | 
| 
       351 
     | 
    
         
            -
                    super
         
     | 
| 
      
 377 
     | 
    
         
            +
                  if method_name.end_with?("=")
         
     | 
| 
      
 378 
     | 
    
         
            +
                    attributes[method_name.chop] = arguments.first
         
     | 
| 
      
 379 
     | 
    
         
            +
                    return
         
     | 
| 
      
 380 
     | 
    
         
            +
                  end
         
     | 
| 
      
 381 
     | 
    
         
            +
             
     | 
| 
      
 382 
     | 
    
         
            +
                  if attributes.include?(method_name)
         
     | 
| 
      
 383 
     | 
    
         
            +
                    return attributes[method_name]
         
     | 
| 
       352 
384 
     | 
    
         
             
                  end
         
     | 
| 
       353 
     | 
    
         
            -
                end
         
     | 
| 
       354 
385 
     | 
    
         | 
| 
      
 386 
     | 
    
         
            +
                  super
         
     | 
| 
      
 387 
     | 
    
         
            +
                end
         
     | 
| 
       355 
388 
     | 
    
         
             
              end
         
     | 
| 
       356 
389 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Mailjet
         
     | 
| 
       2 
2 
     | 
    
         
             
              class Campaigndraft
         
     | 
| 
       3 
3 
     | 
    
         
             
                include Mailjet::Resource
         
     | 
| 
       4 
     | 
    
         
            -
                self.resource_path = ' 
     | 
| 
      
 4 
     | 
    
         
            +
                self.resource_path = 'REST/campaigndraft'
         
     | 
| 
       5 
5 
     | 
    
         
             
                self.public_operations = [:get, :put, :post]
         
     | 
| 
       6 
6 
     | 
    
         
             
                self.filters = [:campaign, :contacts_list, :delivered_at, :edit_mode, :is_archived, :is_campaign, :is_deleted, :is_handled, :is_starred, :modified, :news_letter_template, :segmentation, :status, :subject, :template]
         
     | 
| 
       7 
7 
     | 
    
         
             
                self.resourceprop = [:campaign, :contacts_list, :created_at, :delivered_at, :edit_mode, :id, :is_starred, :is_text_part_included, :locale, :modified_at, :preset, :reply_email, :segmentation, :sender, :sender_email, :sender_name, :status, :subject, :template_id, :title, :url, :used, 'CampaignID', 'CampaignALT', 'ContactsListID', 'ContactsListALT', 'SegmentationID', 'SegmentationALT', :contacts_list_id,'TemplateID']
         
     | 
| 
         @@ -2,10 +2,26 @@ module Mailjet 
     | 
|
| 
       2 
2 
     | 
    
         
             
              class Campaigndraft_detailcontent
         
     | 
| 
       3 
3 
     | 
    
         
             
                include Mailjet::Resource
         
     | 
| 
       4 
4 
     | 
    
         
             
                self.action = "detailcontent"
         
     | 
| 
       5 
     | 
    
         
            -
                self.resource_path = " 
     | 
| 
      
 5 
     | 
    
         
            +
                self.resource_path = "REST/campaigndraft/id/#{self.action}"
         
     | 
| 
       6 
6 
     | 
    
         
             
                self.public_operations = [:get, :post]
         
     | 
| 
       7 
7 
     | 
    
         
             
                self.filters = []
         
     | 
| 
       8 
8 
     | 
    
         
             
                self.resourceprop = [:text_part, :html_part, :headers, :mjml_content]
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
      
 10 
     | 
    
         
            +
                def self.find(id, job_id = nil, options = {})
         
     | 
| 
      
 11 
     | 
    
         
            +
                  opts = define_options(options)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  self.resource_path = create_action_resource_path(id, job_id) if self.action
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                  raw_data = parse_api_json(connection(opts)[id].get(default_headers).body)
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  raw_data.map do |entity|
         
     | 
| 
      
 17 
     | 
    
         
            +
                    instanciate_from_api(entity)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
                rescue Mailjet::CommunicationError => e
         
     | 
| 
      
 20 
     | 
    
         
            +
                  if e.code == 404
         
     | 
| 
      
 21 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 22 
     | 
    
         
            +
                  else
         
     | 
| 
      
 23 
     | 
    
         
            +
                    raise e
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
       10 
26 
     | 
    
         
             
              end
         
     | 
| 
       11 
27 
     | 
    
         
             
            end
         
     | 
| 
         @@ -2,7 +2,7 @@ module Mailjet 
     | 
|
| 
       2 
2 
     | 
    
         
             
              class Campaigndraft_schedule
         
     | 
| 
       3 
3 
     | 
    
         
             
                include Mailjet::Resource
         
     | 
| 
       4 
4 
     | 
    
         
             
                self.action = "schedule"
         
     | 
| 
       5 
     | 
    
         
            -
                self.resource_path = " 
     | 
| 
      
 5 
     | 
    
         
            +
                self.resource_path = "REST/campaigndraft/id/#{self.action}"
         
     | 
| 
       6 
6 
     | 
    
         
             
                self.public_operations = [:post, :delete , :get]
         
     | 
| 
       7 
7 
     | 
    
         
             
                self.filters = []
         
     | 
| 
       8 
8 
     | 
    
         
             
                self.resourceprop = [:date]
         
     | 
| 
         @@ -2,7 +2,7 @@ module Mailjet 
     | 
|
| 
       2 
2 
     | 
    
         
             
              class Campaigndraft_send
         
     | 
| 
       3 
3 
     | 
    
         
             
                include Mailjet::Resource
         
     | 
| 
       4 
4 
     | 
    
         
             
                self.action = "send"
         
     | 
| 
       5 
     | 
    
         
            -
                self.resource_path = " 
     | 
| 
      
 5 
     | 
    
         
            +
                self.resource_path = "REST/campaigndraft/id/#{self.action}"
         
     | 
| 
       6 
6 
     | 
    
         
             
                self.public_operations = [:post]
         
     | 
| 
       7 
7 
     | 
    
         
             
                self.filters = []
         
     | 
| 
       8 
8 
     | 
    
         
             
                self.resourceprop = []
         
     | 
| 
         @@ -2,7 +2,7 @@ module Mailjet 
     | 
|
| 
       2 
2 
     | 
    
         
             
              class Campaigndraft_status
         
     | 
| 
       3 
3 
     | 
    
         
             
                include Mailjet::Resource
         
     | 
| 
       4 
4 
     | 
    
         
             
                self.action = 'status'
         
     | 
| 
       5 
     | 
    
         
            -
                self.resource_path = " 
     | 
| 
      
 5 
     | 
    
         
            +
                self.resource_path = "REST/campaigndraft/id/#{self.action}"
         
     | 
| 
       6 
6 
     | 
    
         
             
                self.public_operations =  [:get]
         
     | 
| 
       7 
7 
     | 
    
         
             
                self.filters = []
         
     | 
| 
       8 
8 
     | 
    
         
             
                self.resourceprop = []
         
     | 
| 
         @@ -2,7 +2,7 @@ module Mailjet 
     | 
|
| 
       2 
2 
     | 
    
         
             
              class Campaigndraft_test
         
     | 
| 
       3 
3 
     | 
    
         
             
                include Mailjet::Resource
         
     | 
| 
       4 
4 
     | 
    
         
             
                self.action = "test"
         
     | 
| 
       5 
     | 
    
         
            -
                self.resource_path = " 
     | 
| 
      
 5 
     | 
    
         
            +
                self.resource_path = "REST/campaigndraft/id/#{self.action}"
         
     | 
| 
       6 
6 
     | 
    
         
             
                self.public_operations = [:post]
         
     | 
| 
       7 
7 
     | 
    
         
             
                self.filters = []
         
     | 
| 
       8 
8 
     | 
    
         
             
                self.resourceprop = [:email, :name]
         
     | 
| 
         @@ -4,7 +4,16 @@ module Mailjet 
     | 
|
| 
       4 
4 
     | 
    
         
             
                self.resource_path = 'REST/contact'
         
     | 
| 
       5 
5 
     | 
    
         
             
                self.public_operations = [:get, :put, :post]
         
     | 
| 
       6 
6 
     | 
    
         
             
                self.filters = [:campaign, :contacts_list, :is_unsubscribed, :last_activity_at, :recipient, :status]
         
     | 
| 
       7 
     | 
    
         
            -
                self.resourceprop = [ 
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
                self.resourceprop = [
         
     | 
| 
      
 8 
     | 
    
         
            +
                  :delivered_count,
         
     | 
| 
      
 9 
     | 
    
         
            +
                  :email,
         
     | 
| 
      
 10 
     | 
    
         
            +
                  :id,
         
     | 
| 
      
 11 
     | 
    
         
            +
                  :is_opt_in_pending,
         
     | 
| 
      
 12 
     | 
    
         
            +
                  :is_spam_complaining,
         
     | 
| 
      
 13 
     | 
    
         
            +
                  :name,
         
     | 
| 
      
 14 
     | 
    
         
            +
                  :unsubscribed_by,
         
     | 
| 
      
 15 
     | 
    
         
            +
                  :is_excluded_from_campaigns
         
     | 
| 
      
 16 
     | 
    
         
            +
                ]
         
     | 
| 
      
 17 
     | 
    
         
            +
                self.read_only_attributes = [:created_at, :last_activity_at, :last_update_at, :unsubscribed_at]
         
     | 
| 
       9 
18 
     | 
    
         
             
              end
         
     | 
| 
       10 
19 
     | 
    
         
             
            end
         
     | 
| 
         @@ -6,5 +6,22 @@ module Mailjet 
     | 
|
| 
       6 
6 
     | 
    
         
             
                self.public_operations = [:get]
         
     | 
| 
       7 
7 
     | 
    
         
             
                self.filters = []
         
     | 
| 
       8 
8 
     | 
    
         
             
                self.resourceprop = []
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                def self.find(id, job_id = nil, options = {})
         
     | 
| 
      
 11 
     | 
    
         
            +
                  opts = define_options(options)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  self.resource_path = create_action_resource_path(id, job_id) if self.action
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                  raw_data = parse_api_json(connection(opts).get(default_headers).body)
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  raw_data.map do |entity|
         
     | 
| 
      
 17 
     | 
    
         
            +
                    instanciate_from_api(entity)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
                rescue Mailjet::CommunicationError => e
         
     | 
| 
      
 20 
     | 
    
         
            +
                  if e.code == 404
         
     | 
| 
      
 21 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 22 
     | 
    
         
            +
                  else
         
     | 
| 
      
 23 
     | 
    
         
            +
                    raise e
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
       9 
26 
     | 
    
         
             
              end
         
     | 
| 
       10 
27 
     | 
    
         
             
            end
         
     | 
| 
         @@ -5,6 +5,5 @@ module Mailjet 
     | 
|
| 
       5 
5 
     | 
    
         
             
                self.public_operations = [:get, :put, :post]
         
     | 
| 
       6 
6 
     | 
    
         
             
                self.filters = []
         
     | 
| 
       7 
7 
     | 
    
         
             
                self.resourceprop = [:alive_at, :contacts_list, :count, :current, :data_id, :errcount, :err_treshold, :id, :import_options, :job_end, :job_start, :method, :request_at, :status]
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
8 
     | 
    
         
             
              end
         
     | 
| 
       10 
9 
     | 
    
         
             
            end
         
     | 
| 
         @@ -4,7 +4,8 @@ module Mailjet 
     | 
|
| 
       4 
4 
     | 
    
         
             
                self.resource_path = 'REST/listrecipient'
         
     | 
| 
       5 
5 
     | 
    
         
             
                self.public_operations = [:get, :put, :post, :delete]
         
     | 
| 
       6 
6 
     | 
    
         
             
                self.filters = [:active, :blocked, :contact, :contact_email, :contacts_list, :last_activity_at, :list_name, :opened, :status, :unsub]
         
     | 
| 
       7 
     | 
    
         
            -
                self.resourceprop = [:contact, :id, :is_active, :is_unsubscribed, :list, : 
     | 
| 
      
 7 
     | 
    
         
            +
                self.resourceprop = [:contact, :id, :is_active, :is_unsubscribed, :list, :contact_id, :list_id, 'ContactID', 'ListID', 'ContactALT', 'ListALT']
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
      
 9 
     | 
    
         
            +
                self.read_only_attributes = [:subscribed_at, :unsubscribed_at]
         
     | 
| 
       9 
10 
     | 
    
         
             
              end
         
     | 
| 
       10 
11 
     | 
    
         
             
            end
         
     | 
| 
         @@ -8,5 +8,21 @@ module Mailjet 
     | 
|
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
                self.read_only = true
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
      
 11 
     | 
    
         
            +
                def self.find(id, job_id = nil, options = {})
         
     | 
| 
      
 12 
     | 
    
         
            +
                  opts = define_options(options)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  self.resource_path = create_action_resource_path(id, job_id) if self.action
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  raw_data = parse_api_json(connection(opts)[id].get(default_headers).body)
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  raw_data.map do |entity|
         
     | 
| 
      
 18 
     | 
    
         
            +
                    instanciate_from_api(entity)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
                rescue Mailjet::CommunicationError => e
         
     | 
| 
      
 21 
     | 
    
         
            +
                  if e.code == 404
         
     | 
| 
      
 22 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 23 
     | 
    
         
            +
                  else
         
     | 
| 
      
 24 
     | 
    
         
            +
                    raise e
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
       11 
27 
     | 
    
         
             
              end
         
     | 
| 
       12 
28 
     | 
    
         
             
            end
         
     | 
| 
         @@ -8,5 +8,22 @@ module Mailjet 
     | 
|
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
                self.read_only = true
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
      
 11 
     | 
    
         
            +
                def self.find(id, job_id = nil, options = {})
         
     | 
| 
      
 12 
     | 
    
         
            +
                  opts = define_options(options)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  self.resource_path = create_action_resource_path(id, job_id) if self.action
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  raw_data = parse_api_json(connection(opts)[id].get(default_headers).body)
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  raw_data.map do |entity|
         
     | 
| 
      
 18 
     | 
    
         
            +
                    instanciate_from_api(entity)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
                rescue Mailjet::CommunicationError => e
         
     | 
| 
      
 21 
     | 
    
         
            +
                  if e.code == 404
         
     | 
| 
      
 22 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 23 
     | 
    
         
            +
                  else
         
     | 
| 
      
 24 
     | 
    
         
            +
                    raise e
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
       11 
28 
     | 
    
         
             
              end
         
     | 
| 
       12 
29 
     | 
    
         
             
            end
         
     | 
| 
         @@ -4,7 +4,6 @@ module Mailjet 
     | 
|
| 
       4 
4 
     | 
    
         
             
                self.resource_path = 'REST/newsletter'
         
     | 
| 
       5 
5 
     | 
    
         
             
                self.public_operations = [:get, :put, :post]
         
     | 
| 
       6 
6 
     | 
    
         
             
                self.filters = [:campaign, :contacts_list, :delivered_at, :edit_mode, :is_archived, :is_campaign, :is_deleted, :is_handled, :is_starred, :modified, :news_letter_template, :segmentation, :status, :subject]
         
     | 
| 
       7 
     | 
    
         
            -
                self.resourceprop = [:callback, :campaign, :contacts_list, :created_at, :delivered_at, :edit_mode, :edit_type, :footer, :footer_address, :footer_wysiwyg_type, :header_filename, :header_link, :header_text, :header_url, :id, :ip, :is_handled, :is_starred, :is_text_part_included, :locale, :modified_at, :permalink, :permalink_host, :permalink_wysiwyg_type, :politeness_mode, :reply_email, :segmentation, :sender, :sender_email, :sender_name, :status, :subject, :template, :test_address, :title, :url, 'CampaignID', 'CampaignALT', 'ContactsListID', 'ContactsListALT', 'SegmentationID', 'SegmentationALT', :contacts_list_id]
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
                self.resourceprop = [:callback, :campaign, :contacts_list, :created_at, :delivered_at, :edit_mode, :edit_type, :footer, :footer_address, :footer_wysiwyg_type, :header_filename, :header_link, :header_text, :header_url, :id, :ip, :is_handled, :is_starred, :is_text_part_included, :locale, :modified_at, :permalink, :permalink_host, :permalink_wysiwyg_type, :politeness_mode, :reply_email, :segmentation, :segmentation_id, :sender, :sender_email, :sender_name, :status, :subject, :template, :test_address, :title, :url, 'CampaignID', 'CampaignALT', 'ContactsListID', 'ContactsListALT', 'SegmentationID', 'SegmentationALT', :contacts_list_id]
         
     | 
| 
       9 
8 
     | 
    
         
             
              end
         
     | 
| 
       10 
9 
     | 
    
         
             
            end
         
     | 
| 
         @@ -8,5 +8,22 @@ module Mailjet 
     | 
|
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
                self.read_only = true
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
      
 11 
     | 
    
         
            +
                def self.find(id, job_id = nil, options = {})
         
     | 
| 
      
 12 
     | 
    
         
            +
                  opts = define_options(options)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  self.resource_path = create_action_resource_path(id, job_id) if self.action
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  raw_data = parse_api_json(connection(opts)[id].get(default_headers).body)
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  raw_data.map do |entity|
         
     | 
| 
      
 18 
     | 
    
         
            +
                    instanciate_from_api(entity)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
                rescue Mailjet::CommunicationError => e
         
     | 
| 
      
 21 
     | 
    
         
            +
                  if e.code == 404
         
     | 
| 
      
 22 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 23 
     | 
    
         
            +
                  else
         
     | 
| 
      
 24 
     | 
    
         
            +
                    raise e
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
       11 
28 
     | 
    
         
             
              end
         
     | 
| 
       12 
29 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,33 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Mailjet
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Statcounters
         
     | 
| 
      
 3 
     | 
    
         
            +
                include Mailjet::Resource
         
     | 
| 
      
 4 
     | 
    
         
            +
                self.resource_path = 'REST/statcounters'
         
     | 
| 
      
 5 
     | 
    
         
            +
                self.public_operations = [:get]
         
     | 
| 
      
 6 
     | 
    
         
            +
                self.filters = [:source_id, :counter_resolution, :counter_source, :counter_timing]
         
     | 
| 
      
 7 
     | 
    
         
            +
                self.resourceprop = [
         
     | 
| 
      
 8 
     | 
    
         
            +
                  :api_key_id,
         
     | 
| 
      
 9 
     | 
    
         
            +
                  :event_click_delay,
         
     | 
| 
      
 10 
     | 
    
         
            +
                  :event_clicked_count,
         
     | 
| 
      
 11 
     | 
    
         
            +
                  :event_open_delay,
         
     | 
| 
      
 12 
     | 
    
         
            +
                  :event_opened_count,
         
     | 
| 
      
 13 
     | 
    
         
            +
                  :event_spam_count,
         
     | 
| 
      
 14 
     | 
    
         
            +
                  :event_unsubscribed_count,
         
     | 
| 
      
 15 
     | 
    
         
            +
                  :event_workflow_exited_count,
         
     | 
| 
      
 16 
     | 
    
         
            +
                  :message_blocked_count,
         
     | 
| 
      
 17 
     | 
    
         
            +
                  :message_clicked_count,
         
     | 
| 
      
 18 
     | 
    
         
            +
                  :message_deferred_count,
         
     | 
| 
      
 19 
     | 
    
         
            +
                  :message_hard_bounced_count,
         
     | 
| 
      
 20 
     | 
    
         
            +
                  :message_opened_count,
         
     | 
| 
      
 21 
     | 
    
         
            +
                  :message_queued_count,
         
     | 
| 
      
 22 
     | 
    
         
            +
                  :message_sent_count,
         
     | 
| 
      
 23 
     | 
    
         
            +
                  :message_soft_bounced_count,
         
     | 
| 
      
 24 
     | 
    
         
            +
                  :message_spam_count,
         
     | 
| 
      
 25 
     | 
    
         
            +
                  :message_unsubscribed_count,
         
     | 
| 
      
 26 
     | 
    
         
            +
                  :message_work_flow_exited_count,
         
     | 
| 
      
 27 
     | 
    
         
            +
                  :source_id,
         
     | 
| 
      
 28 
     | 
    
         
            +
                  :timeslice,
         
     | 
| 
      
 29 
     | 
    
         
            +
                  :total,
         
     | 
| 
      
 30 
     | 
    
         
            +
                ]
         
     | 
| 
      
 31 
     | 
    
         
            +
                self.read_only = true
         
     | 
| 
      
 32 
     | 
    
         
            +
              end
         
     | 
| 
      
 33 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,12 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Mailjet
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Statistics_linkclick
         
     | 
| 
      
 3 
     | 
    
         
            +
                include Mailjet::Resource
         
     | 
| 
      
 4 
     | 
    
         
            +
                self.resource_path = 'REST/statistics/link-click'
         
     | 
| 
      
 5 
     | 
    
         
            +
                self.public_operations = [:get]
         
     | 
| 
      
 6 
     | 
    
         
            +
                self.filters = [:campaign_id]
         
     | 
| 
      
 7 
     | 
    
         
            +
                self.resourceprop = [:url, :position_index, :clicked_messages_count, :clicked_events_count]
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                self.read_only = true
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,10 +1,26 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Mailjet
         
     | 
| 
       2 
2 
     | 
    
         
             
              class Template_detailcontent
         
     | 
| 
       3 
3 
     | 
    
         
             
                include Mailjet::Resource
         
     | 
| 
       4 
     | 
    
         
            -
                self. 
     | 
| 
       5 
     | 
    
         
            -
                self. 
     | 
| 
      
 4 
     | 
    
         
            +
                self.action = 'detailcontent'
         
     | 
| 
      
 5 
     | 
    
         
            +
                self.resource_path = "REST/template/id/#{self.action}"
         
     | 
| 
      
 6 
     | 
    
         
            +
                self.public_operations = [:get,:post]
         
     | 
| 
       6 
7 
     | 
    
         
             
                self.filters = [:api_key, :categories, :categories_selection_method, :edit_mode, :name, :owner_type, :purposes, :purposes_selection_method, :user]
         
     | 
| 
       7 
8 
     | 
    
         
             
                self.resourceprop = [:author, :categories, :copyright, :description, :edit_mode, :is_starred, :name, :owner_type, :presets, :purposes]
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
      
 10 
     | 
    
         
            +
                def self.find(id, options = {})
         
     | 
| 
      
 11 
     | 
    
         
            +
                  self.resource_path = create_action_resource_path(id)
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  opts = define_options(options)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  response = connection(opts).get(default_headers)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  attributes = parse_api_json(response.body).first
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  instanciate_from_api(attributes)
         
     | 
| 
      
 18 
     | 
    
         
            +
                rescue Mailjet::CommunicationError => e
         
     | 
| 
      
 19 
     | 
    
         
            +
                  if e.code == 404
         
     | 
| 
      
 20 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 21 
     | 
    
         
            +
                  else
         
     | 
| 
      
 22 
     | 
    
         
            +
                    raise e
         
     | 
| 
      
 23 
     | 
    
         
            +
                  end
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
       9 
25 
     | 
    
         
             
              end
         
     | 
| 
       10 
26 
     | 
    
         
             
            end
         
     | 
    
        data/lib/mailjet/version.rb
    CHANGED