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 collapse
-
#newsfeeds ⇒ Object
Returns the value of attribute newsfeeds.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #can_have_newsfeed? ⇒ Boolean
-
#contacts ⇒ Object
list contacts (private role).
- #has_active_newsfeed? ⇒ Boolean
- #has_inactive_newsfeed? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ SavedSearch
constructor
A new instance of SavedSearch.
- #listings(args = {}) ⇒ Object
- #provided_search? ⇒ Boolean
Methods included from Finders
Methods included from Concerns::Savable
#create!, #params_for_save, #post_data, #save, #save!, #update!
Methods included from Concerns::Destroyable
#destroy, #destroy!, #destroyed?
Methods inherited from Base
#connection, connection, count, element_name, element_name=, first, get, #load, #method_missing, #parse_id, #path, path, #persisted?, prefix, prefix=, #resource_uri, #respond_to?
Methods included from Paginate
#collect, #paginate, #per_page
Methods included from Dirty
#changed, #changed?, #changed_attributes, #changes, #dirty_attributes, #previous_changes
Constructor Details
#initialize(attributes = {}) ⇒ SavedSearch
Returns a new instance of SavedSearch.
13 14 15 16 |
# File 'lib/spark_api/models/saved_search.rb', line 13 def initialize(attributes={}) @newsfeeds = nil super(attributes) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class SparkApi::Models::Base
Instance Attribute Details
#newsfeeds ⇒ Object
Returns the value of attribute newsfeeds.
9 10 11 |
# File 'lib/spark_api/models/saved_search.rb', line 9 def newsfeeds @newsfeeds end |
Class Method Details
.provided ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/spark_api/models/saved_search.rb', line 18 def self.provided() Class.new(self).tap do |provided| provided.element_name = '/savedsearches' provided.prefix = '/provided' def provided_search? true end def newsfeeds [] end SparkApi.logger.info("#{self.name}.path: #{provided.path}") end end |
.tagged(tag, arguments = {}) ⇒ Object
32 33 34 |
# File 'lib/spark_api/models/saved_search.rb', line 32 def self.tagged(tag, arguments={}) collect(connection.get("/#{self.element_name}/tags/#{tag}", arguments)) end |
Instance Method Details
#can_have_newsfeed? ⇒ Boolean
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/spark_api/models/saved_search.rb', line 83 def can_have_newsfeed? return false if provided_search? return true if has_active_newsfeed? || has_inactive_newsfeed? # Newsfeed restriction criteria for saved searches: # http://alpha.sparkplatform.com/docs/api_services/newsfeed/restrictions#criteria standard_fields = %w(BathsTotal BedsTotal City CountyOrParish ListPrice Location MlsStatus PostalCode PropertyType RoomsTotal State) number_of_filters = 0 standard_fields.each do |field| number_of_filters += 1 if self.Filter.include? field end number_of_filters >= 3 end |
#contacts ⇒ Object
list contacts (private role)
37 38 39 40 41 |
# File 'lib/spark_api/models/saved_search.rb', line 37 def contacts return [] unless persisted? results = connection.get("#{self.class.path}/#{@attributes["Id"]}") @attributes['ContactIds'] = results.first['ContactIds'] end |
#has_active_newsfeed? ⇒ Boolean
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/spark_api/models/saved_search.rb', line 102 def has_active_newsfeed? return false if provided_search? if self.respond_to? "NewsFeedSubscriptionSummary" self.NewsFeedSubscriptionSummary['ActiveSubscription'] else saved_search = SavedSearch.find( self.Id, {"_expand" => "NewsFeedSubscriptionSummary"}) saved_search.NewsFeedSubscriptionSummary['ActiveSubscription'] end end |
#has_inactive_newsfeed? ⇒ Boolean
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/spark_api/models/saved_search.rb', line 113 def has_inactive_newsfeed? return false if provided_search? if self.respond_to? "NewsFeedSubscriptionSummary" !self.NewsFeedSubscriptionSummary['ActiveSubscription'] else saved_search = SavedSearch.find( self.Id, {"_expand" => "NewsFeedSubscriptionSummary"}) !saved_search.NewsFeedSubscriptionSummary['ActiveSubscription'] end end |
#listings(args = {}) ⇒ Object
65 66 67 68 |
# File 'lib/spark_api/models/saved_search.rb', line 65 def listings(args = {}) arguments = {:_filter => self.Filter}.merge(args) @listings ||= Listing.collect(connection.get("/listings", arguments)) end |
#provided_search? ⇒ Boolean
79 80 81 |
# File 'lib/spark_api/models/saved_search.rb', line 79 def provided_search? false end |