Module: Rentlinx::PhotoClientMethods

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

Overview

Client methods for photos

TODO: Refactor into AttachmentClientMethods

Instance Method Summary collapse

Instance Method Details

#get_photos_for_property_id(id) ⇒ Object



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

def get_photos_for_property_id(id)
  data = request('GET', "properties/#{id}/photos")['data']
  data.map do |photo_data|
    if photo_data['unitID'].nil? || photo_data['unitID'] == ''
      photo_data.delete('unitID')
      PropertyPhoto.new(symbolize_data(photo_data))
    else
      UnitPhoto.new(symbolize_data(photo_data))
    end
  end
end

#post_photos(photos) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rentlinx/modules/photo_client_methods.rb', line 6

def post_photos(photos)
  return if photos.nil?
  raise(Rentlinx::InvalidObject, photos.find { |p| !p.valid? }) unless photos.all?(&:valid?)
  raise(Rentlinx::IncompatibleGroupOfObjectsForPost, 'propertyID') unless photos.all? { |p| p.propertyID == photos.first.propertyID }

  property_photos = photos.select { |p| p.class == Rentlinx::PropertyPhoto }
  unit_photos = photos - property_photos

  post_property_photos(property_photos) unless property_photos.empty?
  post_unit_photos(unit_photos) unless unit_photos.empty?
end

#unpost_photo(photo) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/rentlinx/modules/photo_client_methods.rb', line 41

def unpost_photo(photo)
  case photo
  when Rentlinx::UnitPhoto
    unpost_unit_photo(photo.unitID, photo.url)
  when Rentlinx::PropertyPhoto
    unpost_property_photo(photo.propertyID, photo.url)
  else
    raise TypeError, "Invalid type: #{photo.class}"
  end
end

#unpost_photos_for(object) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/rentlinx/modules/photo_client_methods.rb', line 18

def unpost_photos_for(object)
  case object
  when Rentlinx::Unit
    post_photos_for_unit_id(object.unitID, [])
  when Rentlinx::Property
    post_photos_for_property_id(object.propertyID, [])
  else
    raise TypeError, "Type not permitted: #{object.class}"
  end
end