Class: GoodData::ChannelConfiguration
Constant Summary
collapse
- CHANNEL_CONFIGURATION_PATH =
'/gdc/account/profile/%s/channelConfigurations'
- EMPTY_OBJECT =
{
'channelConfiguration' => {
'configuration' => {
'emailConfiguration' => {
'to' => ''
}
},
'meta' => {
'title' => ''
}
}
}
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
Initializes object instance from raw wire JSON
72
73
74
75
76
77
|
# File 'lib/gooddata/models/channel_configuration.rb', line 72
def initialize(json)
super
@json = json
@to = data['configuration']['emailConfiguration']['to']
@title = data['meta']['title']
end
|
Instance Attribute Details
Returns the value of attribute title.
26
27
28
|
# File 'lib/gooddata/models/channel_configuration.rb', line 26
def title
@title
end
|
Returns the value of attribute to.
26
27
28
|
# File 'lib/gooddata/models/channel_configuration.rb', line 26
def to
@to
end
|
Class Method Details
.[](id = :all, opts = { client: GoodData.connection }) ⇒ Object
.all(opts = { client: GoodData.connection }) ⇒ Object
.create(opts = { client: GoodData.connection }) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/gooddata/models/channel_configuration.rb', line 45
def create(opts = { client: GoodData.connection })
c = GoodData.get_client(opts)
options = { to: c.user.email, title: c.user.email }.merge(opts)
existing_channel = all.find { |channel| channel.to == options[:to] }
return existing_channel if existing_channel
channel = create_object(options)
channel.save
channel
end
|
.create_object(data = {}) ⇒ Object
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/gooddata/models/channel_configuration.rb', line 57
def create_object(data = {})
c = GoodData.get_client(data)
new_data = GoodData::Helpers.deep_dup(EMPTY_OBJECT).tap do |d|
d['channelConfiguration']['configuration']['emailConfiguration']['to'] = data[:to]
d['channelConfiguration']['meta']['title'] = data[:title]
end
c.create(ChannelConfiguration, new_data)
end
|
Instance Method Details
#==(other) ⇒ Object
107
108
109
110
|
# File 'lib/gooddata/models/channel_configuration.rb', line 107
def ==(other)
return false unless [:to, :title].all? { |m| other.respond_to?(m) }
@to == other.to && @title == other.title
end
|
93
94
95
|
# File 'lib/gooddata/models/channel_configuration.rb', line 93
def delete
client.delete uri
end
|
#obj_id ⇒ Object
Also known as:
channel_id
101
102
103
|
# File 'lib/gooddata/models/channel_configuration.rb', line 101
def obj_id
uri.split('/').last
end
|
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/gooddata/models/channel_configuration.rb', line 79
def save
response = if uri
data_to_send = GoodData::Helpers.deep_dup(raw_data).tap do |d|
d['channelConfiguration']['configuration']['emailConfiguration']['to'] = to
d['channelConfiguration']['meta']['title'] = title
end
client.put(uri, data_to_send)
else
client.post(CHANNEL_CONFIGURATION_PATH % client.user.account_setting_id, raw_data)
end
@json = client.get response['channelConfiguration']['meta']['uri']
self
end
|
97
98
99
|
# File 'lib/gooddata/models/channel_configuration.rb', line 97
def uri
data['meta']['uri'] if data && data['meta'] && data['meta']['uri']
end
|