class SparkApi::Models::SavedSearch

Public Class Methods

provided() click to toggle source
# File lib/spark_api/models/saved_search.rb, line 11
def self.provided()
  Class.new(self).tap do |provided|
    provided.element_name = '/savedsearches'
    provided.prefix = '/provided'
    SparkApi.logger.info("#{self.name}.path: #{provided.path}")
  end
end
tagged(tag, arguments={}) click to toggle source
# File lib/spark_api/models/saved_search.rb, line 19
def self.tagged(tag, arguments={})
  collect(connection.get("/#{self.element_name}/tags/#{tag}", arguments))
end

Public Instance Methods

contacts() click to toggle source

list contacts (private role)

# File lib/spark_api/models/saved_search.rb, line 28
def contacts
  return [] unless persisted?
  results = connection.get("#{self.class.path}/#{@attributes["Id"]}")
  @attributes['ContactIds'] = results.first['ContactIds']
end
favorite?() click to toggle source
# File lib/spark_api/models/saved_search.rb, line 23
def favorite?
  @attributes["Tags"] && @attributes["Tags"].include?( "Favorites")
end
has_active_newsfeed?() click to toggle source
# File lib/spark_api/models/saved_search.rb, line 71
def has_active_newsfeed?
  if self.respond_to? "NewsFeedSubscriptionSummary"
    self.NewsFeedSubscriptionSummary['ActiveSubscription']
  else
    search = connection.get "#{self.class.path}/#{@attributes['Id']}", 
      {"_expand" => "NewsFeedSubscriptionSummary"}
    search.first["NewsFeedSubscriptionSummary"]["ActiveSubscription"]
  end
end
has_inactive_newsfeed?() click to toggle source
# File lib/spark_api/models/saved_search.rb, line 81
def has_inactive_newsfeed?
  if self.respond_to?("NewsFeeds") && self.respond_to?("NewsFeedSubscriptionSummary")
    self.NewsFeeds.any? && !self.NewsFeedSubscriptionSummary['ActiveSubscription']
  else
    search = connection.get("#{self.class.path}/#{@attributes['Id']}", 
      {"_expand" => "NewsFeedSubscriptionSummary, NewsFeeds"}).first
    search["NewsFeeds"].any? && !search["NewsFeedSubscriptionSummary"]["ActiveSubscription"]
  end
end
listing_search_role() click to toggle source
# File lib/spark_api/models/saved_search.rb, line 91
def listing_search_role
  :public if path =~ /contact/
end
listings(args = {}) click to toggle source
# File lib/spark_api/models/saved_search.rb, line 56
def listings(args = {})
  arguments = {:_filter => "SavedSearch Eq '#{self.Id}'"}
  arguments.merge!(:RequestMode => 'permissive') if Provided?
  @listings ||= Listing.collect(connection.get("/listings", arguments.merge(args)))
end
newsfeeds() click to toggle source
# File lib/spark_api/models/saved_search.rb, line 62
def newsfeeds
  @newsfeeds ||=  if attributes.key?("NewsFeeds")
                    Newsfeed.collect(attributes["NewsFeeds"])
                  else
                    Newsfeed.collect(connection.get("#{self.class.path}/#{@attributes["Id"]}", 
                      :_expand => "NewsFeeds").first["NewsFeeds"])
                  end
end

Private Instance Methods

resource_pluralized() click to toggle source
# File lib/spark_api/models/saved_search.rb, line 97
def resource_pluralized; "SavedSearches" end
update_contacts(method, contact_id) click to toggle source
# File lib/spark_api/models/saved_search.rb, line 99
def update_contacts(method, contact_id)
  @attributes['ContactIds'] = [] if @attributes['ContactIds'].nil?
  case method
  when :attach
    @attributes['ContactIds'] << contact_id
  when :detach
    @attributes['ContactIds'].delete contact_id
  end
end