rentlinx 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rentlinx/errors.rb +1 -1
- data/lib/rentlinx/models/base.rb +14 -5
- data/lib/rentlinx/validators/attribute_processor_service.rb +31 -0
- data/lib/rentlinx/validators/base_validator.rb +23 -0
- data/lib/rentlinx/validators/phone_validator.rb +14 -0
- data/lib/rentlinx/validators/state_validator.rb +8 -0
- data/lib/rentlinx/validators/zip_validator.rb +8 -0
- data/lib/rentlinx/version.rb +1 -1
- data/lib/rentlinx.rb +5 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d9edda5dacfcfcfc5bacb55131280a97b10d17f
|
4
|
+
data.tar.gz: 34bbbd157f68b05db896d3d758fa4aa77369fa01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e24d4cd7d154e0e78c00e89b35ff86c5a9efc632f967a221bcea7eb9f1021af1e5aeecffc188260f2c858d5b35d43f83cb46d3dc9f1a290c567daab9c6da4e65
|
7
|
+
data.tar.gz: 592290b007d27b614c5023bb43606b4143167bc50bbdcf723698c7ac933eb543fec5db0b0d1dcd9824a979705f5f335f83497ca5d2a58c5956402c69753cbb03
|
data/lib/rentlinx/errors.rb
CHANGED
data/lib/rentlinx/models/base.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
module Rentlinx
|
2
2
|
class Base
|
3
3
|
def initialize(attrs)
|
4
|
+
@processor = AttributeProcessor.new(attrs)
|
5
|
+
attrs = @processor.process
|
4
6
|
attributes.each do |at|
|
5
7
|
send("#{at}=", attrs[at])
|
6
8
|
end
|
7
9
|
remaining_attrs = attrs.keys - attributes
|
8
|
-
raise UnexpectedAttributes, "Unexpected Attributes: #{remaining_attrs.join(', ')}" if remaining_attrs.size > 0
|
10
|
+
raise UnexpectedAttributes, "Unexpected Attributes: #{remaining_attrs.join(', ')}" if remaining_attrs.compact.size > 0
|
9
11
|
end
|
10
12
|
|
11
13
|
def attributes
|
@@ -49,17 +51,24 @@ module Rentlinx
|
|
49
51
|
end
|
50
52
|
|
51
53
|
def valid?
|
52
|
-
|
54
|
+
error_messages.empty?
|
53
55
|
end
|
54
56
|
|
55
57
|
def valid_for_post?
|
56
58
|
required_attributes_for_post.none? { |at| blank?(send(at)) }
|
57
59
|
end
|
58
60
|
|
59
|
-
def
|
60
|
-
|
61
|
+
def error_messages
|
62
|
+
@processor = AttributeProcessor.new(to_hash)
|
63
|
+
@processor.process
|
61
64
|
|
62
|
-
|
65
|
+
missing_attrs = required_attributes.select { |at| blank?(send(at)) }
|
66
|
+
|
67
|
+
missing_errors = missing_attrs.each_with_object({}) do |at, obj|
|
68
|
+
obj[at] = 'is missing'
|
69
|
+
end
|
70
|
+
|
71
|
+
@processor.errors.merge(missing_errors)
|
63
72
|
end
|
64
73
|
|
65
74
|
private
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Rentlinx
|
2
|
+
class AttributeProcessor
|
3
|
+
attr_reader :errors
|
4
|
+
attr_reader :processed_attrs
|
5
|
+
|
6
|
+
def initialize(attrs)
|
7
|
+
@attrs = attrs
|
8
|
+
@processed_attrs = @attrs
|
9
|
+
@errors = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def process
|
13
|
+
validators = { phoneNumber: PhoneValidator,
|
14
|
+
state: StateValidator,
|
15
|
+
zip: ZipValidator }
|
16
|
+
|
17
|
+
@attrs.each do |field, val|
|
18
|
+
next unless validators.keys.include?(field)
|
19
|
+
validator = validators[field].new(val)
|
20
|
+
@processed_attrs[field] = validator.processed_value
|
21
|
+
@errors[field] = validator.error unless validator.valid?
|
22
|
+
end
|
23
|
+
|
24
|
+
@processed_attrs
|
25
|
+
end
|
26
|
+
|
27
|
+
def valid?
|
28
|
+
@errors.size == 0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rentlinx
|
2
|
+
class BaseValidator
|
3
|
+
attr_reader :error
|
4
|
+
|
5
|
+
def initialize(val)
|
6
|
+
@value = val
|
7
|
+
@error = ''
|
8
|
+
validate
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid?
|
12
|
+
@error == ''
|
13
|
+
end
|
14
|
+
|
15
|
+
def processed_value
|
16
|
+
@value
|
17
|
+
end
|
18
|
+
|
19
|
+
def value_blank?
|
20
|
+
@value.nil? || @value == ''
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Rentlinx
|
2
|
+
class PhoneValidator < BaseValidator
|
3
|
+
def validate
|
4
|
+
return if value_blank? || Phony.plausible?(@value) || Phony.plausible?('1' + @value)
|
5
|
+
@error = "#{@value} is not a valid phone number"
|
6
|
+
end
|
7
|
+
|
8
|
+
def processed_value
|
9
|
+
return '' if value_blank?
|
10
|
+
return @value unless valid?
|
11
|
+
Phony.normalize(@value)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/rentlinx/version.rb
CHANGED
data/lib/rentlinx.rb
CHANGED
@@ -4,6 +4,11 @@ require 'rentlinx/errors'
|
|
4
4
|
require 'rentlinx/models/base'
|
5
5
|
require 'rentlinx/models/property'
|
6
6
|
require 'rentlinx/models/unit'
|
7
|
+
require 'rentlinx/validators/attribute_processor_service'
|
8
|
+
require 'rentlinx/validators/base_validator'
|
9
|
+
require 'rentlinx/validators/phone_validator'
|
10
|
+
require 'rentlinx/validators/state_validator'
|
11
|
+
require 'rentlinx/validators/zip_validator'
|
7
12
|
|
8
13
|
module Rentlinx
|
9
14
|
@username = nil
|
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.4.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-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: phony
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.14.6
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.14.6
|
41
55
|
description:
|
42
56
|
email: bryce.boe@appfolio.com
|
43
57
|
executables: []
|
@@ -53,6 +67,11 @@ files:
|
|
53
67
|
- lib/rentlinx/models/base.rb
|
54
68
|
- lib/rentlinx/models/property.rb
|
55
69
|
- lib/rentlinx/models/unit.rb
|
70
|
+
- lib/rentlinx/validators/attribute_processor_service.rb
|
71
|
+
- lib/rentlinx/validators/base_validator.rb
|
72
|
+
- lib/rentlinx/validators/phone_validator.rb
|
73
|
+
- lib/rentlinx/validators/state_validator.rb
|
74
|
+
- lib/rentlinx/validators/zip_validator.rb
|
56
75
|
- lib/rentlinx/version.rb
|
57
76
|
homepage: https://github.com/appfolio/rentlinx_client
|
58
77
|
licenses:
|