Class: MLS::Address

Inherits:
Resource show all
Defined in:
lib/mls/models/address.rb

Defined Under Namespace

Classes: Parser

Instance Attribute Summary collapse

Attributes inherited from Resource

#errors, #persisted

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, #create!, inherited, #initialize, #new_record?, #persisted?, #properties, #properties_excluded_from_comparison, #properties_for_comparison, #save!, #set_default_values, #to_key, #update!, #update_attributes

Constructor Details

This class inherits a constructor from MLS::Resource

Instance Attribute Details

#listing_typesObject

Returns the value of attribute listing_types.



53
54
55
# File 'lib/mls/models/address.rb', line 53

def listing_types
  @listing_types
end

#listingsObject

Returns the value of attribute listings.



53
54
55
# File 'lib/mls/models/address.rb', line 53

def listings
  @listings
end

#photosObject

Returns the value of attribute photos.



53
54
55
# File 'lib/mls/models/address.rb', line 53

def photos
  @photos
end

#videosObject

Returns the value of attribute videos.



53
54
55
# File 'lib/mls/models/address.rb', line 53

def videos
  @videos
end

Class Method Details

.all(options = {}) ⇒ Object

currently supported options are :include, :where, :limit, :offset



134
135
136
137
# File 'lib/mls/models/address.rb', line 134

def all(options={})
  response = MLS.get('/addresses', options)
  MLS::Address::Parser.parse_collection(response.body)
end

.find(id) ⇒ Object



128
129
130
131
# File 'lib/mls/models/address.rb', line 128

def find(id)
  response = MLS.get("/addresses/#{id}")
  MLS::Address::Parser.parse(response.body)
end

.query(q) ⇒ Object



123
124
125
126
# File 'lib/mls/models/address.rb', line 123

def query(q)
  response = MLS.get('/addresses/query', :query => q)
  MLS::Address::Parser.parse_collection(response.body)
end

Instance Method Details

#amenitiesObject



111
112
113
# File 'lib/mls/models/address.rb', line 111

def amenities
  MLS.address_amenities
end

#avatar(size = '100x200#', protocol = 'http') ⇒ Object

should include an optional use address or no_image image



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/mls/models/address.rb', line 56

def avatar(size='100x200#', protocol='http')
  params = {
    :size => size,
    :format => 'png',
    :sensor => false,
    :location => [formatted_address],
    :fov => 120
  }

  if avatar_digest
    "#{protocol}://#{MLS.image_host}/#{avatar_digest}.jpg?s=#{URI.escape(size)}"
  else
    params[:size] = params[:size].match(/\d+x\d+/)[0]
    "#{protocol}://maps.googleapis.com/maps/api/streetview?" + params.map{|k,v| k.to_s + '=' + URI.escape(v.to_s) }.join('&')
  end
end

#find_listings(space_available, floor, unit) ⇒ Object



115
116
117
118
119
# File 'lib/mls/models/address.rb', line 115

def find_listings(space_available, floor, unit)
  response = MLS.get("/addresses/#{id}/find_listings", 
    :floor => floor, :unit => unit, :space_available => space_available)
  MLS::Listing::Parser.parse_collection(response.body)
end

#saveObject



73
74
75
76
77
78
79
80
81
82
# File 'lib/mls/models/address.rb', line 73

def save
  MLS.put("/addresses/#{id}", {:address => to_hash}, 400) do |response, code|
    if code == 200 || code == 400
      MLS::Address::Parser.update(self, response.body)
      code == 200      
    else
      raise MLS::Exception::UnexpectedResponse, code
    end
  end
end

#to_hashObject



84
85
86
87
88
89
# File 'lib/mls/models/address.rb', line 84

def to_hash
  hash = super
  hash[:photo_ids] = photos.map(&:id) if photos
  hash[:videos_attributes] = videos.map(&:to_hash) unless videos.blank?
  hash
end

#to_paramObject



91
92
93
# File 'lib/mls/models/address.rb', line 91

def to_param
  [state, city, "#{street_number} #{street}"].map(&:parameterize).join('/')
end

#urlObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/mls/models/address.rb', line 95

def url
  if defined? Rails
    case Rails.env
    when "production"
      host = "42floors.com"
    when "staging"
      host = "staging.42floors.com"
    when "development","test"
      host = "spire.dev"
    end
  else
    host = "42floors.com"
  end
  "http://#{host}/#{slug}"
end