Class: Driftrock::Service::DriftrockModel::User
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#get_from_api_method, included, #post_to_api_method, #put_to_api_method
Constructor Details
#initialize(object_hash) ⇒ User
Returns a new instance of User.
7
8
9
10
11
12
13
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 7
def initialize(object_hash)
super(object_hash)
@invites = [] unless invites && invites.is_a?(Array)
@invites = invites.map do |invite|
CompanyInvite.new(invite)
end
end
|
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
5
6
7
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 5
def created_at
@created_at
end
|
#email ⇒ Object
Returns the value of attribute email.
5
6
7
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 5
def email
@email
end
|
#first_name ⇒ Object
Returns the value of attribute first_name.
5
6
7
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 5
def first_name
@first_name
end
|
#id ⇒ Object
Returns the value of attribute id.
5
6
7
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 5
def id
@id
end
|
#invites ⇒ Object
Returns the value of attribute invites.
5
6
7
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 5
def invites
@invites
end
|
#last_name ⇒ Object
Returns the value of attribute last_name.
5
6
7
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 5
def last_name
@last_name
end
|
#session_id ⇒ Object
Returns the value of attribute session_id.
5
6
7
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 5
def session_id
@session_id
end
|
Class Method Details
.find_by_session_id(session_id) ⇒ Object
24
25
26
27
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 24
def self.find_by_session_id(session_id)
object_hash = get_from_api_method.call("/#{session_id}")
new(object_hash)
end
|
.login(validation_data) ⇒ Object
19
20
21
22
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 19
def self.login(validation_data)
post_to_api_method.call("/login", validation_data)
end
|
Instance Method Details
#accept_invitation(company_id) ⇒ Object
39
40
41
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 39
def accept_invitation(company_id)
post_to_api_method.call("/invitation/#{company_id}/accept")
end
|
#add_company(company_data) ⇒ Object
47
48
49
50
51
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 47
def add_company(company_data)
post_to_api_method.call("/company", company_data.merge({
user_id: session_id
}))
end
|
#add_invite(invite_code) ⇒ Object
34
35
36
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 34
def add_invite(invite_code)
post_to_api_method.call("/invitation/#{invite_code}/add")
end
|
#admin? ⇒ Boolean
15
16
17
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 15
def admin?
@check_admin
end
|
#companies ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 59
def companies
company_arr = get_from_api_method.call("/companies",
{user_id: session_id})
company_arr.map do |company_hash|
Company.new(company_hash)
end
end
|
#company(company_id) ⇒ Object
53
54
55
56
57
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 53
def company(company_id)
company_hsh = get_from_api_method.call("/company/#{company_id}",
{user_id: session_id})
Company.new(company_hsh)
end
|
#reject_invitation(company_id) ⇒ Object
43
44
45
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 43
def reject_invitation(company_id)
post_to_api_method.call("/invitation/#{company_id}/reject")
end
|
#user_admin? ⇒ Boolean
29
30
31
32
|
# File 'lib/driftrock-service/driftrock_model/user.rb', line 29
def user_admin?
response = get_from_api_method.call("/#{session_id}/is_admin")
response['is_admin'] =~ /true/
end
|