Class: Woopy::Account

Inherits:
Resource
  • Object
show all
Defined in:
lib/woopy/account.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

headers

Class Method Details

.restore!(subdomain) ⇒ Object

class methods



5
6
7
# File 'lib/woopy/account.rb', line 5

def self.restore!(subdomain)
  Account.put("restore", { subdomain: subdomain })
end

Instance Method Details

#employ(user, role = nil) ⇒ Object

instance methods



10
11
12
# File 'lib/woopy/account.rb', line 10

def employ(user, role = nil)
  Employment.create(account_id: self.id, user_id: user.id, role: role)
end

#employmentsObject



22
23
24
25
26
27
# File 'lib/woopy/account.rb', line 22

def employments
  employments_json = Account.get("#{self.id}/employments")
  employments = employments_json.inject([]) do |memo, employment_json|
    memo << create_employment(employment_json)
  end
end

#find_employment(user) ⇒ Object



35
36
37
38
39
# File 'lib/woopy/account.rb', line 35

def find_employment(user)
  employment_json = Account.get("#{self.id}/users/#{user.id}/employment")

  create_employment(employment_json)
end

#find_user(user_id) ⇒ Object



29
30
31
32
33
# File 'lib/woopy/account.rb', line 29

def find_user(user_id)
  user_json = Account.get("#{self.id}/users/#{user_id}")

  User.new(user_json, true)
end

#grant_role(user, roles) ⇒ Object



41
42
43
44
# File 'lib/woopy/account.rb', line 41

def grant_role(user, roles)
  false unless roles.class == Array
  Account.put("#{self.id}/users/#{user.id}/update_roles", { roles: roles })
end

#make_owner(user, role = nil) ⇒ Object



18
19
20
# File 'lib/woopy/account.rb', line 18

def make_owner(user, role = nil)
  Ownership.create(account_id: self.id, user_id: user.id, role: role)
end

#unemploy(employment) ⇒ Object



14
15
16
# File 'lib/woopy/account.rb', line 14

def unemploy(employment)
  employment.destroy
end