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
-
#get_links_for_property_id(id) ⇒ Object
Gets all the links for a given property, including unit links.
-
#get_links_for_unit(unit) ⇒ Object
Gets all the links for a given unit.
-
#post_links(links) ⇒ Object
Posts an array of links to Rentlinx.
-
#unpost_link(link) ⇒ Object
Unposts a specific link.
-
#unpost_links_for(object) ⇒ Object
Unposts all links for unit or property by posting an empty array to the batch update endpoint.
Instance Method Details
#get_links_for_property_id(id) ⇒ Object
Gets all the links for a given property, including unit links
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 |
#get_links_for_unit(unit) ⇒ Object
Gets all the links for a given unit
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.
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 |
#unpost_link(link) ⇒ Object
Unposts a specific link
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 |
#unpost_links_for(object) ⇒ Object
Unposts all links for unit or property by posting an empty array to the batch update endpoint
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 |