Class: Reggora::User

Inherits:
Object
  • Object
show all
Defined in:
lib/reggora/Entity/Lender/user.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ User

Returns a new instance of User.



3
4
5
6
# File 'lib/reggora/Entity/Lender/user.rb', line 3

def initialize(client)
  @model = 'user'
  @client = client
end

Instance Method Details

#all(params = {}) ⇒ Object

returns a list of all the users in the requesting lender.



9
10
11
# File 'lib/reggora/Entity/Lender/user.rb', line 9

def all(params = {})
  @client.get("/#{@model}s", params)
end

#create(user_params) ⇒ Object

creates a user to the reggora platform.



25
26
27
# File 'lib/reggora/Entity/Lender/user.rb', line 25

def create(user_params)
  @client.post("/#{@model}s", user_params)
end

#delete(user_id) ⇒ Object



35
36
37
# File 'lib/reggora/Entity/Lender/user.rb', line 35

def delete(user_id)
  @client.delete("/#{@model}s/#{user_id}")
end

#edit(user_id, user_params) ⇒ Object

updates a user’s information. No fields are required and only the supplied fields will be updated on the user.



31
32
33
# File 'lib/reggora/Entity/Lender/user.rb', line 31

def edit(user_id, user_params)
  @client.put("/#{@model}s/#{user_id}", user_params)
end

#find(user_id) ⇒ Object

takes a user ID as a URL parameter and returns a user object.



14
15
16
# File 'lib/reggora/Entity/Lender/user.rb', line 14

def find(user_id)
  @client.get("/#{@model}s/#{user_id}")
end

#invite(email, role, firstname, lastname, phone_number) ⇒ Object

invites a user to the reggora platform



19
20
21
22
# File 'lib/reggora/Entity/Lender/user.rb', line 19

def invite(email, role, firstname, lastname, phone_number)
  invite_params = invite_params(email, role, firstname, lastname, phone_number)
  @client.post("/#{@model}s/invite", invite_params)
end

#invite_params(email, role, firstname, lastname, phone_number) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/reggora/Entity/Lender/user.rb', line 52

def invite_params(email, role, firstname, lastname, phone_number)
  {
      email: email,
      role: role,
      firstname: firstname,
      lastname: lastname,
      phone_number: phone_number
  }
end

#query_params(ordering = '-created', offset = 0, limit = 0, search = '') ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/reggora/Entity/Lender/user.rb', line 62

def query_params(ordering = '-created', offset = 0, limit = 0, search = '')
  {
      ordering: ordering,
      offset: offset,
      limit: limit,
      search: search
  }
end

#sample_dataObject



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/reggora/Entity/Lender/user.rb', line 71

def sample_data
  s = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
  {
      email: "fake#{s[1...4]}@reggora.com",
      role: "Admin",
      firstname: "Fake",
      lastname: "Person#{s[1...4]}",
      phone_number: "#{rand(100000...99999)}",
      branch_id: '',
      nmls_id: '',
      matched_users: []
  }
end

#user_attributes(email, role, firstname, lastname, phone_number, branch_id = '', nmls_id = '', matched_users = []) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/reggora/Entity/Lender/user.rb', line 39

def user_attributes(email, role, firstname, lastname, phone_number, branch_id = '', nmls_id = '', matched_users = [])
  {
      email: email,
      role: role,
      firstname: firstname,
      lastname: lastname,
      phone_number: phone_number,
      branch_id: branch_id,
      nmls_id: nmls_id,
      matched_users: matched_users
  }
end