Class: MailService::List

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/services/mail_service/list.rb

Class Method Summary collapse

Class Method Details

.all(options = {}) ⇒ Object



89
90
91
# File 'app/services/mail_service/list.rb', line 89

def self.all(options = {})
  fetch(options)[:data].try(:map, &:with_indifferent_access)
end

.count(options = {}) ⇒ Object



93
94
95
# File 'app/services/mail_service/list.rb', line 93

def self.count(options = {})
  fetch(options)[:total]
end

.exists?(id) ⇒ Boolean

Class Methods


Returns:

  • (Boolean)


78
79
80
# File 'app/services/mail_service/list.rb', line 78

def self.exists?(id)
  find_by_id(id).present?
end

.fetch(options = {}) ⇒ Object



97
98
99
100
101
102
103
104
105
# File 'app/services/mail_service/list.rb', line 97

def self.fetch(options = {})
  begin
    parent.connection.lists.list(options).with_indifferent_access
  rescue => e  
    Rails.logger.info "**[MailService Error][Exists] #{e.message}"   
    Rails.logger.warn "**[MailService Error][Exists] #{e.backtrace.join("\n")}" if Rails.env.development?
    {}
  end
end

.find_by_id(id) ⇒ Object



82
83
84
85
86
87
# File 'app/services/mail_service/list.rb', line 82

def self.find_by_id(id)
  return nil unless id

  response = fetch(filters: { list_id: id }).try(:with_indifferent_access)
  response[:data].try(:map, &:with_indifferent_access).try(:first) if response[:total] == 1
end