class Syncano::Resources::Notifications::Base

Base notification class used for inheritance

Public Class Methods

all(client, scope_parameters = {}, conditions = {}) click to toggle source

Wrapper for api “get” method Returns all objects from Syncano @param [Syncano::Clients::Base] client @param [Hash] scope_parameters @param [Hash] conditions @return [Array] which contains Syncano::Resources::Base objects

# File lib/syncano/resources/notifications/base.rb, line 43
def self.all(client, scope_parameters = {}, conditions = {})
  mapping = {
      new: ::Syncano::Resources::Notifications::Create,
      change: ::Syncano::Resources::Notifications::Update,
      delete: ::Syncano::Resources::Notifications::Destroy,
      message: ::Syncano::Resources::Notifications::Message
  }

  response = perform_all(client, scope_parameters, conditions)
  response.data.to_a.collect do |attributes|
    type = attributes.delete(:type)
    mapping[type.to_sym].new(client, attributes.merge(scope_parameters))
  end
end
create(client, attributes) click to toggle source

Wrapper for api “send” method Creates object in Syncano @param [Syncano::Clients::Base] client @param [Hash] attributes @return [Syncano::Resources::Base]

# File lib/syncano/resources/notifications/base.rb, line 63
def self.create(client, attributes)
  perform_create(client, nil, attributes)
  ::Syncano::Resources::Notifications::Message.new(client, map_to_scope_parameters(attributes))
end
instantize_notification(client, packet) click to toggle source

Proxy method for creating instance of proper subclass @param [Syncano::Clients::Base] client @param [Syncano::Packets::Base] packet @return [Syncano::Notifications::Base]

# File lib/syncano/resources/notifications/base.rb, line 23
def self.instantize_notification(client, packet)
  if packet.message?
    ::Syncano::Resources::Notifications::Message.new(client, packet)
  else
    mapping = {
      new: ::Syncano::Resources::Notifications::Create,
      change: ::Syncano::Resources::Notifications::Update,
      delete: ::Syncano::Resources::Notifications::Destroy
    }

    mapping[packet.type.to_sym].new(client, packet)
  end
end
new(client, attributes) click to toggle source

Constructor for Syncano::Notifications::Base object @param [Syncano::Clients::Base] client @param [Hash] attributes

Calls superclass method Syncano::Resources::Base::new
# File lib/syncano/resources/notifications/base.rb, line 10
def initialize(client, attributes)
  if attributes.is_a?(::Syncano::Packets::Base)
    super(client, {})
    self.attributes = { source: attributes.source, target: attributes.target, data: attributes.data }
  else
    super(client, attributes)
  end
end

Private Class Methods

perform_all(client, scope_parameters, conditions) click to toggle source

Executes proper all request @param [Syncano::Clients::Base] client @param [Hash] scope_parameters @param [Hash] conditions @return [Syncano::Response]

# File lib/syncano/resources/notifications/base.rb, line 79
def self.perform_all(client, scope_parameters, conditions)
  make_request(client, nil, :get_history, conditions.merge(scope_parameters), :history)
end
perform_create(client, batch_client, attributes) click to toggle source

Executes proper create request @param [Syncano::Clients::Base] client @param [Jimson::BatchClient] batch_client @param [Hash] attributes @return [Syncano::Response]

# File lib/syncano/resources/notifications/base.rb, line 88
def self.perform_create(client, batch_client, attributes)
  make_request(client, batch_client, :send, attributes_to_sync(attributes))
end

Private Instance Methods

perform_save(batch_client) click to toggle source

Executes proper save request @param [Jimson::BatchClient] batch_client @return [Syncano::Response]

# File lib/syncano/resources/notifications/base.rb, line 95
def perform_save(batch_client)
  if new_record?
    self.class.perform_create(client, batch_client, attributes)
  end
end