honest_renter 0.0.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +7 -0
- data/Gemfile.lock +23 -1
- data/LICENSE.txt +22 -0
- data/README.md +116 -1
- data/Rakefile +11 -0
- data/honest_renter.gemspec +6 -1
- data/lib/authenticator.rb +76 -0
- data/lib/client.rb +11 -0
- data/lib/honest_renter.rb +12 -0
- data/lib/request.rb +71 -0
- data/lib/requests/expandable.rb +10 -0
- data/lib/requests/filter.rb +9 -0
- data/lib/requests/find_all.rb +27 -0
- data/lib/requests/find_all_by_filter.rb +38 -0
- data/lib/requests/find_by_id.rb +23 -0
- data/lib/requests/post.rb +15 -0
- data/lib/requires.rb +18 -0
- data/lib/response.rb +30 -0
- data/lib/session.rb +20 -0
- data/models/applicant.rb +42 -0
- data/models/base_model.rb +57 -0
- data/models/candidate.rb +31 -0
- data/models/child.rb +20 -0
- data/models/code.rb +27 -0
- data/models/cooccupant.rb +20 -0
- data/models/country.rb +16 -0
- data/models/email.rb +21 -0
- data/models/emergency_contact.rb +20 -0
- data/models/ethnicity.rb +16 -0
- data/models/failed_login.rb +21 -0
- data/models/gender.rb +16 -0
- data/models/inbox_filters.rb +26 -0
- data/models/invite_settings.rb +23 -0
- data/models/member.rb +24 -0
- data/models/name.rb +22 -0
- data/models/notification.rb +18 -0
- data/models/notification_type.rb +19 -0
- data/models/organization.rb +23 -0
- data/models/participant.rb +21 -0
- data/models/person.rb +30 -0
- data/models/pet.rb +22 -0
- data/models/pet_age_category.rb +18 -0
- data/models/pet_size_category.rb +18 -0
- data/models/pet_type.rb +18 -0
- data/models/phone.rb +24 -0
- data/models/phone_type.rb +18 -0
- data/models/position.rb +23 -0
- data/models/reason_for_archive.rb +18 -0
- data/models/reason_for_eviction.rb +18 -0
- data/models/reason_for_exclusion.rb +18 -0
- data/models/reference.rb +20 -0
- data/models/relationship_type.rb +19 -0
- data/models/reminder.rb +19 -0
- data/models/residence.rb +25 -0
- data/models/smoking_status_category.rb +18 -0
- data/models/sort_by_option.rb +18 -0
- data/models/time_of_day.rb +18 -0
- data/models/title.rb +17 -0
- data/models/user.rb +20 -0
- data/models/vehicle.rb +21 -0
- data/modules/requests_unsupported.rb +21 -0
- data/modules/unrequestable.rb +23 -0
- data/test/fixtures/ethnicities/find_all.json +38 -0
- data/test/fixtures/members/find.json +31 -0
- data/test/fixtures/titles/find_all_by_filters.json +11 -0
- data/test/integration/find_all_by_filters_test.rb +12 -0
- data/test/integration/find_all_test.rb +11 -0
- data/test/integration/find_test.rb +10 -0
- data/test/lib/authenticator_test.rb +75 -0
- data/test/lib/requests/filter_test.rb +14 -0
- data/test/lib/requests/find_all_by_filter_test.rb +44 -0
- data/test/lib/requests/find_all_test.rb +59 -0
- data/test/lib/requests/find_by_id_test.rb +30 -0
- data/test/lib/requests/post_test.rb +38 -0
- data/test/lib/response_test.rb +46 -0
- data/test/lib/session_test.rb +45 -0
- data/test/models/base_model_test.rb +62 -0
- data/test/test_helper.rb +76 -0
- data/version.rb +1 -1
- metadata +134 -2
@@ -0,0 +1,27 @@
|
|
1
|
+
module HonestRenter
|
2
|
+
class FindAll
|
3
|
+
include Expandable
|
4
|
+
|
5
|
+
def initialize(resource_name, session, limit = nil, offset = nil)
|
6
|
+
@resource_name = resource_name
|
7
|
+
@session = session
|
8
|
+
@limit = limit
|
9
|
+
@offset = offset
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
client = HonestRenter::Client.new
|
14
|
+
request = HonestRenter::Request.new(client, @session)
|
15
|
+
query = {}.tap do |params|
|
16
|
+
unless @expansions.nil? || @expansions.empty?
|
17
|
+
params[:expand] = JSON(@expansions)
|
18
|
+
end
|
19
|
+
|
20
|
+
params[:limit] = @limit unless @limit.nil?
|
21
|
+
params[:offset] = @offset unless @offset.nil?
|
22
|
+
end
|
23
|
+
|
24
|
+
request.get(@resource_name, query)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module HonestRenter
|
2
|
+
class FindAllByFilter
|
3
|
+
include Expandable
|
4
|
+
|
5
|
+
def initialize(resource_name, session, limit = nil, offset = nil)
|
6
|
+
@resource_name = resource_name
|
7
|
+
@session = session
|
8
|
+
@limit = limit
|
9
|
+
@offset = offset
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_filter(filter)
|
13
|
+
@filters ||=[]
|
14
|
+
@filters << filter
|
15
|
+
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def call
|
20
|
+
client = HonestRenter::Client.new
|
21
|
+
request = HonestRenter::Request.new(client, @session)
|
22
|
+
query = {}.tap do |params|
|
23
|
+
unless @expansions.nil? || @expansions.empty?
|
24
|
+
params[:expand] = JSON(@expansions)
|
25
|
+
end
|
26
|
+
|
27
|
+
Array(@filters).each do |filter|
|
28
|
+
params[filter.key] = filter.value
|
29
|
+
end
|
30
|
+
|
31
|
+
params[:limit] = @limit unless @limit.nil?
|
32
|
+
params[:offset] = @offset unless @offset.nil?
|
33
|
+
end
|
34
|
+
|
35
|
+
request.get(@resource_name, query)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module HonestRenter
|
2
|
+
class FindById
|
3
|
+
include Expandable
|
4
|
+
|
5
|
+
def initialize(id, resource_name, session)
|
6
|
+
@id = id
|
7
|
+
@resource_name = resource_name
|
8
|
+
@session = session
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
client = HonestRenter::Client.new
|
13
|
+
request = HonestRenter::Request.new(client, @session)
|
14
|
+
url = "#{ @resource_name }/#{ @id }"
|
15
|
+
|
16
|
+
query = {}.tap do |params|
|
17
|
+
params[:expand] = JSON(@expansions) unless Array(@expansions).empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
request.get(url, query)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module HonestRenter
|
2
|
+
class Post
|
3
|
+
def initialize(resource_name, body, session=nil)
|
4
|
+
@resource_name = resource_name
|
5
|
+
@body = body
|
6
|
+
@session = session
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
client = HonestRenter::Client.new
|
11
|
+
request = HonestRenter::Request.new(client, @session)
|
12
|
+
request.post(@resource_name, @body)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/requires.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# master require file for whole tree
|
2
|
+
require_relative 'client'
|
3
|
+
require_relative 'request'
|
4
|
+
require_relative 'response'
|
5
|
+
require_relative 'session'
|
6
|
+
require_relative 'authenticator'
|
7
|
+
require_relative '../models/base_model'
|
8
|
+
require_relative 'requests/expandable'
|
9
|
+
|
10
|
+
[
|
11
|
+
'../../modules',
|
12
|
+
'../../models',
|
13
|
+
'../requests'
|
14
|
+
].each do |dir|
|
15
|
+
Dir[File.expand_path("#{dir}/*.rb", __FILE__)].each do |file|
|
16
|
+
require file
|
17
|
+
end
|
18
|
+
end
|
data/lib/response.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module HonestRenter
|
2
|
+
class Response
|
3
|
+
class MalformedResponse < StandardError; end
|
4
|
+
class RequestError < StandardError; end
|
5
|
+
|
6
|
+
attr_reader :body, :headers, :error
|
7
|
+
|
8
|
+
HAPPY_STATUSES = [200, 300].freeze
|
9
|
+
|
10
|
+
def initialize(raw_response)
|
11
|
+
@status = raw_response.status
|
12
|
+
@headers = raw_response.headers
|
13
|
+
|
14
|
+
begin
|
15
|
+
@body = JSON.parse(raw_response.body)
|
16
|
+
rescue JSON::ParserError, TypeError => e
|
17
|
+
raise MalformedResponse,
|
18
|
+
"Honest Renter response body not valid JSON, #{ raw_response.body } given"
|
19
|
+
end
|
20
|
+
|
21
|
+
if @body.key?('error')
|
22
|
+
@error = RequestError.new(@body['error']['message'])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def success?
|
27
|
+
HAPPY_STATUSES.include?(@status.floor)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/session.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module HonestRenter
|
2
|
+
class Session
|
3
|
+
attr_reader :honr_authentication_token, :honr_session
|
4
|
+
|
5
|
+
def initialize(honr_authentication_token, honr_session)
|
6
|
+
@honr_authentication_token = honr_authentication_token.to_s
|
7
|
+
@honr_session = JSON.parse(honr_session) rescue nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def expires_at
|
11
|
+
return Time.now if @honr_session.nil?
|
12
|
+
Time.at(@honr_session['expires'])
|
13
|
+
end
|
14
|
+
|
15
|
+
def expired?
|
16
|
+
return true if @honr_session.nil? || !@honr_session.is_a?(Hash)
|
17
|
+
expires_at < Time.now
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/models/applicant.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module HonestRenter
|
2
|
+
class Applicant < BaseModel
|
3
|
+
ATTRIBUTES = [
|
4
|
+
:id,
|
5
|
+
:account,
|
6
|
+
:administration,
|
7
|
+
:approved,
|
8
|
+
:archived,
|
9
|
+
:assessments,
|
10
|
+
:candidate,
|
11
|
+
:children,
|
12
|
+
:code,
|
13
|
+
:comments,
|
14
|
+
:cooccupants,
|
15
|
+
:correctedAddress,
|
16
|
+
:desired_move_in_date,
|
17
|
+
:fields,
|
18
|
+
:invitation,
|
19
|
+
:invite_cooccupants,
|
20
|
+
:location,
|
21
|
+
:location_is_correct,
|
22
|
+
:metadata,
|
23
|
+
:norm,
|
24
|
+
:number_of_adults,
|
25
|
+
:number_of_children,
|
26
|
+
:reason_for_archiving,
|
27
|
+
:reminders,
|
28
|
+
:results,
|
29
|
+
:sent_return_code,
|
30
|
+
:unit,
|
31
|
+
:viewings
|
32
|
+
].freeze
|
33
|
+
|
34
|
+
attr_accessor *ATTRIBUTES
|
35
|
+
|
36
|
+
class << self
|
37
|
+
def attr_name
|
38
|
+
'applicants'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module HonestRenter
|
2
|
+
class BaseModel
|
3
|
+
def initialize(data)
|
4
|
+
data.each do |key, value|
|
5
|
+
snaked = HonestRenter.snake_case(key)
|
6
|
+
if self.respond_to?(snaked)
|
7
|
+
send(:"#{snaked}=", value)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_h
|
13
|
+
{}.tap do |hash|
|
14
|
+
instance_variables.each do |variable|
|
15
|
+
name = variable.to_s[1..-1]
|
16
|
+
value = instance_variable_get(variable)
|
17
|
+
hash[name] = value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def find_all(session, limit=nil, offset=nil)
|
24
|
+
args = [session, limit, offset].compact
|
25
|
+
response = HonestRenter::FindAll.new(attr_name, *args).call
|
26
|
+
raise response.error unless response.success?
|
27
|
+
initialize_all_from_response(response)
|
28
|
+
end
|
29
|
+
|
30
|
+
def find(id, session)
|
31
|
+
response = HonestRenter::FindById.new(id, attr_name, session).call
|
32
|
+
raise response.error unless response.success?
|
33
|
+
new(response.body["data"])
|
34
|
+
end
|
35
|
+
|
36
|
+
def find_all_by_filters(filters, session, limit=nil, offset=nil)
|
37
|
+
args = [session, limit, offset].compact
|
38
|
+
request = HonestRenter::FindAllByFilter.new(attr_name, *args)
|
39
|
+
filters.each { |filter| request.add_filter(filter) }
|
40
|
+
response = request.call
|
41
|
+
|
42
|
+
raise response.error unless response.success?
|
43
|
+
initialize_all_from_response(response)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def initialize_all_from_response(response)
|
49
|
+
response.body['data'].map do |data|
|
50
|
+
new(data)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private_constant :BaseModel
|
57
|
+
end
|
data/models/candidate.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module HonestRenter
|
2
|
+
class Candidate < BaseModel
|
3
|
+
ATTRIBUTES = [
|
4
|
+
:id,
|
5
|
+
:administrations,
|
6
|
+
:best_time_to_contact,
|
7
|
+
:currently_employed,
|
8
|
+
:emergency_contacts,
|
9
|
+
:explination_for_background_checks,
|
10
|
+
:explination_for_eviction,
|
11
|
+
:has_been_evicted,
|
12
|
+
:has_explination_for_background_check,
|
13
|
+
:has_pet,
|
14
|
+
:has_problems_with_landlord,
|
15
|
+
:has_vehicle,
|
16
|
+
:problems_with_landlord,
|
17
|
+
:residences,
|
18
|
+
:smoking_status,
|
19
|
+
:pets,
|
20
|
+
:vehicles
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
attr_accessor *ATTRIBUTES
|
24
|
+
|
25
|
+
class << self
|
26
|
+
def attr_name
|
27
|
+
'candidates'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/models/child.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module HonestRenter
|
2
|
+
class Child < BaseModel
|
3
|
+
ATTRIBUTES = [
|
4
|
+
:id,
|
5
|
+
:age,
|
6
|
+
:applicant,
|
7
|
+
:created
|
8
|
+
].freeze
|
9
|
+
|
10
|
+
attr_accessor *ATTRIBUTES
|
11
|
+
|
12
|
+
include Unrequestable
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def attr_name
|
16
|
+
'child'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/models/code.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module HonestRenter
|
2
|
+
class Code < BaseModel
|
3
|
+
ATTRIBUTES = [
|
4
|
+
:id,
|
5
|
+
:account,
|
6
|
+
:administration,
|
7
|
+
:applicant,
|
8
|
+
:assessments,
|
9
|
+
:created,
|
10
|
+
:email,
|
11
|
+
:expires,
|
12
|
+
:location,
|
13
|
+
:metadata,
|
14
|
+
:person,
|
15
|
+
:unit,
|
16
|
+
:value
|
17
|
+
].freeze
|
18
|
+
|
19
|
+
attr_accessor *ATTRIBUTES
|
20
|
+
|
21
|
+
class << self
|
22
|
+
def attr_name
|
23
|
+
'codes'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module HonestRenter
|
2
|
+
class Cooccupant < BaseModel
|
3
|
+
ATTRIBUTES = [
|
4
|
+
:id,
|
5
|
+
:applicant,
|
6
|
+
:created,
|
7
|
+
:occupant,
|
8
|
+
:person,
|
9
|
+
:relationship
|
10
|
+
].freeze
|
11
|
+
|
12
|
+
attr_accessor *ATTRIBUTES
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def attr_name
|
16
|
+
'cooccupants'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/models/country.rb
ADDED
data/models/email.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module HonestRenter
|
2
|
+
class Email < BaseModel
|
3
|
+
ATTRIBUTES = [
|
4
|
+
:id,
|
5
|
+
:address,
|
6
|
+
:confirmed,
|
7
|
+
:created,
|
8
|
+
:flagged,
|
9
|
+
:organization,
|
10
|
+
:person
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
attr_accessor *ATTRIBUTES
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def attr_name
|
17
|
+
'emails'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module HonestRenter
|
2
|
+
class EmergencyContact < BaseModel
|
3
|
+
ATTRIBUTES = [
|
4
|
+
:id,
|
5
|
+
:candidate,
|
6
|
+
:contact,
|
7
|
+
:relationship
|
8
|
+
].freeze
|
9
|
+
|
10
|
+
attr_accessor *ATTRIBUTES
|
11
|
+
|
12
|
+
include Unrequestable
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def attr_name
|
16
|
+
'emergency_contacts'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|