Class: GoodData::ScheduledMail
- Inherits:
-
MdObject
- Object
- Rest::Object
- Rest::Resource
- MdObject
- GoodData::ScheduledMail
- Includes:
- Mixin::Lockable
- Defined in:
- lib/gooddata/models/metadata/scheduled_mail.rb
Constant Summary collapse
- DEFAULT_OPTS =
{ # Meta options :title => 'Scheduled report example', :summary => 'Daily at 12:00pm PT', :tags => '', :deprecated => 0, # Content When options :recurrency => '0:0:0:12:0:0', :startDate => '2012-06-05', :timeZone => 'America/Los_Angeles', # Content Email options :to => [], :bcc => [], :subject => 'Scheduled Report', :body => "Hey, I'm sending you new Reports and Dashboards!", # Attachments :attachments => [] }
Constants inherited from MdObject
MdObject::IDENTIFIERS_CFG, MdObject::MD_OBJ_CTG
Constants included from Mixin::MdIdToUri
Mixin::MdIdToUri::IDENTIFIERS_CFG
Constants included from Mixin::MdObjectIndexer
Mixin::MdObjectIndexer::MD_OBJ_CTG
Instance Attribute Summary
Attributes inherited from Rest::Object
Class Method Summary collapse
-
.all(options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::MdObject> | Array<Hash>
Method intended to get all objects of that type in a specified project.
- .convert_attachment(item, opts) ⇒ Object
- .create(options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Object
Instance Method Summary collapse
-
#add_attachment(item, opts) ⇒ Array
Add attachment.
-
#add_attachment!(item, opts) ⇒ Array
Add attachment and save.
-
#attachments ⇒ Array<GoodData::DashboardAttachment | GoodData::ReportAttachment>
Get attachments as objects.
-
#body ⇒ String
Get body.
-
#body=(new_body) ⇒ String
Set body.
-
#recurrency ⇒ String
Get recurrency string.
-
#recurrency=(new_recurrency) ⇒ Hash
Set recurrency.
-
#start_date ⇒ String
Get start date.
-
#start_date=(new_start_date) ⇒ String
Set start date.
-
#subject ⇒ String
Get subject.
-
#subject=(new_subject) ⇒ String
Set subject.
-
#timezone ⇒ String
Get timezone.
-
#timezone=(new_timezone) ⇒ String
Set timezone.
-
#to ⇒ String
Get recipients.
-
#to=(new_to) ⇒ Array<String>
Set recipients.
-
#when ⇒ Hash
Get 'when' section.
-
#when=(new_when) ⇒ Hash
Set 'when' section.
Methods included from Mixin::Lockable
#lock, #lock!, #lock_with_dependencies!, #locked?, #unlock, #unlock!, #unlock_with_dependencies!, #unlocked?
Methods inherited from MdObject
#==, #add_tag, #browser_uri, #delete, #deprecated, #deprecated=, find_replaceable_values, #initialize, #listed?, #project, #reload!, #remove_tag, replace, #replace, #replace!, replace_bracketed, replace_quoted, #save, #save_as, #tag_set, #unlisted, #unlisted=, #validate
Methods included from Mixin::MdIdToUri
Methods included from Mixin::MdObjectIndexer
Methods included from Mixin::MdObjectQuery
#all, #dependency, #dependency?, #query, #usedby, #usedby?, #using, #using?
Methods included from Mixin::MdFinders
#find_by_identifier, #find_by_tag, #find_by_title, #find_first_by_identifier, #find_first_by_title
Methods included from Mixin::MdObjId
Methods included from Mixin::MdGrantees
#change_permission, #grant, #grantees, #revoke
Methods included from Mixin::MdRelations
#dependency, #dependency?, #usedby, #usedby?, #using, #using?
Methods included from Mixin::ObjId
Methods included from Mixin::Links
Methods inherited from Rest::Resource
Methods inherited from Rest::Object
client, default_client, #initialize, #saved?
Methods included from Mixin::DataPropertyReader
Methods included from Mixin::DataPropertyWriter
Methods included from Mixin::MetaPropertyReader
Methods included from Mixin::MetaPropertyWriter
Methods included from Mixin::MetaGetter
Methods included from Mixin::DataGetter
Methods included from Mixin::RootKeyGetter
Methods included from Mixin::ContentGetter
Constructor Details
This class inherits a constructor from GoodData::MdObject
Class Method Details
.all(options = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::MdObject> | Array<Hash>
Method intended to get all objects of that type in a specified project
53 54 55 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 53 def all( = { :client => GoodData.connection, :project => GoodData.project }) query('scheduledMail', ScheduledMail, ) end |
.convert_attachment(item, opts) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 57 def (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 }) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 83 def create( = { :client => GoodData.connection, :project => GoodData.project }) client = [:client] fail ArgumentError, 'No :client specified' if client.nil? p = [: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()) 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] } } } = opts[:attachments].map do || key = .keys.first body = [key] ScheduledMail.(key, body) end scheduled_mail[:scheduledMail][:content][:attachments] = client.create(ScheduledMail, GoodData::Helpers.stringify_keys(scheduled_mail), :project => project) end |
Instance Method Details
#add_attachment(item, opts) ⇒ Array
Add attachment
135 136 137 138 139 140 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 135 def (item, opts) = ScheduledMail.(item, opts) fail ArgumentError unless content['attachments'] << end |
#add_attachment!(item, opts) ⇒ Array
Add attachment and save
147 148 149 150 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 147 def (item, opts) (item, opts) save! end |
#attachments ⇒ Array<GoodData::DashboardAttachment | GoodData::ReportAttachment>
Get attachments as objects
155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 155 def content['attachments'].map do || key = .keys.first if key == 'dashboardAttachment' GoodData::DashboardAttachment.new(self, ) elsif key == 'reportAttachment' GoodData::ReportAttachment.new(self, ) else RuntimeError "Unsupported attachment type: #{key}" end end end |
#body ⇒ String
Get body
172 173 174 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 172 def body content['body'] end |
#body=(new_body) ⇒ String
Set body
180 181 182 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 180 def body=(new_body) content['body'] = new_body end |
#recurrency ⇒ String
Get recurrency string
187 188 189 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 187 def recurrency content['when']['recurrency'] end |
#recurrency=(new_recurrency) ⇒ Hash
Set recurrency
195 196 197 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 195 def recurrency=(new_recurrency) content['when']['recurrency'] = new_recurrency end |
#start_date ⇒ String
Get start date
202 203 204 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 202 def start_date content['when']['startDate'] end |
#start_date=(new_start_date) ⇒ String
Set start date
210 211 212 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 210 def start_date=(new_start_date) content['when']['startDate'] = new_start_date end |
#subject ⇒ String
Get subject
217 218 219 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 217 def subject content['subject'] end |
#subject=(new_subject) ⇒ String
Set subject
225 226 227 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 225 def subject=(new_subject) content['subject'] = new_subject end |
#timezone ⇒ String
Get timezone
232 233 234 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 232 def timezone content['when']['timeZone'] end |
#timezone=(new_timezone) ⇒ String
Set timezone
240 241 242 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 240 def timezone=(new_timezone) content['when']['timeZone'] = new_timezone end |
#to ⇒ String
Get recipients
247 248 249 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 247 def to content['to'] end |
#to=(new_to) ⇒ Array<String>
Set recipients
255 256 257 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 255 def to=(new_to) content['to'] = new_to.is_a?(Array) ? new_to : [new_to] end |
#when ⇒ Hash
Get 'when' section
262 263 264 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 262 def when content['when'] end |
#when=(new_when) ⇒ Hash
Set 'when' section
270 271 272 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 270 def when=(new_when) content['when'] = new_when end |