Sha256: 5099673b7c07fa406b80fd87b3baef00e199477538025fb52d98d015196ce233

Contents?: true

Size: 1.62 KB

Versions: 10

Compression:

Stored size: 1.62 KB

Contents

require 'eloqua/remote_object'

module Eloqua
  
  class Entity < RemoteObject
    
    self.remote_group = :entity

    # Returns an :id indexed list of memberships for contact
    # 
    #     # Example output
    #     {'1' => {:id => '1', :name => 'Contact Group Name', :type => 'ContactGroup}}
    #
    # @return [Hash] Integer => Hash
    def list_memberships
      self.class.list_memberships(id)
    end

    def add_membership(asset)
      asset.add_member(self)
    end

    def remove_membership(asset)
      asset.remove_member(self)
    end

    class << self

      # Returns an :id indexed list of memberships for given contact id
      # 
      #     # Example output
      #     {'1' => {:id => '1', :name => 'Contact Group Name', :type => 'ContactGroup}}
      #
      # @param [String, Integer] contact id
      # @return [Hash] Integer => Hash
      def list_memberships(id)
        memberships = api.list_memberships(remote_type, id)

        if(memberships && !memberships.empty?)
          memberships.inject({}) do |map, membership|
            map[membership[:id]] = membership
            map
          end
        else
          memberships || {}
        end
          
      end

      def where(conditions = nil, fields = [], limit = 200, page = 1)
				if(conditions)
					query = where
					conditions.each do |key, value|
						query.on(key, '=', value)
					end
					query.fields(fields) if fields
					query.limit(limit)
					query.page(page)
					results = query.all
					if(results.blank?)
						false
					else
						results
					end
				else
					Eloqua::Query.new(self)
				end
      end      
    end
    
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
eloqua-1.2.4 lib/eloqua/entity.rb
eloqua-1.2.3 lib/eloqua/entity.rb
eloqua-1.2.2 lib/eloqua/entity.rb
eloqua-1.2.1 lib/eloqua/entity.rb
eloqua-1.2.0 lib/eloqua/entity.rb
eloqua-1.1.4 lib/eloqua/entity.rb
eloqua-1.1.3 lib/eloqua/entity.rb
eloqua-1.1.2 lib/eloqua/entity.rb
eloqua-1.1.1 lib/eloqua/entity.rb
eloqua-1.1.0 lib/eloqua/entity.rb