Class: GoodData::NotificationRule
Constant Summary
collapse
- NOTIFICATION_RULES_PATH =
'/gdc/projects/%s/dataload/processes/%s/notificationRules'
- EMPTY_OBJECT =
{
'notificationRule' => {
'email' => '',
'subject' => '',
'body' => '',
'events' => []
}
}
Instance Attribute Summary collapse
Attributes inherited from Rest::Object
#client, #json, #project
Class Method Summary
collapse
Instance Method Summary
collapse
client, default_client, #saved?
#data_property_reader
#data_property_writer
#metadata_property_reader
#metadata_property_writer
#meta
#data
#root_key
#content
Constructor Details
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
Returns the value of attribute body.
20
21
22
|
# File 'lib/gooddata/models/notification_rule.rb', line 20
def body
@body
end
|
Returns the value of attribute channels.
21
22
23
|
# File 'lib/gooddata/models/notification_rule.rb', line 21
def channels
@channels
end
|
Returns the value of attribute email.
20
21
22
|
# File 'lib/gooddata/models/notification_rule.rb', line 20
def email
@email
end
|
Returns the value of attribute events.
20
21
22
|
# File 'lib/gooddata/models/notification_rule.rb', line 20
def events
@events
end
|
Returns the value of attribute process.
20
21
22
|
# File 'lib/gooddata/models/notification_rule.rb', line 20
def process
@process
end
|
Returns the value of attribute subject.
20
21
22
|
# File 'lib/gooddata/models/notification_rule.rb', line 20
def subject
@subject
end
|
#subscription ⇒ Object
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
|
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
|
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
|
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
|