sendgrid 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/sendgrid.rb +21 -11
  3. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/lib/sendgrid.rb CHANGED
@@ -107,7 +107,7 @@ module SendGrid
107
107
  # Sets the custom X-SMTPAPI header before sending the email
108
108
  def perform_delivery_smtp(mail)
109
109
  puts "SendGrid X-SMTPAPI: #{sendgrid_json_headers(mail)}" if Object.const_defined?("SENDGRID_DEBUG_OUTPUT") && SENDGRID_DEBUG_OUTPUT
110
- headers['X-SMTPAPI'] = sendgrid_json_headers(mail)
110
+ mail['X-SMTPAPI'] = sendgrid_json_headers(mail)
111
111
  super
112
112
  end
113
113
 
@@ -126,24 +126,27 @@ module SendGrid
126
126
  header_opts[:category] = self.class.default_sg_category
127
127
  end
128
128
 
129
- # Set enables
129
+ # Set enables/disables
130
130
  header_opts[:filters] = {} unless header_opts.has_key?(:filters)
131
- if (@sg_options && !@sg_options.empty?) || (@sg_disabled_options && !@sg_disabled_options.empty?)
131
+ enabled_opts = []
132
+ if @sg_options && !@sg_options.empty?
132
133
  # merge the options so that the instance-level "overrides"
133
- merged = self.class.default_sg_options
134
- merged += @sg_options if @sg_options
135
- merged.reject! { |option| @sg_disabled_options.include?(option) } if @sg_disabled_options
136
- header_opts[:filters] = filters_hash_from_options(merged)
137
- else
138
- header_opts[:filters] = filters_hash_from_options(self.class.default_sg_options)
134
+ merged = self.class.default_sg_options || []
135
+ merged += @sg_options
136
+ enabled_opts = merged
137
+ elsif self.class.default_sg_options
138
+ enabled_opts = self.class.default_sg_options
139
+ end
140
+ if !enabled_opts.empty? || (@sg_disabled_options && !@sg_disabled_options.empty?)
141
+ header_opts[:filters] = filters_hash_from_options(enabled_opts, @sg_disabled_options)
139
142
  end
140
143
 
141
144
  header_opts.to_json
142
145
  end
143
146
 
144
- def filters_hash_from_options(opts)
147
+ def filters_hash_from_options(enabled_opts, disabled_opts)
145
148
  filters = {}
146
- opts.each do |opt|
149
+ enabled_opts.each do |opt|
147
150
  filters[opt] = {'settings' => {'enable' => 1}}
148
151
  case opt.to_sym
149
152
  when :subscriptiontrack
@@ -170,6 +173,13 @@ module SendGrid
170
173
  end
171
174
  end
172
175
  end
176
+
177
+ if disabled_opts
178
+ disabled_opts.each do |opt|
179
+ filters[opt] = {'settings' => {'enable' => 0}}
180
+ end
181
+ end
182
+
173
183
  return filters
174
184
  end
175
185
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Blankenship