Class: Campfiyah::Account

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subdomain, token) ⇒ Account

Returns a new instance of Account.



5
6
7
8
9
10
# File 'lib/campfiyah/account.rb', line 5

def initialize(subdomain, token)
  @adapter   = Campfiyah.adapter.new(subdomain, token)

  @token     = token
  @subdomain = subdomain
end

Instance Attribute Details

#subdomainObject

Returns the value of attribute subdomain.



3
4
5
# File 'lib/campfiyah/account.rb', line 3

def subdomain
  @subdomain
end

#tokenObject

Returns the value of attribute token.



3
4
5
# File 'lib/campfiyah/account.rb', line 3

def token
  @token
end

Instance Method Details

#room_by_id(id) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/campfiyah/account.rb', line 23

def room_by_id(id)
  if @rooms
    rooms.find {|r| r.id.to_i == id.to_i}
  else
    Room.from_hash(@adapter.room_by_id(id), @adapter)
  end
end

#room_by_name(name) ⇒ Object



31
32
33
# File 'lib/campfiyah/account.rb', line 31

def room_by_name(name)
  rooms.find {|r| r.name == name}
end

#roomsObject



17
18
19
20
21
# File 'lib/campfiyah/account.rb', line 17

def rooms
  @rooms ||= @adapter.rooms.map do |room|
    Room.from_hash(room, @adapter)
  end.sort { |a,b| a.name <=> b.name }
end

#user_by_id(id) ⇒ Object



12
13
14
15
# File 'lib/campfiyah/account.rb', line 12

def user_by_id(id)
  user = @adapter.user_by_id(id)
  User.from_hash(user, @adapter)
end