Class: YouGotListed::Listings::SearchResponse

Inherits:
Response
  • Object
show all
Defined in:
lib/you_got_listed/listings.rb

Instance Attribute Summary collapse

Attributes inherited from Response

#ygl_response

Instance Method Summary collapse

Methods inherited from Response

#method_missing, #success?

Constructor Details

#initialize(response, client, limit = 20, raise_error = false) ⇒ SearchResponse



68
69
70
71
72
# File 'lib/you_got_listed/listings.rb', line 68

def initialize(response, client, limit = 20, raise_error = false)
  super(response, raise_error)
  self.limit = limit
  self.client = client
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class YouGotListed::Response

Instance Attribute Details

#clientObject

Returns the value of attribute client.



66
67
68
# File 'lib/you_got_listed/listings.rb', line 66

def client
  @client
end

#limitObject

Returns the value of attribute limit.



66
67
68
# File 'lib/you_got_listed/listings.rb', line 66

def limit
  @limit
end

Instance Method Details

#mls_results?Boolean



90
91
92
# File 'lib/you_got_listed/listings.rb', line 90

def mls_results?
  @has_mls_properties ||= properties.any?{|property| property.mls_listing?}
end

#paginatorObject



94
95
96
97
98
99
100
101
# File 'lib/you_got_listed/listings.rb', line 94

def paginator
  @paginator_cache ||= WillPaginate::Collection.create(
    (self.ygl_response.page_index ? self.ygl_response.page_index : 1),
    self.limit,
    (self.ygl_response.total ? self.ygl_response.total : properties.size)) do |pager|
    pager.replace properties
  end
end

#propertiesObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/you_got_listed/listings.rb', line 74

def properties
  @cached_properties ||= begin
    props = []
    if self.success? && !self.ygl_response.listings.blank?
      if self.ygl_response.listings.listing.is_a?(Array)
        self.ygl_response.listings.listing.each do |listing|
          props << YouGotListed::Listing.new(listing, self.client)
        end
      else
        props << YouGotListed::Listing.new(self.ygl_response.listings.listing, self.client)
      end
    end
    props
  end
end