Class: Osm::Email::DeliveryReport::Recipient

Inherits:
Model
  • Object
show all
Defined in:
lib/osm/email.rb,
lib/osm/email.rb

Overview

Ensure class exists for definition of validations

Constant Summary collapse

SORT_BY =
[:delivery_report, :id]
VALID_STATUSES =
Osm::Email::DeliveryReport::VALID_STATUSES.clone

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#<, #<=, #<=>, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i

Constructor Details

#initializeObject

Initialize a new DeliveryReport::Recipient

Parameters:

  • attributes (Hash)

    The hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)



# File 'lib/osm/email.rb', line 255

Instance Attribute Details

#addressString

Returns the email address of the recipient.

Returns:

  • (String)

    the email address of the recipient



238
# File 'lib/osm/email.rb', line 238

attribute :id, type: Integer

#delivery_reportOsm::Email::DeliveryReport

Returns the report this recipient belongs to.

Returns:



238
# File 'lib/osm/email.rb', line 238

attribute :id, type: Integer

#idFixnum

Returns the id of the email recipient.

Returns:

  • (Fixnum)

    the id of the email recipient



238
# File 'lib/osm/email.rb', line 238

attribute :id, type: Integer

#member_idFixnum

Returns the id of the member the email was sent to.

Returns:

  • (Fixnum)

    the id of the member the email was sent to



238
# File 'lib/osm/email.rb', line 238

attribute :id, type: Integer

#statusSymbol

Returns the status of the email sent to the recipient.

Returns:

  • (Symbol)

    the status of the email sent to the recipient



238
# File 'lib/osm/email.rb', line 238

attribute :id, type: Integer

Instance Method Details

#bounced?Boolean

Check if the email to this recipient bounced

Returns:

  • (Boolean)


306
307
308
309
310
# File 'lib/osm/email.rb', line 306

VALID_STATUSES.each do |attribute|
  define_method "#{attribute}?" do
    status.eql?(attribute)
  end
end

#delivered?Boolean

Check if the email to this recipient was delivered

Returns:

  • (Boolean)


306
307
308
309
310
# File 'lib/osm/email.rb', line 306

VALID_STATUSES.each do |attribute|
  define_method "#{attribute}?" do
    status.eql?(attribute)
  end
end

#get_email(api, options = {}) ⇒ Osm::Email::DeliveryReport::Email

Get email contents for this recipient

Parameters:

  • api (Osm::Api)

    The api to use to make the request

Returns:



264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/osm/email.rb', line 264

def get_email(api, options={})
  Osm::Model.require_access_to_section(api, delivery_report.section_id, options)
  cache_key = ['email_delivery_reports_email', delivery_report.section_id, delivery_report.id, id]

  if !options[:no_cache] && Osm::Model.cache_exist?(api, cache_key)
    return cache_read(api, cache_key)
  end

  email = Osm::Email::DeliveryReport::Email.fetch_from_osm(api, delivery_report.section_id, delivery_report.id, member_id, address)

  cache_write(api, cache_key, email)
  return email
end

#inspectObject



316
317
318
# File 'lib/osm/email.rb', line 316

def inspect
  Osm::inspect_instance(self, {replace_with: {'delivery_report' => :id}})
end

#processed?Boolean

Check if the email to this recipient has been processes

Returns:

  • (Boolean)


306
307
308
309
310
# File 'lib/osm/email.rb', line 306

VALID_STATUSES.each do |attribute|
  define_method "#{attribute}?" do
    status.eql?(attribute)
  end
end

#to_sObject



312
313
314
# File 'lib/osm/email.rb', line 312

def to_s
  "#{address} - #{status}"
end

#unblock_address(api) ⇒ Object

Unblock email address from being sent emails

Parameters:

  • api (Osm::Api)

    The api to use to make the request

  • whether (Boolean)

    removal was successful



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/osm/email.rb', line 281

def unblock_address(api)
  return true unless bounced?

  data = api.perform_query('ext/settings/emails/?action=unBlockEmail', {
    'section_id' => delivery_report.section_id,
    'email'      => address,
    'email_id'   => delivery_report.id
  })

  if data.is_a?(Hash)
    fail Osm::Error, data['error'].to_s unless data['error'].nil?
    return !!data['status']
  end
  return false
end