rentlinx 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 720fea912d43966d463f3a33bccd817bd48ff08c
4
- data.tar.gz: 509098fd3d69076b2f49614b5cdea935f8e64899
3
+ metadata.gz: 6e3eba7e898a937ec5f358abcdb172ae207a1586
4
+ data.tar.gz: 57cc34bb4131f160deac0b107fe24f8d870e3987
5
5
  SHA512:
6
- metadata.gz: da9a9b33b4926c3089f5825624170ab79213eb7e439149f3b87ee2e634c9e31ea5d3018899a40a574470f37b906628bfa7bc4de5f33255af46dd2add9791821a
7
- data.tar.gz: 391d5f7b9f102ac645c1c10db3b2fe4157b37c9e9515007ad2ac31101541eb4ab32ad47d07b0d794eff388e26aedbea385f217b4fb21830be78ce2cf37f4ab15
6
+ metadata.gz: 18bc2f16c329de3b9ad5c9462f623ebdee7a58b3e337a80eb6046238f98c45b6ff904c4c259a5cadcf434a5bcc027af40a0339d4dca8ba822cb75f0a08a3732e
7
+ data.tar.gz: 9964b42866d070ac37ee9293ed34c057f90e904c0a0eb15c0886693d6cbc898ed66eafad92062972971a57bbc87859a8d0a8a7d167ebe506ddf1581e785671d4
data/lib/rentlinx.rb CHANGED
@@ -2,6 +2,7 @@ require 'rentlinx/client'
2
2
  require 'rentlinx/errors'
3
3
  require 'rentlinx/models/base'
4
4
  require 'rentlinx/models/property'
5
+ require 'rentlinx/models/unit'
5
6
 
6
7
  module Rentlinx
7
8
  @username = nil
@@ -14,6 +14,8 @@ module Rentlinx
14
14
  case object
15
15
  when Rentlinx::Property
16
16
  post_property(object)
17
+ when Rentlinx::Unit
18
+ post_unit(object)
17
19
  else
18
20
  raise TypeError, "Invalid object: #{object.class}"
19
21
  end
@@ -22,27 +24,47 @@ module Rentlinx
22
24
  def get(type, id)
23
25
  case type
24
26
  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)
27
+ Property.new(process_get("properties/#{id}"))
32
28
  when :unit
33
- # todo
29
+ Unit.new(process_get("units/#{id}"))
34
30
  else
35
31
  raise InvalidTypeParam, "Type not recognized: #{type}"
36
32
  end
37
33
  end
38
34
 
35
+ def get_units_for_property_id(id)
36
+ data = request('GET', "properties/#{id}/units")['data']
37
+ data.map do |unit_data|
38
+ Unit.new(symbolize_data(unit_data))
39
+ end
40
+ end
41
+
39
42
  private
40
43
 
44
+ def process_get(route)
45
+ data = request('GET', route)['data']
46
+ symbolize_data(data)
47
+ end
48
+
49
+ def symbolize_data(data)
50
+ data = data.each_with_object({}) do |(k, v), memo|
51
+ memo[k.to_sym] = v
52
+ memo
53
+ end
54
+ data.delete(:type)
55
+ data
56
+ end
57
+
41
58
  def post_property(prop)
42
59
  return false unless prop.valid?
43
60
  request('PUT', "properties/#{prop.propertyID}", prop.to_hash)
44
61
  end
45
62
 
63
+ def post_unit(unit)
64
+ return false unless unit.valid?
65
+ request('PUT', "units/#{unit.unitID}", unit.to_hash)
66
+ end
67
+
46
68
  def authenticate(username, password)
47
69
  data = { username: username, password: password }
48
70
  response = request('POST', 'authentication/login', data)
@@ -1,5 +1,25 @@
1
1
  module Rentlinx
2
2
  class Base
3
+ def initialize(attrs)
4
+ attributes.each do |at|
5
+ send("#{at}=", attrs[at])
6
+ end
7
+ remaining_attrs = attrs.keys - attributes
8
+ raise UnexpectedAttributes, "Unexpected Attributes: #{remaining_attrs.join(', ')}" if remaining_attrs.size > 0
9
+ end
10
+
11
+ def attributes
12
+ self.class::ATTRIBUTES
13
+ end
14
+
15
+ def required_attributes
16
+ self.class::REQUIRED_ATTRIBUTES
17
+ end
18
+
19
+ def required_attributes_for_post
20
+ self.class::REQUIRED_ATTRIBUTES_FOR_POST
21
+ end
22
+
3
23
  def post
4
24
  Rentlinx.client.post(self)
5
25
  end
@@ -7,5 +27,29 @@ module Rentlinx
7
27
  def self.get_from_id(type, id)
8
28
  Rentlinx.client.get(type.to_sym, id)
9
29
  end
30
+
31
+ def get_units_for_property_id(id)
32
+ Rentlinx.client.get_units_for_property_id(id)
33
+ end
34
+
35
+ def to_hash
36
+ {}.tap do |hash|
37
+ attributes.each do |at|
38
+ hash[at] = send(at)
39
+ end
40
+ end
41
+ end
42
+
43
+ def valid?
44
+ required_attributes.all? do |at|
45
+ !send(at).nil? && send(at) != ''
46
+ end
47
+ end
48
+
49
+ def valid_for_post?
50
+ required_attributes_for_post.all? do |at|
51
+ !send(at).nil? && send(at) != ''
52
+ end
53
+ end
10
54
  end
11
55
  end
@@ -9,40 +9,28 @@ module Rentlinx
9
9
  REQUIRED_ATTRIBUTES = [:propertyID, :address, :city, :state, :zip,
10
10
  :phoneNumber, :emailAddress]
11
11
 
12
- REQUIRED_FOR_POST = REQUIRED_ATTRIBUTES + [:companyID, :companyName]
12
+ REQUIRED_ATTRIBUTES_FOR_POST = REQUIRED_ATTRIBUTES + [:companyID, :companyName]
13
13
 
14
14
  attr_accessor(*ATTRIBUTES)
15
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
16
+ def post_with_units
17
+ post
18
+ units.each(&:post) unless units.nil? || units.empty?
22
19
  end
23
20
 
24
- def self.from_id(id)
25
- get_from_id(:property, id)
21
+ def units
22
+ @units ||= get_units_for_property_id(propertyID)
26
23
  end
27
24
 
28
- def valid?
29
- REQUIRED_ATTRIBUTES.all? do |at|
30
- !send(at).nil? && send(at) != ''
25
+ def units=(unit_list)
26
+ @units = unit_list.map do |unit|
27
+ unit.propertyID = propertyID
28
+ unit
31
29
  end
32
30
  end
33
31
 
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
32
+ def self.from_id(id)
33
+ get_from_id(:property, id)
46
34
  end
47
35
  end
48
36
  end
@@ -0,0 +1,20 @@
1
+ module Rentlinx
2
+ class Unit < Base
3
+ ATTRIBUTES = [:unitID, :propertyID, :name, :description, :rent, :maxRent,
4
+ :deposit, :maxDeposit, :squareFeet, :maxSquareFeet,
5
+ :bedrooms, :fullBaths, :halfBaths, :isMobilityAccessible,
6
+ :isVisionAccessible, :isHearingAccessible, :rentIsBasedOnIncome,
7
+ :isOpenToLease, :dateAvailable, :dateLeasedThrough, :numUnits,
8
+ :numAvailable]
9
+
10
+ REQUIRED_ATTRIBUTES = [:unitID]
11
+
12
+ REQUIRED_ATTRIBUTES_FOR_POST = REQUIRED_ATTRIBUTES + [:propertyID]
13
+
14
+ attr_accessor(*ATTRIBUTES)
15
+
16
+ def self.from_id(id)
17
+ get_from_id(:unit, id)
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Rentlinx
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.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.2.0
4
+ version: 0.3.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-18 00:00:00.000000000 Z
11
+ date: 2015-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -52,6 +52,7 @@ files:
52
52
  - lib/rentlinx/errors.rb
53
53
  - lib/rentlinx/models/base.rb
54
54
  - lib/rentlinx/models/property.rb
55
+ - lib/rentlinx/models/unit.rb
55
56
  - lib/rentlinx/version.rb
56
57
  homepage: https://github.com/appfolio/rentlinx_client
57
58
  licenses: