class GoodData::ScheduledMail

Constants

DEFAULT_OPTS

Public Class Methods

all(options = { :client => GoodData.connection, :project => GoodData.project }) click to toggle source

Method intended to get all objects of that type in a specified project

@param options [Hash] the options hash @option options [Boolean] :full if passed true the subclass can decide to pull in full objects. This is desirable from the usability POV but unfortunately has negative impact on performance so it is not the default @return [Array<GoodData::MdObject> | Array<Hash>] Return the appropriate metadata objects or their representation

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 56
def all(options = { :client => GoodData.connection, :project => GoodData.project })
  query('scheduledMail', ScheduledMail, options)
end
convert_attachment(item, opts) click to toggle source
# File lib/gooddata/models/metadata/scheduled_mail.rb, line 60
def convert_attachment(item, opts)
  if item.is_a?(GoodData::Dashboard)
    {
      dashboardAttachment: GoodData::DashboardAttachment::DEFAULT_OPTS.merge(opts.merge(:uri => item.uri))
    }
  elsif item.is_a?(GoodData::Report)
    {
      reportAttachment: GoodData::ReportAttachment::DEFAULT_OPTS.merge(opts.merge(:uri => item.uri))
    }
  elsif item.is_a?(GoodData::DashboardAttachment)
    item.json
  elsif item.is_a?(GoodData::ReportAttachment)
    item.json
  elsif item.is_a?(Hash)
    item
  elsif item == 'dashboardAttachment'
    {
      dashboardAttachment: GoodData::DashboardAttachment::DEFAULT_OPTS.merge(opts)
    }
  elsif item == 'reportAttachment'
    {
      reportAttachment: GoodData::ReportAttachment::DEFAULT_OPTS.merge(opts)
    }
  end
end
create(options = { :client => GoodData.connection, :project => GoodData.project }) click to toggle source
# File lib/gooddata/models/metadata/scheduled_mail.rb, line 86
def create(options = { :client => GoodData.connection, :project => GoodData.project })
  client = options[:client]
  fail ArgumentError, 'No :client specified' if client.nil?

  p = options[:project]
  fail ArgumentError, 'No :project specified' if p.nil?

  project = client.projects(p)
  fail ArgumentError, 'Wrong :project specified' if project.nil?

  opts = GoodData::ScheduledMail::DEFAULT_OPTS.merge(GoodData::Helpers.symbolize_keys(options))

  scheduled_mail = {
    :scheduledMail => {
      :meta => {
        :title => opts[:title],
        :summary => opts[:summary],
        :tags => opts[:tags],
        :deprecated => opts[:deprecated]
      },
      :content => {
        :when => {
          :recurrency => opts[:recurrency],
          :startDate => opts[:startDate] || opts[:start_date],
          :timeZone => opts[:timeZone] || opts[:time_zone] || opts[:timezone]
        },
        :to => opts[:to].is_a?(Array) ? opts[:to] : [opts[:to]],
        :bcc => opts[:bcc].is_a?(Array) ? opts[:bcc] : [opts[:bcc]],
        :subject => opts[:subject],
        :body => opts[:body]
      }
    }
  }

  attachments = opts[:attachments].map do |attachment|
    key = attachment.keys.first
    body = attachment[key]

    ScheduledMail.convert_attachment(key, body)
  end

  scheduled_mail[:scheduledMail][:content][:attachments] = attachments

  client.create(ScheduledMail, GoodData::Helpers.stringify_keys(scheduled_mail), :project => project)
end

Public Instance Methods

add_attachment(item, opts) click to toggle source

Add attachment

@param [String | Object] item Schedule to add @param [Hash] opts Optional schedule options @return [Array] New list of attachments

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 138
def add_attachment(item, opts)
  attachment = ScheduledMail.convert_attachment(item, opts)
  fail ArgumentError unless attachment

  content['attachments'] << attachment
end
add_attachment!(item, opts) click to toggle source

Add attachment and save

@param [String | Object] item Schedule to add @param [Hash] opts Optional schedule options @return [Array] New list of attachments

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 150
def add_attachment!(item, opts)
  add_attachment(item, opts)
  save!
end
attachments() click to toggle source

Get attachments as objects

@return [Array<GoodData::DashboardAttachment | GoodData::ReportAttachment>] Array of attachments

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 158
def attachments
  content['attachments'].map do |attachment|
    key = attachment.keys.first

    if key == 'dashboardAttachment'
      GoodData::DashboardAttachment.new(self, attachment)
    elsif key == 'reportAttachment'
      GoodData::ReportAttachment.new(self, attachment)
    else
      RuntimeError "Unsupported attachment type: #{key}"
    end
  end
end
body() click to toggle source

Get body

@return [String] Scheduled email body

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 175
def body
  content['body']
end
body=(new_body) click to toggle source

Set body

@param [String] new_body New body to be set @return [String] New body

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 183
def body=(new_body)
  content['body'] = new_body
end
recurrency() click to toggle source

Get recurrency string

@return [String] Recurrency (cron) string

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 190
def recurrency
  content['when']['recurrency']
end
recurrency=(new_recurrency) click to toggle source

Set recurrency

@param [String] new_recurrency New recurrency to be set @return [Hash] New recurrency

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 198
def recurrency=(new_recurrency)
  content['when']['recurrency'] = new_recurrency
end
start_date() click to toggle source

Get start date

@return [String] Start date

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 205
def start_date
  content['when']['startDate']
end
start_date=(new_start_date) click to toggle source

Set start date

@param [String] new_start_date New start date to be set @return [String] New start date

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 213
def start_date=(new_start_date)
  content['when']['startDate'] = new_start_date
end
subject() click to toggle source

Get subject

@return [String] Subject of scheduled email

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 220
def subject
  content['subject']
end
subject=(new_subject) click to toggle source

Set subject

@param [String] new_subject New subject to be set @return [String] New subject

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 228
def subject=(new_subject)
  content['subject'] = new_subject
end
timezone() click to toggle source

Get timezone

@return [String] Timezone

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 235
def timezone
  content['when']['timeZone']
end
timezone=(new_timezone) click to toggle source

Set timezone

@param [String] new_timezone New timezone string to be set @return [String] New timezone

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 243
def timezone=(new_timezone)
  content['when']['timeZone'] = new_timezone
end
to() click to toggle source

Get recipients

@return [String] Recipients of email

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 250
def to
  content['to']
end
to=(new_to) click to toggle source

Set recipients

@param [String|Array<String>] new_to New recipients to be set @return [Array<String>] New recipient list

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 258
def to=(new_to)
  content['to'] = new_to.is_a?(Array) ? new_to : [new_to]
end
when() click to toggle source

Get ‘when’ section

@return [Hash] ‘when’ section from json

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 265
def when
  content['when']
end
when=(new_when) click to toggle source

Set ‘when’ section

@param [Hash] new_when New ‘when’ section to be set @return [Hash] New ‘when’ section

# File lib/gooddata/models/metadata/scheduled_mail.rb, line 273
def when=(new_when)
  content['when'] = new_when
end