rentlinx 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/lib/rentlinx.rb +3 -0
- data/lib/rentlinx/client.rb +38 -1
- data/lib/rentlinx/errors.rb +10 -0
- data/lib/rentlinx/models/base.rb +11 -0
- data/lib/rentlinx/models/property.rb +48 -0
- data/lib/rentlinx/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 720fea912d43966d463f3a33bccd817bd48ff08c
|
4
|
+
data.tar.gz: 509098fd3d69076b2f49614b5cdea935f8e64899
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da9a9b33b4926c3089f5825624170ab79213eb7e439149f3b87ee2e634c9e31ea5d3018899a40a574470f37b906628bfa7bc4de5f33255af46dd2add9791821a
|
7
|
+
data.tar.gz: 391d5f7b9f102ac645c1c10db3b2fe4157b37c9e9515007ad2ac31101541eb4ab32ad47d07b0d794eff388e26aedbea385f217b4fb21830be78ce2cf37f4ab15
|
data/README.md
CHANGED
@@ -49,6 +49,21 @@ test files can be executed via:
|
|
49
49
|
ruby -Ilib:test test/FILENAME.rb
|
50
50
|
|
51
51
|
|
52
|
+
### Usage
|
53
|
+
|
54
|
+
For all endpoints, attributes are defined by the API: https://www.rentlinx.com/mongoose/help
|
55
|
+
|
56
|
+
Properties can be created, updated, and fetched from Rentlinx like so:
|
57
|
+
|
58
|
+
prop = Property.new(attributes)
|
59
|
+
prop.post # creates
|
60
|
+
|
61
|
+
prop.website = 'http://example.com'
|
62
|
+
prop.post # updates
|
63
|
+
|
64
|
+
prop = Property.from_id('property-id') # fetches
|
65
|
+
|
66
|
+
|
52
67
|
## Copyright and license
|
53
68
|
|
54
69
|
Source released under the Simplified BSD License.
|
data/lib/rentlinx.rb
CHANGED
data/lib/rentlinx/client.rb
CHANGED
@@ -10,8 +10,39 @@ module Rentlinx
|
|
10
10
|
@api_token ||= authenticate(Rentlinx.username, Rentlinx.password)
|
11
11
|
end
|
12
12
|
|
13
|
+
def post(object)
|
14
|
+
case object
|
15
|
+
when Rentlinx::Property
|
16
|
+
post_property(object)
|
17
|
+
else
|
18
|
+
raise TypeError, "Invalid object: #{object.class}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def get(type, id)
|
23
|
+
case type
|
24
|
+
when :property
|
25
|
+
data = request('GET', "properties/#{id}")['data']
|
26
|
+
data = data.each_with_object({}) do |(k, v), memo|
|
27
|
+
memo[k.to_sym] = v
|
28
|
+
memo
|
29
|
+
end
|
30
|
+
data.delete(:type)
|
31
|
+
Property.new(data)
|
32
|
+
when :unit
|
33
|
+
# todo
|
34
|
+
else
|
35
|
+
raise InvalidTypeParam, "Type not recognized: #{type}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
13
39
|
private
|
14
40
|
|
41
|
+
def post_property(prop)
|
42
|
+
return false unless prop.valid?
|
43
|
+
request('PUT', "properties/#{prop.propertyID}", prop.to_hash)
|
44
|
+
end
|
45
|
+
|
15
46
|
def authenticate(username, password)
|
16
47
|
data = { username: username, password: password }
|
17
48
|
response = request('POST', 'authentication/login', data)
|
@@ -19,11 +50,17 @@ module Rentlinx
|
|
19
50
|
end
|
20
51
|
|
21
52
|
def request(method, path, data = nil)
|
22
|
-
options = { body: data.to_json, header:
|
53
|
+
options = { body: data.to_json, header: authenticated_headers }
|
23
54
|
response = session.request(method, URI.join(@url_prefix, path), options)
|
24
55
|
JSON.parse(response.body)
|
25
56
|
end
|
26
57
|
|
58
|
+
def authenticated_headers
|
59
|
+
Rentlinx::Default.headers.tap do |headers|
|
60
|
+
headers['Authentication-Token'] = @api_token unless @api_token.nil?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
27
64
|
def session
|
28
65
|
@session ||= HTTPClient.new
|
29
66
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Rentlinx
|
2
|
+
class Property < Base
|
3
|
+
ATTRIBUTES = [:companyID, :propertyID, :description, :address, :city, :state,
|
4
|
+
:zip, :marketingName, :hideAddress, :latitude, :longitude,
|
5
|
+
:website, :yearBuilt, :numUnits, :phoneNumber, :extension,
|
6
|
+
:faxNumber, :emailAddress, :acceptsHcv, :propertyType,
|
7
|
+
:activeURL, :companyName]
|
8
|
+
|
9
|
+
REQUIRED_ATTRIBUTES = [:propertyID, :address, :city, :state, :zip,
|
10
|
+
:phoneNumber, :emailAddress]
|
11
|
+
|
12
|
+
REQUIRED_FOR_POST = REQUIRED_ATTRIBUTES + [:companyID, :companyName]
|
13
|
+
|
14
|
+
attr_accessor(*ATTRIBUTES)
|
15
|
+
|
16
|
+
def initialize(attrs)
|
17
|
+
ATTRIBUTES.each do |at|
|
18
|
+
send("#{at}=", attrs[at])
|
19
|
+
end
|
20
|
+
remaining_attrs = attrs.keys - ATTRIBUTES
|
21
|
+
raise UnexpectedAttributes, "Unexpected Attributes: #{remaining_attrs.join(', ')}" if remaining_attrs.size > 0
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.from_id(id)
|
25
|
+
get_from_id(:property, id)
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid?
|
29
|
+
REQUIRED_ATTRIBUTES.all? do |at|
|
30
|
+
!send(at).nil? && send(at) != ''
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def valid_for_post?
|
35
|
+
REQUIRED_FOR_POST.all? do |at|
|
36
|
+
!send(at).nil? && send(at) != ''
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_hash
|
41
|
+
{}.tap do |hash|
|
42
|
+
ATTRIBUTES.each do |at|
|
43
|
+
hash[at] = send(at)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
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.2.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-06-
|
11
|
+
date: 2015-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -49,6 +49,9 @@ files:
|
|
49
49
|
- lib/rentlinx.rb
|
50
50
|
- lib/rentlinx/client.rb
|
51
51
|
- lib/rentlinx/default.rb
|
52
|
+
- lib/rentlinx/errors.rb
|
53
|
+
- lib/rentlinx/models/base.rb
|
54
|
+
- lib/rentlinx/models/property.rb
|
52
55
|
- lib/rentlinx/version.rb
|
53
56
|
homepage: https://github.com/appfolio/rentlinx_client
|
54
57
|
licenses:
|