rentlinx 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d19f3bb23c3ab1ca16eebdb00ec239267df0722
4
- data.tar.gz: 2ef514311063b7ab1f28e7ce1e4f6afc9b74f460
3
+ metadata.gz: 19357d100a6d1f9831a34874d338e756b6e85750
4
+ data.tar.gz: ae7d1c3cba03207c61fb12dc74497aeb227419c3
5
5
  SHA512:
6
- metadata.gz: a89c42aeb4127cbf48554f51dfdc4c3e663141c665bcf7139f54bab5590eed5cd4ae3c594e5a020a502cf43d6808042a898bb7c62f2e9d7528159a282a90d4ee
7
- data.tar.gz: 1101bd08295be7edb2149f4753da148ee0b8681e742fcac8d9a99dd7ea4a34b7f9a6f0be06dc5e5d528a6bb01282835da3b2dbc988b3e35ba14c3f03b2e3be39
6
+ metadata.gz: db9dc683bd829ca60ffa8d73078824591503cc06ceba242c5b0c252fd5edb1f49bb170ea6febb4c706a0372453ee3418d599734465b4c62bce6a5c4f49001990
7
+ data.tar.gz: 8764af15461fd1d0311ddaa14e878cfc0c045222f6e82c0bfef42078d921d21dd3da0c937afff59eb2ccc09b78ebd68bdbb37e7876f406492ef53e5ca72292c2
data/lib/rentlinx.rb CHANGED
@@ -4,6 +4,10 @@ require 'rentlinx/errors'
4
4
  require 'rentlinx/models/base'
5
5
  require 'rentlinx/models/property'
6
6
  require 'rentlinx/models/unit'
7
+ require 'rentlinx/models/property_photo'
8
+ require 'rentlinx/models/unit_photo'
9
+ require 'rentlinx/models/property_amenity'
10
+ require 'rentlinx/models/unit_amenity'
7
11
 
8
12
  module Rentlinx
9
13
  @username = nil
@@ -2,9 +2,18 @@ require 'httpclient'
2
2
  require 'json'
3
3
  require 'uri'
4
4
  require 'rentlinx/default'
5
+ require 'rentlinx/modules/property_client_methods'
6
+ require 'rentlinx/modules/unit_client_methods'
7
+ require 'rentlinx/modules/photo_client_methods'
8
+ require 'rentlinx/modules/amenity_client_methods'
5
9
 
6
10
  module Rentlinx
7
11
  class Client
12
+ include Rentlinx::PropertyClientMethods
13
+ include Rentlinx::UnitClientMethods
14
+ include Rentlinx::PhotoClientMethods
15
+ include Rentlinx::AmenityClientMethods
16
+
8
17
  def initialize
9
18
  raise Rentlinx::NotConfigured if Rentlinx.username.nil? ||
10
19
  Rentlinx.password.nil? ||
@@ -49,13 +58,6 @@ module Rentlinx
49
58
  end
50
59
  end
51
60
 
52
- def get_units_for_property_id(id)
53
- data = request('GET', "properties/#{id}/units")['data']
54
- data.map do |unit_data|
55
- Unit.new(symbolize_data(unit_data))
56
- end
57
- end
58
-
59
61
  private
60
62
 
61
63
  def process_get(route)
@@ -72,24 +74,6 @@ module Rentlinx
72
74
  data
73
75
  end
74
76
 
75
- def post_property(prop)
76
- return false unless prop.valid?
77
- request('PUT', "properties/#{prop.propertyID}", prop.to_hash)
78
- end
79
-
80
- def post_unit(unit)
81
- return false unless unit.valid?
82
- request('PUT', "units/#{unit.unitID}", unit.to_hash)
83
- end
84
-
85
- def unpost_property(id)
86
- request('DELETE', "properties/#{id}")
87
- end
88
-
89
- def unpost_unit(id)
90
- request('DELETE', "units/#{id}")
91
- end
92
-
93
77
  def authenticate(username, password)
94
78
  data = { username: username, password: password }
95
79
  response = request('POST', 'authentication/login', data)
@@ -20,10 +20,6 @@ module Rentlinx
20
20
  self.class::REQUIRED_ATTRIBUTES
21
21
  end
22
22
 
23
- def required_attributes_for_post
24
- self.class::REQUIRED_ATTRIBUTES_FOR_POST
25
- end
26
-
27
23
  def post
28
24
  Rentlinx.client.post(self)
29
25
  end
@@ -40,10 +36,6 @@ module Rentlinx
40
36
  Rentlinx.client.get(type.to_sym, id)
41
37
  end
42
38
 
43
- def get_units_for_property_id(id)
44
- Rentlinx.client.get_units_for_property_id(id)
45
- end
46
-
47
39
  def to_hash
48
40
  {}.tap do |hash|
49
41
  attributes.each do |at|
@@ -56,10 +48,6 @@ module Rentlinx
56
48
  error_messages.empty?
57
49
  end
58
50
 
59
- def valid_for_post?
60
- required_attributes_for_post.none? { |at| blank?(send(at)) }
61
- end
62
-
63
51
  def error_messages
64
52
  @processor = AttributeProcessor.new(to_hash)
65
53
  @processor.process
@@ -1,3 +1,5 @@
1
+ require 'rentlinx/modules/photoable'
2
+
1
3
  module Rentlinx
2
4
  class Property < Base
3
5
  ATTRIBUTES = [:companyID, :propertyID, :description, :address, :city, :state,
@@ -9,8 +11,6 @@ module Rentlinx
9
11
  REQUIRED_ATTRIBUTES = [:propertyID, :address, :city, :state, :zip,
10
12
  :phoneNumber, :emailAddress]
11
13
 
12
- REQUIRED_ATTRIBUTES_FOR_POST = REQUIRED_ATTRIBUTES + [:companyID, :companyName]
13
-
14
14
  attr_accessor(*ATTRIBUTES)
15
15
 
16
16
  def post_with_units
@@ -32,5 +32,16 @@ module Rentlinx
32
32
  def self.from_id(id)
33
33
  get_from_id(:property, id)
34
34
  end
35
+
36
+ include Rentlinx::Photoable
37
+ def photo_class
38
+ Rentlinx::PropertyPhoto
39
+ end
40
+
41
+ private
42
+
43
+ def get_units_for_property_id(id)
44
+ Rentlinx.client.get_units_for_property_id(id)
45
+ end
35
46
  end
36
47
  end
@@ -0,0 +1,13 @@
1
+ module Rentlinx
2
+ class PropertyAmenity < Base
3
+ ATTRIBUTES = [:details, :name, :propertyID]
4
+
5
+ REQUIRED_ATTRIBUTES = [:name, :propertyID]
6
+
7
+ attr_accessor(*ATTRIBUTES)
8
+
9
+ def to_hash
10
+ { details: details, name: name }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Rentlinx
2
+ class PropertyPhoto < Base
3
+ ATTRIBUTES = [:url, :caption, :position, :propertyID, :unitID]
4
+
5
+ REQUIRED_ATTRIBUTES = [:url, :propertyID]
6
+
7
+ attr_accessor(*ATTRIBUTES)
8
+
9
+ def to_hash
10
+ { url: url, caption: caption }
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,5 @@
1
+ require 'rentlinx/modules/photoable'
2
+
1
3
  module Rentlinx
2
4
  class Unit < Base
3
5
  ATTRIBUTES = [:unitID, :propertyID, :name, :description, :rent, :maxRent,
@@ -9,10 +11,17 @@ module Rentlinx
9
11
 
10
12
  REQUIRED_ATTRIBUTES = [:unitID]
11
13
 
12
- REQUIRED_ATTRIBUTES_FOR_POST = REQUIRED_ATTRIBUTES + [:propertyID]
13
-
14
14
  attr_accessor(*ATTRIBUTES)
15
15
 
16
+ include Rentlinx::Photoable
17
+ def photo_class
18
+ Rentlinx::UnitPhoto
19
+ end
20
+
21
+ def photos
22
+ super.select { |p| p.unitID == unitID }
23
+ end
24
+
16
25
  def self.from_id(id)
17
26
  get_from_id(:unit, id)
18
27
  end
@@ -0,0 +1,9 @@
1
+ module Rentlinx
2
+ class UnitAmenity < PropertyAmenity
3
+ ATTRIBUTES += [:unitID]
4
+
5
+ REQUIRED_ATTRIBUTES += [:unitID]
6
+
7
+ attr_accessor(*ATTRIBUTES)
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Rentlinx
2
+ class UnitPhoto < PropertyPhoto
3
+ REQUIRED_ATTRIBUTES += [:unitID]
4
+ end
5
+ end
@@ -0,0 +1,74 @@
1
+ module Rentlinx
2
+ module AmenityClientMethods
3
+ def post_amenities(amenities)
4
+ raise Rentlinx::InvalidObject, amenities.find { |a| !a.valid? } unless amenities.all?(&:valid?)
5
+ raise Rentlinx::InvalidObject, amenities unless amenities.all? { |p| p.propertyID == amenities.first.propertyID }
6
+ property_amenities = amenities.select { |p| p.class == Rentlinx::PropertyAmenity }
7
+ unit_amenities = amenities - property_amenities
8
+
9
+ post_property_amenities(property_amenities) unless property_amenities.empty?
10
+ post_unit_amenities(unit_amenities) unless unit_amenities.empty?
11
+ end
12
+
13
+ def get_amenities_for_property_id(id)
14
+ data = request('GET', "properties/#{id}/amenities")['data']
15
+ data.map do |amenity_data|
16
+ if amenity_data['unitID'].nil? || amenity_data['unitID'] == ''
17
+ amenity_data.delete('unitID')
18
+ PropertyAmenity.new(symbolize_data(amenity_data))
19
+ else
20
+ UnitAmenity.new(symbolize_data(amenity_data))
21
+ end
22
+ end
23
+ rescue Rentlinx::NotFound
24
+ return []
25
+ end
26
+
27
+ def get_amenities_for_unit(unit)
28
+ amenities = get_amenities_for_property_id(unit.propertyID)
29
+ amenities.select { |a| defined? a.unitID && a.unitID == unit.unitID }
30
+ end
31
+
32
+ def unpost_amenity(amenity)
33
+ case amenity
34
+ when Rentlinx::UnitAmenity
35
+ unpost_unit_amenity(amenity.unitID, amenity.name)
36
+ when Rentlinx::PropertyAmenity
37
+ unpost_property_amenity(amenity.propertyID, amenity.name)
38
+ else
39
+ raise TypeError, "Invalid type: #{type}"
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ # post_amenities should only be called from property or unit, so we don't need
46
+ # to handle multiple properties
47
+ def post_property_amenities(amenities)
48
+ request('PUT', "properties/#{amenities.first.propertyID}/amenities", amenities.map(&:to_hash))
49
+ end
50
+
51
+ def post_unit_amenities(amenities)
52
+ hash = {}
53
+ amenities.each do |p|
54
+ if hash.keys.include?(p.unitID)
55
+ hash[p.unitID] << p
56
+ else
57
+ hash[p.unitID] = [p]
58
+ end
59
+ end
60
+
61
+ hash.each do |unitID, unit_amenities|
62
+ request('PUT', "units/#{unitID}/amenities", unit_amenities.map(&:to_hash))
63
+ end
64
+ end
65
+
66
+ def unpost_property_amenity(id, name)
67
+ request('DELETE', URI.encode("properties/#{id}/amenities/#{name}"))
68
+ end
69
+
70
+ def unpost_unit_amenity(id, name)
71
+ request('DELETE', URI.encode("units/#{id}/amenities/#{name}"))
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,67 @@
1
+ module Rentlinx
2
+ module PhotoClientMethods
3
+ def post_photos(photos)
4
+ return false unless photos.all?(&:valid?)
5
+ return false unless photos.all? { |p| p.propertyID == photos.first.propertyID }
6
+ property_photos = photos.select { |p| p.is_a? Rentlinx::PropertyPhoto }
7
+ unit_photos = photos - property_photos
8
+
9
+ post_property_photos(property_photos) unless property_photos.empty?
10
+ post_unit_photos(unit_photos) unless unit_photos.empty?
11
+ end
12
+
13
+ def get_photos_for_property_id(id)
14
+ data = request('GET', "properties/#{id}/photos")['data']
15
+ data.map do |photo_data|
16
+ if photo_data['unitID'].nil? || photo_data['unitID'] == ''
17
+ photo_data.delete('unitID')
18
+ PropertyPhoto.new(symbolize_data(photo_data))
19
+ else
20
+ UnitPhoto.new(symbolize_data(photo_data))
21
+ end
22
+ end
23
+ end
24
+
25
+ def unpost_photo(photo)
26
+ case photo
27
+ when Rentlinx::PropertyPhoto
28
+ unpost_property_photo(photo.propertyID, photo.url)
29
+ when Rentlinx::UnitPhoto
30
+ unpost_unit_photo(photo.unitID, photo.url)
31
+ else
32
+ raise TypeError, "Invalid type: #{type}"
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ # post_photos should only be called from property or unit, so we don't need
39
+ # to handle multiple properties
40
+ def post_property_photos(photos)
41
+ request('PUT', "properties/#{photos.first.propertyID}/photos", photos.map(&:to_hash))
42
+ end
43
+
44
+ def post_unit_photos(photos)
45
+ hash = {}
46
+ photos.each do |p|
47
+ if hash.keys.include?(p.unitID)
48
+ hash[p.unitID] << p
49
+ else
50
+ hash[p.unitID] = [p]
51
+ end
52
+ end
53
+
54
+ hash.each do |unitID, unit_photos|
55
+ request('PUT', "units/#{unitID}/photos", unit_photos.map(&:to_hash))
56
+ end
57
+ end
58
+
59
+ def unpost_property_photo(id, url)
60
+ request('DELETE', "properties/#{id}/photos", url: url)
61
+ end
62
+
63
+ def unpost_unit_photo(id, url)
64
+ request('DELETE', "units/#{id}/photos", url: url)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,33 @@
1
+ module Rentlinx
2
+ module Photoable
3
+ def post_with_photos
4
+ post
5
+ Rentlinx.client.post_photos(@photos)
6
+ end
7
+
8
+ def photos
9
+ @photos ||= get_photos_for_property_id(propertyID)
10
+ end
11
+
12
+ def photos=(photo_list)
13
+ @photos = photo_list.map do |photo|
14
+ photo.propertyID = propertyID
15
+ photo.unitID = unitID if defined? unitID
16
+ photo
17
+ end
18
+ end
19
+
20
+ def add_photo(options)
21
+ options.merge!(propertyID: propertyID)
22
+ options.merge!(unitID: unitID) if defined? unitID
23
+ @photos ||= []
24
+ @photos << photo_class.new(options)
25
+ end
26
+
27
+ private
28
+
29
+ def get_photos_for_property_id(id)
30
+ Rentlinx.client.get_photos_for_property_id(id)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ module Rentlinx
2
+ module PropertyClientMethods
3
+ def get_units_for_property_id(id)
4
+ data = request('GET', "properties/#{id}/units")['data']
5
+ data.map do |unit_data|
6
+ Unit.new(symbolize_data(unit_data))
7
+ end
8
+ end
9
+
10
+ private
11
+
12
+ def post_property(prop)
13
+ return false unless prop.valid?
14
+ request('PUT', "properties/#{prop.propertyID}", prop.to_hash)
15
+ end
16
+
17
+ def unpost_property(id)
18
+ request('DELETE', "properties/#{id}")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ module Rentlinx
2
+ module UnitClientMethods
3
+ private
4
+
5
+ def post_unit(unit)
6
+ return false unless unit.valid?
7
+ request('PUT', "units/#{unit.unitID}", unit.to_hash)
8
+ end
9
+
10
+ def unpost_unit(id)
11
+ request('DELETE', "units/#{id}")
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Rentlinx
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rentlinx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - AppFolio, Inc.
@@ -66,7 +66,16 @@ files:
66
66
  - lib/rentlinx/errors.rb
67
67
  - lib/rentlinx/models/base.rb
68
68
  - lib/rentlinx/models/property.rb
69
+ - lib/rentlinx/models/property_amenity.rb
70
+ - lib/rentlinx/models/property_photo.rb
69
71
  - lib/rentlinx/models/unit.rb
72
+ - lib/rentlinx/models/unit_amenity.rb
73
+ - lib/rentlinx/models/unit_photo.rb
74
+ - lib/rentlinx/modules/amenity_client_methods.rb
75
+ - lib/rentlinx/modules/photo_client_methods.rb
76
+ - lib/rentlinx/modules/photoable.rb
77
+ - lib/rentlinx/modules/property_client_methods.rb
78
+ - lib/rentlinx/modules/unit_client_methods.rb
70
79
  - lib/rentlinx/validators/attribute_processor_service.rb
71
80
  - lib/rentlinx/validators/base_validator.rb
72
81
  - lib/rentlinx/validators/phone_validator.rb