Class: SparkApi::Models::SavedSearch
- Extended by:
- Finders
- Includes:
- Concerns::Destroyable, Concerns::Savable
- Defined in:
- lib/spark_api/models/saved_search.rb
Constant Summary
Constants included from Paginate
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#contacts ⇒ Object
list contacts (private role).
- #favorite? ⇒ Boolean
- #has_active_newsfeed? ⇒ Boolean
- #has_inactive_newsfeed? ⇒ Boolean
- #listing_search_role ⇒ Object
- #listings(args = {}) ⇒ Object
- #newsfeeds ⇒ Object
Methods included from Finders
Methods included from Concerns::Savable
#create!, #params_for_save, #post_data, #save, #save!, #update!, #update_attributes
Methods included from Concerns::Destroyable
#destroy, #destroy!, #destroyed?, included
Methods inherited from Base
connection, #connection, count, element_name, element_name=, first, get, #id, #initialize, #load, #method_missing, #parse_id, path, #path, #persisted?, prefix, prefix=, #resource_uri, #respond_to?, #to_param, #to_partial_path
Methods included from Paginate
#collect, #paginate, #per_page
Methods included from Dirty
#changed, #changed?, #changed_attributes, #changes, #dirty_attributes, #previous_changes
Constructor Details
This class inherits a constructor from SparkApi::Models::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class SparkApi::Models::Base
Class Method Details
.provided ⇒ Object
11 12 13 14 15 16 17 |
# 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 = {}) ⇒ Object
19 20 21 |
# 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 |
Instance Method Details
#contacts ⇒ Object
list contacts (private role)
28 29 30 31 32 |
# 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? ⇒ Boolean
23 24 25 |
# File 'lib/spark_api/models/saved_search.rb', line 23 def favorite? @attributes["Tags"] && @attributes["Tags"].include?( "Favorites") end |
#has_active_newsfeed? ⇒ Boolean
71 72 73 74 75 76 77 78 79 |
# 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? ⇒ Boolean
81 82 83 84 85 86 87 88 89 |
# 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 ⇒ Object
91 92 93 |
# File 'lib/spark_api/models/saved_search.rb', line 91 def listing_search_role :public if path =~ /contact/ end |
#listings(args = {}) ⇒ Object
56 57 58 59 60 |
# 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 ⇒ Object
62 63 64 65 66 67 68 69 |
# 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 |