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:1*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
Constants included from Mixin::MdObjectQuery
Mixin::MdObjectQuery::ERROR_MESSAGE_NO_PROJECT
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, #get_flag?, #initialize, #listed?, #production, #production=, #project, #reload!, #remove_tag, replace, #replace, #replace!, replace_bracketed, replace_quoted, #restricted, #restricted=, #save, #save_as, #set_flag, #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
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
56 57 58 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 56 def all( = { :client => GoodData.connection, :project => GoodData.project }) query('scheduledMail', ScheduledMail, ) end |
.convert_attachment(item, opts) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 60 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
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 128 129 130 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 86 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
138 139 140 141 142 143 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 138 def (item, opts) = ScheduledMail.(item, opts) fail ArgumentError unless content['attachments'] << end |
#add_attachment!(item, opts) ⇒ Array
Add attachment and save
150 151 152 153 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 150 def (item, opts) (item, opts) save! end |
#attachments ⇒ Array<GoodData::DashboardAttachment | GoodData::ReportAttachment>
Get attachments as objects
158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 158 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
175 176 177 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 175 def body content['body'] end |
#body=(new_body) ⇒ String
Set body
183 184 185 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 183 def body=(new_body) content['body'] = new_body end |
#recurrency ⇒ String
Get recurrency string
190 191 192 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 190 def recurrency content['when']['recurrency'] end |
#recurrency=(new_recurrency) ⇒ Hash
Set recurrency
198 199 200 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 198 def recurrency=(new_recurrency) content['when']['recurrency'] = new_recurrency end |
#start_date ⇒ String
Get start date
205 206 207 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 205 def start_date content['when']['startDate'] end |
#start_date=(new_start_date) ⇒ String
Set start date
213 214 215 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 213 def start_date=(new_start_date) content['when']['startDate'] = new_start_date end |
#subject ⇒ String
Get subject
220 221 222 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 220 def subject content['subject'] end |
#subject=(new_subject) ⇒ String
Set subject
228 229 230 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 228 def subject=(new_subject) content['subject'] = new_subject end |
#timezone ⇒ String
Get timezone
235 236 237 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 235 def timezone content['when']['timeZone'] end |
#timezone=(new_timezone) ⇒ String
Set timezone
243 244 245 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 243 def timezone=(new_timezone) content['when']['timeZone'] = new_timezone end |
#to ⇒ String
Get recipients
250 251 252 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 250 def to content['to'] end |
#to=(new_to) ⇒ Array<String>
Set recipients
258 259 260 |
# 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 ⇒ Hash
Get 'when' section
265 266 267 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 265 def when content['when'] end |
#when=(new_when) ⇒ Hash
Set 'when' section
273 274 275 |
# File 'lib/gooddata/models/metadata/scheduled_mail.rb', line 273 def when=(new_when) content['when'] = new_when end |