Module: Rentlinx::Linkable

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

Overview

A module that encapsulates all link 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 Amenityable and Photoable

Instance Method Summary collapse

Instance Method Details



47
48
49
50
51
52
# File 'lib/rentlinx/modules/linkable.rb', line 47

def add_link(options)
  options[:propertyID] = propertyID
  options[:unitID] = unitID if defined? unitID
  @links ||= []
  @links << link_class.new(options)
end

Loads and caches the list of amenities from Rentlinx.

Returns:

  • a list of amenities



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

def links
  @links ||=
    if defined? unitID
      Rentlinx.client.get_links_for_unit(self)
    else
      Rentlinx.client.get_links_for_property_id(propertyID)
    end
end

#links=(link_list) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/rentlinx/modules/linkable.rb', line 39

def links=(link_list)
  @links = link_list.map do |link|
    link.propertyID = propertyID
    link.unitID = unitID if defined? unitID
    link
  end
end

#post_linksObject

Posts the links for an object



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

def post_links
  return if @links.nil?

  if @links.empty?
    Rentlinx.client.unpost_links_for(self)
  else
    Rentlinx.client.post_links(@links)
  end
end

#post_with_linksObject

Posts the object with associated links

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/linkable.rb', line 11

def post_with_links
  post
  post_links
end