class GoodData::ChannelConfiguration

Constants

CHANNEL_CONFIGURATION_PATH
EMPTY_OBJECT

Attributes

title[RW]
to[RW]

Public Class Methods

[](id = :all, opts = { client: GoodData.connection }) click to toggle source
# File lib/gooddata/models/channel_configuration.rb, line 29
def [](id = :all, opts = { client: GoodData.connection })
  c = GoodData.get_client(opts)

  uri = CHANNEL_CONFIGURATION_PATH % c.user.account_setting_id
  if id == :all
    data = c.get uri
    data['channelConfigurations']['items'].map { |channel_data| c.create(ChannelConfiguration, channel_data) }
  else
    c.create(ChannelConfiguration, c.get("#{uri}/#{id}"))
  end
end
all(opts = { client: GoodData.connection }) click to toggle source
# File lib/gooddata/models/channel_configuration.rb, line 41
def all(opts = { client: GoodData.connection })
  ChannelConfiguration[:all, opts]
end
create(opts = { client: GoodData.connection }) click to toggle source
# 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 = {}) click to toggle source
# 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
new(json) click to toggle source

Initializes object instance from raw wire JSON

@param json Json used for initialization

Calls superclass method
# 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

Public Instance Methods

==(other) click to toggle source
# 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
channel_id()
Alias for: obj_id
delete() click to toggle source
# File lib/gooddata/models/channel_configuration.rb, line 93
def delete
  client.delete uri
end
obj_id() click to toggle source
# File lib/gooddata/models/channel_configuration.rb, line 101
def obj_id
  uri.split('/').last
end
Also aliased as: channel_id
save() click to toggle source
# 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
uri() click to toggle source
# File lib/gooddata/models/channel_configuration.rb, line 97
def uri
  data['meta']['uri'] if data && data['meta'] && data['meta']['uri']
end