rentlinx 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e982c2be41722f9f4d073747e2e1b62c65a7e6c
4
- data.tar.gz: 7f402610e2f22b453b6824d8049898be05db4325
3
+ metadata.gz: 720fea912d43966d463f3a33bccd817bd48ff08c
4
+ data.tar.gz: 509098fd3d69076b2f49614b5cdea935f8e64899
5
5
  SHA512:
6
- metadata.gz: e9456965acfd7fa9d0f36201fd836db98803029fbbf10e81a44fc3d68908ef712922d4426c31920c457b182d83b483fea964a1fd982b496acf02de5919e037e5
7
- data.tar.gz: 75d49028469c3b1948f9659701a25a1cfaefe66de95731a74b7f7c87fe2181b5f102b55706899b5af8ea9e21a94ff77e158fdeaa925137e7d1d928d62fdcfb8b
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.
@@ -1,4 +1,7 @@
1
1
  require 'rentlinx/client'
2
+ require 'rentlinx/errors'
3
+ require 'rentlinx/models/base'
4
+ require 'rentlinx/models/property'
2
5
 
3
6
  module Rentlinx
4
7
  @username = nil
@@ -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: Rentlinx::Default.headers }
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,10 @@
1
+ module Rentlinx
2
+ class RentlinxError < StandardError
3
+ end
4
+
5
+ class UnexpectedAttributes < RentlinxError
6
+ end
7
+
8
+ class InvalidTypeParam < RentlinxError
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module Rentlinx
2
+ class Base
3
+ def post
4
+ Rentlinx.client.post(self)
5
+ end
6
+
7
+ def self.get_from_id(type, id)
8
+ Rentlinx.client.get(type.to_sym, id)
9
+ end
10
+ end
11
+ 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
@@ -1,3 +1,3 @@
1
1
  module Rentlinx
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
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.1.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-17 00:00:00.000000000 Z
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: