Module: Rentlinx::Amenityable

Included in:
Property, Unit
Defined in:
lib/rentlinx/modules/amenityable.rb

Overview

A module that encapsulates all ammenity related logic for Property and Unit objects. All of these methods can be called on Properties and Units.

TODO: Refactor into BaseAble class along with Linkable and Photoable

Instance Method Summary collapse

Instance Method Details

#add_amenity(options) ⇒ Object

Builds a single amenity and attaches it to the object. This method conveniently assigns the propertyID and unitID (if present) of the parent object, so these need not be passed.

Parameters:

  • options (Hash)

    the attributes for the amenity, defined in PropertyAmenity

Returns:

  • the updated list of amenities on the object



60
61
62
63
64
65
# File 'lib/rentlinx/modules/amenityable.rb', line 60

def add_amenity(options)
  options[:propertyID] = propertyID
  options[:unitID] = unitID if defined? unitID
  @amenities ||= []
  @amenities << amenity_class.new(options)
end

#amenitiesObject

Loads and caches the list of amenities from Rentlinx.

Returns:

  • a list of amenities



30
31
32
33
34
35
36
37
38
39
# File 'lib/rentlinx/modules/amenityable.rb', line 30

def amenities
  return @amenities if @amenities

  @amenities =
    if defined? unitID
      Rentlinx.client.get_amenities_for_unit(self)
    else
      Rentlinx.client.get_amenities_for_property_id(propertyID)
    end
end

#amenities=(amenity_list) ⇒ Object

Allows assignment of amenities to the object.

Parameters:

  • amenity_list (Array)

    an array of amenities

Returns:

  • the list of amenities on the object



45
46
47
48
49
50
51
# File 'lib/rentlinx/modules/amenityable.rb', line 45

def amenities=(amenity_list)
  @amenities = amenity_list.map do |amenity|
    amenity.propertyID = propertyID
    amenity.unitID = unitID if defined? unitID
    amenity
  end
end

#post_amenitiesObject

Posts the object’s amenities



17
18
19
20
21
22
23
24
25
# File 'lib/rentlinx/modules/amenityable.rb', line 17

def post_amenities
  return if @amenities.nil?

  if @amenities.empty?
    Rentlinx.client.unpost_amenities_for(self)
  else
    Rentlinx.client.post_amenities(@amenities)
  end
end

#post_with_amenitiesObject

Posts the object with its associated amenities

TODO: Discuss whether or not these kinds of methods are needed, or whether we should have post do everything every time.



11
12
13
14
# File 'lib/rentlinx/modules/amenityable.rb', line 11

def post_with_amenities
  post
  post_amenities
end