Module: Rentlinx::AmenityClientMethods
- Included in:
- Client
- Defined in:
- lib/rentlinx/modules/amenity_client_methods.rb
Overview
Client methods for amenities
TODO: Refactor into AttachmentClientMethods
Instance Method Summary collapse
-
#get_amenities_for_property_id(id) ⇒ Object
Gets all the amenities for a property, dividing them into PropertyAmenity and UnitAmenity objects.
-
#get_amenities_for_unit(unit) ⇒ Object
Gets all the amenities for a unit.
-
#post_amenities(amenities) ⇒ Object
Submits amenities to the batch endpoint on Rentlinx.
-
#unpost_amenities_for(object) ⇒ Object
Unposts all amenities for a unit or property by posting an empty list to the batch update endpoint.
-
#unpost_amenity(amenity) ⇒ Object
Unposts a single amenity.
Instance Method Details
#get_amenities_for_property_id(id) ⇒ Object
Gets all the amenities for a property, dividing them into PropertyAmenity and UnitAmenity objects
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rentlinx/modules/amenity_client_methods.rb', line 42 def get_amenities_for_property_id(id) data = request('GET', "properties/#{id}/amenities")['data'] data.map do |amenity_data| if amenity_data['unitID'].nil? || amenity_data['unitID'] == '' amenity_data.delete('unitID') PropertyAmenity.new(symbolize_data(amenity_data)) else UnitAmenity.new(symbolize_data(amenity_data)) end end rescue Rentlinx::NotFound return [] end |
#get_amenities_for_unit(unit) ⇒ Object
Gets all the amenities for a unit
60 61 62 63 |
# File 'lib/rentlinx/modules/amenity_client_methods.rb', line 60 def get_amenities_for_unit(unit) amenities = get_amenities_for_property_id(unit.propertyID) amenities.select { |a| defined? a.unitID && a.unitID == unit.unitID } end |
#post_amenities(amenities) ⇒ Object
Submits amenities to the batch endpoint on Rentlinx
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rentlinx/modules/amenity_client_methods.rb', line 9 def post_amenities(amenities) return if amenities.nil? raise(Rentlinx::InvalidObject, amenities.find { |a| !a.valid? }) unless amenities.all?(&:valid?) raise(Rentlinx::IncompatibleGroupOfObjectsForPost, 'propertyID') unless amenities.all? { |p| p.propertyID == amenities.first.propertyID } property_amenities = amenities.select { |p| p.class == Rentlinx::PropertyAmenity } unit_amenities = amenities - property_amenities post_property_amenities(property_amenities) unless property_amenities.empty? post_unit_amenities(unit_amenities) unless unit_amenities.empty? end |
#unpost_amenities_for(object) ⇒ Object
Unposts all amenities for a unit or property by posting an empty list to the batch update endpoint.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rentlinx/modules/amenity_client_methods.rb', line 26 def unpost_amenities_for(object) case object when Rentlinx::Unit post_amenities_for_unit_id(object.unitID, []) when Rentlinx::Property post_amenities_for_property_id(object.propertyID, []) else raise TypeError, "Type not permitted: #{object.class}" end end |
#unpost_amenity(amenity) ⇒ Object
Unposts a single amenity
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rentlinx/modules/amenity_client_methods.rb', line 69 def unpost_amenity(amenity) case amenity when Rentlinx::UnitAmenity unpost_unit_amenity(amenity.unitID, amenity.name) when Rentlinx::PropertyAmenity unpost_property_amenity(amenity.propertyID, amenity.name) else raise TypeError, "Invalid type: #{amenity.class}" end end |