Class: GoodData::NotificationRule
- Inherits:
-
Rest::Resource
- Object
- Rest::Object
- Rest::Resource
- GoodData::NotificationRule
- Defined in:
- lib/gooddata/models/notification_rule.rb
Constant Summary collapse
- NOTIFICATION_RULES_PATH =
'/gdc/projects/%s/dataload/processes/%s/notificationRules'
- EMPTY_OBJECT =
{ 'notificationRule' => { 'email' => '', 'subject' => '', 'body' => '', 'events' => [] } }
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#email ⇒ Object
Returns the value of attribute email.
-
#events ⇒ Object
Returns the value of attribute events.
-
#process ⇒ Object
Returns the value of attribute process.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#subscription ⇒ Object
readonly
Returns the value of attribute subscription.
Attributes inherited from Rest::Object
Class Method Summary collapse
- .[](id = :all, opts = { client: GoodData.connection }) ⇒ Object
- .all(opts = { client: GoodData.connection }) ⇒ Object
- .create(opts = { client: GoodData.connection }) ⇒ Object
- .create_object(data = {}) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #delete ⇒ Object
-
#initialize(json) ⇒ NotificationRule
constructor
A new instance of NotificationRule.
- #obj_id ⇒ Object (also: #notification_rule_id)
- #save ⇒ Object
- #uri ⇒ Object
Methods inherited from Rest::Object
client, default_client, #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
#initialize(json) ⇒ NotificationRule
Returns a new instance of NotificationRule.
67 68 69 70 71 72 73 74 75 |
# File 'lib/gooddata/models/notification_rule.rb', line 67 def initialize(json) super @json = json @email = data['email'] @subject = data['subject'] @body = data['body'] @events = data['events'] end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
20 21 22 |
# File 'lib/gooddata/models/notification_rule.rb', line 20 def body @body end |
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
21 22 23 |
# File 'lib/gooddata/models/notification_rule.rb', line 21 def channels @channels end |
#email ⇒ Object
Returns the value of attribute email.
20 21 22 |
# File 'lib/gooddata/models/notification_rule.rb', line 20 def email @email end |
#events ⇒ Object
Returns the value of attribute events.
20 21 22 |
# File 'lib/gooddata/models/notification_rule.rb', line 20 def events @events end |
#process ⇒ Object
Returns the value of attribute process.
20 21 22 |
# File 'lib/gooddata/models/notification_rule.rb', line 20 def process @process end |
#subject ⇒ Object
Returns the value of attribute subject.
20 21 22 |
# File 'lib/gooddata/models/notification_rule.rb', line 20 def subject @subject end |
#subscription ⇒ Object (readonly)
Returns the value of attribute subscription.
21 22 23 |
# File 'lib/gooddata/models/notification_rule.rb', line 21 def subscription @subscription end |
Class Method Details
.[](id = :all, opts = { client: GoodData.connection }) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gooddata/models/notification_rule.rb', line 24 def [](id = :all, opts = { client: GoodData.connection }) c = GoodData.get_client(opts) pid = (opts[:project].respond_to?(:pid) && opts[:project].pid) || opts[:project] process_id = (opts[:process].respond_to?(:process_id) && opts[:process].process_id) || opts[:process] uri = NOTIFICATION_RULES_PATH % [pid, process_id] if id == :all data = c.get uri data['notificationRules']['items'].map { |notification_data| c.create(NotificationRule, notification_data) } else c.create(NotificationRule, c.get("#{uri}/#{id}")) end end |
.all(opts = { client: GoodData.connection }) ⇒ Object
37 38 39 |
# File 'lib/gooddata/models/notification_rule.rb', line 37 def all(opts = { client: GoodData.connection }) NotificationRule[:all, opts] end |
.create(opts = { client: GoodData.connection }) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gooddata/models/notification_rule.rb', line 41 def create(opts = { client: GoodData.connection }) [:email, :events, :project, :process].each { |key| fail "No #{key.inspect} specified" unless opts[key] } pid = (opts[:project].respond_to?(:pid) && opts[:project].pid) || opts[:project] process_id = (opts[:process].respond_to?(:process_id) && opts[:process].process_id) || opts[:process] events = (opts[:events].respond_to?(:each) && opts[:events]) || [opts[:events]] notification_rule = create_object({ subject: 'Email subject', body: 'Email body' }.merge(opts).merge(project: pid, process: process_id, events: events)) notification_rule.save notification_rule end |
.create_object(data = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/gooddata/models/notification_rule.rb', line 53 def create_object(data = {}) c = GoodData.get_client(data) new_data = GoodData::Helpers.deep_dup(EMPTY_OBJECT).tap do |d| d['notificationRule']['email'] = data[:email] d['notificationRule']['subject'] = data[:subject] d['notificationRule']['body'] = data[:body] d['notificationRule']['events'] = data[:events] end c.create(NotificationRule, new_data, data) end |
Instance Method Details
#==(other) ⇒ Object
104 105 106 107 |
# File 'lib/gooddata/models/notification_rule.rb', line 104 def ==(other) return false unless [:email, :subject, :body, :events].all? { |m| other.respond_to?(m) } @email == other.email && @subject == other.subject && @body == other.body && @events == other.events end |
#delete ⇒ Object
109 110 111 |
# File 'lib/gooddata/models/notification_rule.rb', line 109 def delete client.delete uri end |
#obj_id ⇒ Object Also known as: notification_rule_id
81 82 83 |
# File 'lib/gooddata/models/notification_rule.rb', line 81 def obj_id uri.split('/').last end |
#save ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/gooddata/models/notification_rule.rb', line 87 def save response = if uri data_to_send = GoodData::Helpers.deep_dup(EMPTY_OBJECT).tap do |d| d['notificationRule']['email'] = email d['notificationRule']['subject'] = subject d['notificationRule']['body'] = body d['notificationRule']['events'] = (events.respond_to?(:each) && events) || events end client.put(uri, data_to_send) else client.post(NOTIFICATION_RULES_PATH % [project, process], raw_data) end @json = client.get response['notificationRule']['links']['self'] @subscription = data['links']['subscription'] @channels = data['links']['channels'] end |
#uri ⇒ Object
77 78 79 |
# File 'lib/gooddata/models/notification_rule.rb', line 77 def uri data['links']['self'] if data && data['links'] && data['links']['self'] end |