rentlinx 0.9.3 → 0.9.4.pre
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 +1 -0
- data/lib/rentlinx/client.rb +22 -0
- data/lib/rentlinx/errors.rb +1 -1
- data/lib/rentlinx/models/base.rb +36 -8
- data/lib/rentlinx/models/company.rb +21 -0
- data/lib/rentlinx/models/property.rb +2 -1
- data/lib/rentlinx/modules/company_client_methods.rb +15 -0
- data/lib/rentlinx/modules/property_client_methods.rb +6 -0
- data/lib/rentlinx/validators/amount_validator.rb +14 -0
- data/lib/rentlinx/validators/attribute_processor_service.rb +4 -1
- data/lib/rentlinx/version.rb +1 -1
- metadata +8 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8b77a1746107aeea8c8af74a2c59244c46d2cac1
|
|
4
|
+
data.tar.gz: 72a3b7cbcdf9868fee1186720a1accce03bde5c4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cfc3bf598922af2b45d7d194349b9063be2d3fb3592aaf943946cc60c3f946e23125767907bf566aeda63d783733519377a9512c75886a693d2dd7e9a3bffabe
|
|
7
|
+
data.tar.gz: 2a7c3ef5972f5783b2440a31eb1d73f12ffe5e3cb1e6901d40878be9b0ea4a567fc4d7c16cd8ca0a800acb341f41fc8443f34cf50912cfe8f338e6d078561281
|
data/lib/rentlinx.rb
CHANGED
data/lib/rentlinx/client.rb
CHANGED
|
@@ -2,6 +2,7 @@ require 'httpclient'
|
|
|
2
2
|
require 'json'
|
|
3
3
|
require 'uri'
|
|
4
4
|
require 'rentlinx/default'
|
|
5
|
+
require 'rentlinx/modules/company_client_methods'
|
|
5
6
|
require 'rentlinx/modules/property_client_methods'
|
|
6
7
|
require 'rentlinx/modules/unit_client_methods'
|
|
7
8
|
require 'rentlinx/modules/photo_client_methods'
|
|
@@ -15,6 +16,7 @@ module Rentlinx
|
|
|
15
16
|
# It should not be interacted with, the objects provide
|
|
16
17
|
# all the functionality necessary to work with Rentlinx.
|
|
17
18
|
class Client
|
|
19
|
+
include Rentlinx::CompanyClientMethods
|
|
18
20
|
include Rentlinx::PropertyClientMethods
|
|
19
21
|
include Rentlinx::UnitClientMethods
|
|
20
22
|
include Rentlinx::PhotoClientMethods
|
|
@@ -38,11 +40,27 @@ module Rentlinx
|
|
|
38
40
|
@api_token ||= authenticate(Rentlinx.username, Rentlinx.password)
|
|
39
41
|
end
|
|
40
42
|
|
|
43
|
+
# Pushes an object's attributes out to Rentlinx
|
|
44
|
+
#
|
|
45
|
+
# @param object [Rentlinx::Base] the object to be patched
|
|
46
|
+
def patch(object)
|
|
47
|
+
case object
|
|
48
|
+
when Rentlinx::Property
|
|
49
|
+
raise Rentlinx::InvalidObject, object unless object.patch_valid?
|
|
50
|
+
patch_property(object)
|
|
51
|
+
else
|
|
52
|
+
raise TypeError, "Type not permitted: #{object.class}"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
41
56
|
# Pushes an object's attributes out to Rentlinx
|
|
42
57
|
#
|
|
43
58
|
# @param object [Rentlinx::Base] the object to be posted
|
|
44
59
|
def post(object)
|
|
45
60
|
case object
|
|
61
|
+
when Rentlinx::Company
|
|
62
|
+
raise Rentlinx::InvalidObject, object unless object.valid?
|
|
63
|
+
post_company(object)
|
|
46
64
|
when Rentlinx::Property
|
|
47
65
|
raise Rentlinx::InvalidObject, object unless object.valid?
|
|
48
66
|
post_property(object)
|
|
@@ -60,6 +78,8 @@ module Rentlinx
|
|
|
60
78
|
# @param id [String] the rentlinx id of the object to be unposted
|
|
61
79
|
def unpost(type, id)
|
|
62
80
|
case type
|
|
81
|
+
when :company
|
|
82
|
+
unpost_company(id)
|
|
63
83
|
when :property
|
|
64
84
|
unpost_property(id)
|
|
65
85
|
when :unit
|
|
@@ -75,6 +95,8 @@ module Rentlinx
|
|
|
75
95
|
# @param id [String] the rentlinx id of the object to be fetched
|
|
76
96
|
def get(type, id)
|
|
77
97
|
case type
|
|
98
|
+
when :company
|
|
99
|
+
Company.new(process_get("companies/#{id}"))
|
|
78
100
|
when :property
|
|
79
101
|
Property.new(process_get("properties/#{id}"))
|
|
80
102
|
when :unit
|
data/lib/rentlinx/errors.rb
CHANGED
data/lib/rentlinx/models/base.rb
CHANGED
|
@@ -16,6 +16,7 @@ module Rentlinx
|
|
|
16
16
|
#
|
|
17
17
|
# @param attrs [Hash] a hash of attributes to save.
|
|
18
18
|
def initialize(attrs)
|
|
19
|
+
@original_attrs = attrs.dup
|
|
19
20
|
@processor = AttributeProcessor.new(attrs.dup)
|
|
20
21
|
attrs = @processor.process
|
|
21
22
|
attributes.each do |at|
|
|
@@ -39,6 +40,15 @@ module Rentlinx
|
|
|
39
40
|
self.class::REQUIRED_ATTRIBUTES
|
|
40
41
|
end
|
|
41
42
|
|
|
43
|
+
# Sends the object to Rentlinx
|
|
44
|
+
#
|
|
45
|
+
# @example
|
|
46
|
+
# prop = Rentlinx::Property.new(attrs)
|
|
47
|
+
# prop.patch
|
|
48
|
+
def patch
|
|
49
|
+
Rentlinx.client.patch(self)
|
|
50
|
+
end
|
|
51
|
+
|
|
42
52
|
# Sends the object to Rentlinx
|
|
43
53
|
#
|
|
44
54
|
# @example
|
|
@@ -54,7 +64,7 @@ module Rentlinx
|
|
|
54
64
|
# prop = Rentlinx::Property.new(attrs)
|
|
55
65
|
# prop.unpost
|
|
56
66
|
def unpost
|
|
57
|
-
Rentlinx.client.unpost(type, send(
|
|
67
|
+
Rentlinx.client.unpost(type, send(identity))
|
|
58
68
|
end
|
|
59
69
|
|
|
60
70
|
# Converts the object to a hash
|
|
@@ -62,30 +72,44 @@ module Rentlinx
|
|
|
62
72
|
# @return a hash including the attributes and values
|
|
63
73
|
def to_hash
|
|
64
74
|
{}.tap do |hash|
|
|
65
|
-
|
|
75
|
+
@original_attrs.keys.each do |at|
|
|
66
76
|
hash[at] = send(at)
|
|
67
77
|
end
|
|
68
78
|
end
|
|
69
79
|
end
|
|
70
80
|
|
|
71
|
-
# Determines the validity of the object
|
|
81
|
+
# Determines the validity of the object for post
|
|
72
82
|
#
|
|
73
83
|
# @return true if valid, false if invalid
|
|
74
84
|
def valid?
|
|
75
|
-
|
|
85
|
+
validate.empty?
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Determines the validity of the object for patch
|
|
89
|
+
#
|
|
90
|
+
# @return true if valid, false if invalid
|
|
91
|
+
def patch_valid?
|
|
92
|
+
validate(false).empty?
|
|
76
93
|
end
|
|
77
94
|
|
|
78
95
|
# Provides error messages on invalid objects
|
|
79
96
|
#
|
|
97
|
+
# @param check_required_attributes whether to check for required attributes
|
|
80
98
|
# @return a hash of error messages
|
|
81
|
-
def
|
|
99
|
+
def validate(check_required_attributes = true)
|
|
82
100
|
@processor = AttributeProcessor.new(to_hash)
|
|
83
101
|
@processor.process
|
|
84
102
|
|
|
85
|
-
|
|
103
|
+
# object identity is always required, even for patches
|
|
104
|
+
missing_errors = {}
|
|
105
|
+
missing_errors[identity.to_sym] = 'is missing' if self.class.method_defined?(identity) && blank?(send(identity))
|
|
106
|
+
|
|
107
|
+
if check_required_attributes
|
|
108
|
+
missing_attrs = required_attributes.select { |at| blank?(send(at)) }
|
|
86
109
|
|
|
87
|
-
|
|
88
|
-
|
|
110
|
+
missing_attrs.each do |at|
|
|
111
|
+
missing_errors[at] = 'is missing'
|
|
112
|
+
end
|
|
89
113
|
end
|
|
90
114
|
|
|
91
115
|
@processor.errors.merge(missing_errors)
|
|
@@ -109,6 +133,10 @@ module Rentlinx
|
|
|
109
133
|
name.split('::').last.downcase.to_sym
|
|
110
134
|
end
|
|
111
135
|
|
|
136
|
+
def identity
|
|
137
|
+
type.to_s + 'ID'
|
|
138
|
+
end
|
|
139
|
+
|
|
112
140
|
def blank?(str)
|
|
113
141
|
str.nil? || str == ''
|
|
114
142
|
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Rentlinx
|
|
2
|
+
# An object that represents a Rentlinx company.
|
|
3
|
+
class Company < Base
|
|
4
|
+
ATTRIBUTES = [:companyID, :companyCapAmount]
|
|
5
|
+
|
|
6
|
+
REQUIRED_ATTRIBUTES = [:companyID]
|
|
7
|
+
|
|
8
|
+
attr_accessor(*ATTRIBUTES)
|
|
9
|
+
|
|
10
|
+
# Queries Rentlinx and builds a company with the given ID
|
|
11
|
+
#
|
|
12
|
+
# The returned company will have all the attributes Rentlinx
|
|
13
|
+
# has for the company on their end.
|
|
14
|
+
#
|
|
15
|
+
# @param id [String] the Rentlinx id of the company
|
|
16
|
+
# @return a Rentlinx::Company that is up to date with the remote one
|
|
17
|
+
def self.from_id(id)
|
|
18
|
+
get_from_id(:company, id)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -9,7 +9,8 @@ module Rentlinx
|
|
|
9
9
|
:zip, :marketingName, :hideAddress, :latitude, :longitude,
|
|
10
10
|
:website, :yearBuilt, :numUnits, :phoneNumber, :extension,
|
|
11
11
|
:faxNumber, :emailAddress, :acceptsHcv, :propertyType,
|
|
12
|
-
:activeURL, :companyName, :leadsURL
|
|
12
|
+
:activeURL, :companyName, :leadsURL,
|
|
13
|
+
:premium, :capAmount]
|
|
13
14
|
|
|
14
15
|
REQUIRED_ATTRIBUTES = [:propertyID, :address, :city, :state, :zip,
|
|
15
16
|
:phoneNumber, :emailAddress]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Rentlinx
|
|
2
|
+
# Client methods for companies. No public methods.
|
|
3
|
+
module CompanyClientMethods
|
|
4
|
+
private
|
|
5
|
+
|
|
6
|
+
def post_company(company)
|
|
7
|
+
return false unless company.valid?
|
|
8
|
+
request('PUT', "companies/#{company.companyID}", company.to_hash)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def unpost_company(id)
|
|
12
|
+
request('DELETE', "companies/#{id}")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -14,6 +14,12 @@ module Rentlinx
|
|
|
14
14
|
|
|
15
15
|
private
|
|
16
16
|
|
|
17
|
+
def patch_property(prop)
|
|
18
|
+
return false unless prop.patch_valid?
|
|
19
|
+
# TODO: change to 'PATCH' once Rentlinx supports it
|
|
20
|
+
request('PUT', "properties/#{prop.propertyID}", prop.to_hash)
|
|
21
|
+
end
|
|
22
|
+
|
|
17
23
|
def post_property(prop)
|
|
18
24
|
return false unless prop.valid?
|
|
19
25
|
request('PUT', "properties/#{prop.propertyID}", prop.to_hash)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Rentlinx
|
|
2
|
+
# Validator for money amounts.
|
|
3
|
+
# Must be positive amounts.
|
|
4
|
+
# Cannot be cleared once set.
|
|
5
|
+
class AmountValidator < BaseValidator
|
|
6
|
+
private
|
|
7
|
+
|
|
8
|
+
def validate
|
|
9
|
+
@value.sub!(/^0+/, '') unless @value.nil?
|
|
10
|
+
return if @value.to_s =~ /[1-9]\d*(\.\d{1,2})?/
|
|
11
|
+
@error = "'#{@value}' is not a valid amount."
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'rentlinx/validators/base_validator'
|
|
2
2
|
require 'rentlinx/validators/address_validator'
|
|
3
|
+
require 'rentlinx/validators/amount_validator'
|
|
3
4
|
require 'rentlinx/validators/city_validator'
|
|
4
5
|
require 'rentlinx/validators/phone_validator'
|
|
5
6
|
require 'rentlinx/validators/state_validator'
|
|
@@ -37,7 +38,9 @@ module Rentlinx
|
|
|
37
38
|
zip: ZipValidator,
|
|
38
39
|
leadsURL: UrlValidator,
|
|
39
40
|
city: CityValidator,
|
|
40
|
-
address: AddressValidator
|
|
41
|
+
address: AddressValidator,
|
|
42
|
+
capAmount: AmountValidator,
|
|
43
|
+
companyCapAmount: AmountValidator }
|
|
41
44
|
|
|
42
45
|
@attrs.each do |field, val|
|
|
43
46
|
next unless validators.keys.include?(field)
|
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.9.
|
|
4
|
+
version: 0.9.4.pre
|
|
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-11-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httpclient
|
|
@@ -65,6 +65,7 @@ files:
|
|
|
65
65
|
- lib/rentlinx/default.rb
|
|
66
66
|
- lib/rentlinx/errors.rb
|
|
67
67
|
- lib/rentlinx/models/base.rb
|
|
68
|
+
- lib/rentlinx/models/company.rb
|
|
68
69
|
- lib/rentlinx/models/property.rb
|
|
69
70
|
- lib/rentlinx/models/property_amenity.rb
|
|
70
71
|
- lib/rentlinx/models/property_link.rb
|
|
@@ -75,6 +76,7 @@ files:
|
|
|
75
76
|
- lib/rentlinx/models/unit_photo.rb
|
|
76
77
|
- lib/rentlinx/modules/amenity_client_methods.rb
|
|
77
78
|
- lib/rentlinx/modules/amenityable.rb
|
|
79
|
+
- lib/rentlinx/modules/company_client_methods.rb
|
|
78
80
|
- lib/rentlinx/modules/link_client_methods.rb
|
|
79
81
|
- lib/rentlinx/modules/linkable.rb
|
|
80
82
|
- lib/rentlinx/modules/photo_client_methods.rb
|
|
@@ -82,6 +84,7 @@ files:
|
|
|
82
84
|
- lib/rentlinx/modules/property_client_methods.rb
|
|
83
85
|
- lib/rentlinx/modules/unit_client_methods.rb
|
|
84
86
|
- lib/rentlinx/validators/address_validator.rb
|
|
87
|
+
- lib/rentlinx/validators/amount_validator.rb
|
|
85
88
|
- lib/rentlinx/validators/attribute_processor_service.rb
|
|
86
89
|
- lib/rentlinx/validators/base_validator.rb
|
|
87
90
|
- lib/rentlinx/validators/city_validator.rb
|
|
@@ -105,14 +108,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
105
108
|
version: '0'
|
|
106
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
110
|
requirements:
|
|
108
|
-
- - "
|
|
111
|
+
- - ">"
|
|
109
112
|
- !ruby/object:Gem::Version
|
|
110
|
-
version:
|
|
113
|
+
version: 1.3.1
|
|
111
114
|
requirements: []
|
|
112
115
|
rubyforge_project:
|
|
113
|
-
rubygems_version: 2.4.
|
|
116
|
+
rubygems_version: 2.4.5.1
|
|
114
117
|
signing_key:
|
|
115
118
|
specification_version: 4
|
|
116
119
|
summary: API Wrapper for the Rentlinx API
|
|
117
120
|
test_files: []
|
|
118
|
-
has_rdoc:
|