rentlinx 0.6.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rentlinx.rb +2 -0
- data/lib/rentlinx/client.rb +2 -0
- data/lib/rentlinx/models/property.rb +6 -0
- data/lib/rentlinx/models/property_link.rb +13 -0
- data/lib/rentlinx/models/unit.rb +6 -0
- data/lib/rentlinx/models/unit_link.rb +9 -0
- data/lib/rentlinx/modules/amenity_client_methods.rb +1 -1
- data/lib/rentlinx/modules/link_client_methods.rb +72 -0
- data/lib/rentlinx/modules/linkable.rb +38 -0
- data/lib/rentlinx/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e9c6235c8891f0be05e492ba4811f8ea49caefb
|
4
|
+
data.tar.gz: 68324208bc855cc495a4f9e7abc74748b7f26b68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f2e8c07d583ad39c97f246f01c9b0a953509f56e2d37140afee8b88d43fa9d49930265889a38156efc0fb6cdb2d211da27e27a4ffb385e8675ecc94669e970d
|
7
|
+
data.tar.gz: 7bec813c58aac658c954d38fba18440a5772b0a6c2cf06e3ff615725e0a641f19879f255899ffb912057901ea34aede345527384ed66a594733c58465c27d848
|
data/lib/rentlinx.rb
CHANGED
@@ -8,6 +8,8 @@ require 'rentlinx/models/property_photo'
|
|
8
8
|
require 'rentlinx/models/unit_photo'
|
9
9
|
require 'rentlinx/models/property_amenity'
|
10
10
|
require 'rentlinx/models/unit_amenity'
|
11
|
+
require 'rentlinx/models/property_link'
|
12
|
+
require 'rentlinx/models/unit_link'
|
11
13
|
|
12
14
|
module Rentlinx
|
13
15
|
@username = nil
|
data/lib/rentlinx/client.rb
CHANGED
@@ -6,6 +6,7 @@ require 'rentlinx/modules/property_client_methods'
|
|
6
6
|
require 'rentlinx/modules/unit_client_methods'
|
7
7
|
require 'rentlinx/modules/photo_client_methods'
|
8
8
|
require 'rentlinx/modules/amenity_client_methods'
|
9
|
+
require 'rentlinx/modules/link_client_methods'
|
9
10
|
|
10
11
|
module Rentlinx
|
11
12
|
class Client
|
@@ -13,6 +14,7 @@ module Rentlinx
|
|
13
14
|
include Rentlinx::UnitClientMethods
|
14
15
|
include Rentlinx::PhotoClientMethods
|
15
16
|
include Rentlinx::AmenityClientMethods
|
17
|
+
include Rentlinx::LinkClientMethods
|
16
18
|
|
17
19
|
def initialize
|
18
20
|
raise Rentlinx::NotConfigured if Rentlinx.username.nil? ||
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rentlinx/modules/photoable'
|
2
2
|
require 'rentlinx/modules/amenityable'
|
3
|
+
require 'rentlinx/modules/linkable'
|
3
4
|
|
4
5
|
module Rentlinx
|
5
6
|
class Property < Base
|
@@ -44,6 +45,11 @@ module Rentlinx
|
|
44
45
|
Rentlinx::PropertyAmenity
|
45
46
|
end
|
46
47
|
|
48
|
+
include Rentlinx::Linkable
|
49
|
+
def link_class
|
50
|
+
Rentlinx::PropertyLink
|
51
|
+
end
|
52
|
+
|
47
53
|
private
|
48
54
|
|
49
55
|
def get_units_for_property_id(id)
|
data/lib/rentlinx/models/unit.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rentlinx/modules/photoable'
|
2
2
|
require 'rentlinx/modules/amenityable'
|
3
|
+
require 'rentlinx/modules/linkable'
|
3
4
|
|
4
5
|
module Rentlinx
|
5
6
|
class Unit < Base
|
@@ -24,6 +25,11 @@ module Rentlinx
|
|
24
25
|
Rentlinx::UnitAmenity
|
25
26
|
end
|
26
27
|
|
28
|
+
include Rentlinx::Linkable
|
29
|
+
def link_class
|
30
|
+
Rentlinx::UnitLink
|
31
|
+
end
|
32
|
+
|
27
33
|
def photos
|
28
34
|
super.select { |p| p.unitID == unitID }
|
29
35
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Rentlinx
|
2
|
+
module LinkClientMethods
|
3
|
+
def post_links(links)
|
4
|
+
raise Rentlinx::InvalidObject, links.find { |a| !a.valid? } unless links.all?(&:valid?)
|
5
|
+
raise Rentlinx::InvalidObject, links unless links.all? { |p| p.propertyID == links.first.propertyID }
|
6
|
+
property_links = links.select { |l| l.class == Rentlinx::PropertyLink }
|
7
|
+
unit_links = links - property_links
|
8
|
+
|
9
|
+
post_property_links(property_links) unless property_links.empty?
|
10
|
+
post_unit_links(unit_links) unless unit_links.empty?
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_links_for_property_id(id)
|
14
|
+
data = request('GET', "properties/#{id}/links")['data']
|
15
|
+
data.map do |link_data|
|
16
|
+
if link_data['unitID'].nil? || link_data['unitID'] == ''
|
17
|
+
link_data.delete('unitID')
|
18
|
+
PropertyLink.new(symbolize_data(link_data))
|
19
|
+
else
|
20
|
+
UnitLink.new(symbolize_data(link_data))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
rescue Rentlinx::NotFound
|
24
|
+
return []
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_links_for_unit(unit)
|
28
|
+
links = get_links_for_property_id(unit.propertyID)
|
29
|
+
links.select { |a| defined? a.unitID && a.unitID == unit.unitID }
|
30
|
+
end
|
31
|
+
|
32
|
+
def unpost_link(link)
|
33
|
+
case link
|
34
|
+
when Rentlinx::UnitLink
|
35
|
+
unpost_unit_link(link.unitID, link.url)
|
36
|
+
when Rentlinx::PropertyLink
|
37
|
+
unpost_property_link(link.propertyID, link.url)
|
38
|
+
else
|
39
|
+
raise TypeError, "Invalid type: #{link.class}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def post_property_links(links)
|
46
|
+
request('PUT', "properties/#{links.first.propertyID}/links", links.map(&:to_hash))
|
47
|
+
end
|
48
|
+
|
49
|
+
def post_unit_links(links)
|
50
|
+
hash = {}
|
51
|
+
links.each do |p|
|
52
|
+
if hash.keys.include?(p.unitID)
|
53
|
+
hash[p.unitID] << p
|
54
|
+
else
|
55
|
+
hash[p.unitID] = [p]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
hash.each do |unitID, unit_links|
|
60
|
+
request('PUT', "units/#{unitID}/links", unit_links.map(&:to_hash))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def unpost_property_link(id, url)
|
65
|
+
request('DELETE', URI.encode("properties/#{id}/links/"), { url: url })
|
66
|
+
end
|
67
|
+
|
68
|
+
def unpost_unit_link(id, url)
|
69
|
+
request('DELETE', URI.encode("units/#{id}/links/"), { url: url })
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Rentlinx
|
2
|
+
module Linkable
|
3
|
+
def post_with_links
|
4
|
+
post
|
5
|
+
post_links
|
6
|
+
end
|
7
|
+
|
8
|
+
def post_links
|
9
|
+
Rentlinx.client.post_links(@links)
|
10
|
+
end
|
11
|
+
|
12
|
+
def links
|
13
|
+
return @links if @links
|
14
|
+
|
15
|
+
@links =
|
16
|
+
if defined? unitID
|
17
|
+
Rentlinx.client.get_links_for_unit(self)
|
18
|
+
else
|
19
|
+
Rentlinx.client.get_links_for_property_id(propertyID)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def links=(link_list)
|
24
|
+
@links = link_list.map do |link|
|
25
|
+
link.propertyID = propertyID
|
26
|
+
link.unitID = unitID if defined? unitID
|
27
|
+
link
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_link(options)
|
32
|
+
options.merge!(propertyID: propertyID)
|
33
|
+
options.merge!(unitID: unitID) if defined? unitID
|
34
|
+
@links ||= []
|
35
|
+
@links << link_class.new(options)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/rentlinx/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rentlinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AppFolio, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -67,12 +67,16 @@ files:
|
|
67
67
|
- lib/rentlinx/models/base.rb
|
68
68
|
- lib/rentlinx/models/property.rb
|
69
69
|
- lib/rentlinx/models/property_amenity.rb
|
70
|
+
- lib/rentlinx/models/property_link.rb
|
70
71
|
- lib/rentlinx/models/property_photo.rb
|
71
72
|
- lib/rentlinx/models/unit.rb
|
72
73
|
- lib/rentlinx/models/unit_amenity.rb
|
74
|
+
- lib/rentlinx/models/unit_link.rb
|
73
75
|
- lib/rentlinx/models/unit_photo.rb
|
74
76
|
- lib/rentlinx/modules/amenity_client_methods.rb
|
75
77
|
- lib/rentlinx/modules/amenityable.rb
|
78
|
+
- lib/rentlinx/modules/link_client_methods.rb
|
79
|
+
- lib/rentlinx/modules/linkable.rb
|
76
80
|
- lib/rentlinx/modules/photo_client_methods.rb
|
77
81
|
- lib/rentlinx/modules/photoable.rb
|
78
82
|
- lib/rentlinx/modules/property_client_methods.rb
|