Module: Rentlinx::LinkClientMethods

Included in:
Client
Defined in:
lib/rentlinx/modules/link_client_methods.rb

Overview

Client methods for Amenities

TODO: Refactor into AttachmentClientMethods

Instance Method Summary collapse

Instance Method Details

Gets all the links for a given property, including unit links

Parameters:

  • id (String)

    the id of the property



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rentlinx/modules/link_client_methods.rb', line 45

def get_links_for_property_id(id)
  data = request('GET', "properties/#{id}/links")['data']
  data.map do |link_data|
    if link_data['unitID'].nil? || link_data['unitID'] == ''
      link_data.delete('unitID')
      PropertyLink.new(symbolize_data(link_data))
    else
      UnitLink.new(symbolize_data(link_data))
    end
  end
rescue Rentlinx::NotFound
  return []
end

Gets all the links for a given unit

Parameters:

  • unit (Rentlinx::Unit)

    the unit for which links should be fetched



62
63
64
65
# File 'lib/rentlinx/modules/link_client_methods.rb', line 62

def get_links_for_unit(unit)
  links = get_links_for_property_id(unit.propertyID)
  links.select { |link| defined?(link.unitID) && link.unitID == unit.unitID }
end

#post_links(links) ⇒ Object

Posts an array of links to Rentlinx

This uses the batch endpoint, so all links must be associated with the same property. They can be on different units, so long as all units are on the same property.

Parameters:

  • links (Array)

    an array of links which all have the same propertyID

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rentlinx/modules/link_client_methods.rb', line 13

def post_links(links)
  return if links.nil?

  raise(Rentlinx::InvalidObject, links.find { |a| !a.valid? }) unless links.all?(&:valid?)
  raise(Rentlinx::IncompatibleGroupOfObjectsForPost, 'propertyID') unless links.all? { |p| p.propertyID == links.first.propertyID }

  property_links = links.select { |l| l.class == Rentlinx::PropertyLink }
  unit_links = links - property_links

  post_property_links(property_links) unless property_links.empty?
  post_unit_links(unit_links) unless unit_links.empty?
end

Unposts a specific link

Parameters:



70
71
72
73
74
75
76
77
78
79
# File 'lib/rentlinx/modules/link_client_methods.rb', line 70

def unpost_link(link)
  case link
  when Rentlinx::UnitLink
    unpost_unit_link(link.unitID, link.url)
  when Rentlinx::PropertyLink
    unpost_property_link(link.propertyID, link.url)
  else
    raise TypeError, "Invalid type: #{link.class}"
  end
end

Unposts all links for unit or property by posting an empty array to the batch update endpoint

Parameters:



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

def unpost_links_for(object)
  case object
  when Rentlinx::Unit
    post_links_for_unit_id(object.unitID, [])
  when Rentlinx::Property
    post_links_for_property_id(object.propertyID, [])
  else
    raise TypeError, 'Type not permitted: #{object.class}'
  end
end