class Camdram::User

Attributes

email[RW]
name[RW]

Public Instance Methods

get_orgs() click to toggle source

Return an array of societies the user is authorised for

@return [Array] An array of Camdram::Organisation objects.

# File lib/camdram/user.rb, line 40
def get_orgs
  orgs_share('society')
end
get_shows() click to toggle source

Return an array of shows the user is authorised for

@return [Array] An array of Camdram::Show objects.

# File lib/camdram/user.rb, line 32
def get_shows
  slug = "/auth/account/shows.json"
  get_array(slug, Show)
end
get_venues() click to toggle source

Return an array of venues the user is authorised for

@return [Array] An array of Camdram::Venue objects.

# File lib/camdram/user.rb, line 47
def get_venues
  orgs_share('venue')
end
info() click to toggle source

Return a hash of the user's attributes

@return [Hash] Hash with symbolized keys.

# File lib/camdram/user.rb, line 14
def info
  {
    id: id,
    name: name,
    email: email,
  }
end
url_slug() click to toggle source

Return the unique Camdram URL slug of the user

@return [String] The full URL slug.

# File lib/camdram/user.rb, line 25
def url_slug
  "/auth/account.json"
end

Private Instance Methods

orgs_share(orm_type) click to toggle source

Shared code because Camdram stores venues and societies together in the same table

@param orm_type [String] The ORM type to match against (either “society” or “venue”). @return [Array] An array of objects of the specified ORM type's class.

# File lib/camdram/user.rb, line 57
def orgs_share(orm_type)
  object = case orm_type
    when 'society' then Organisation
    when 'venue' then Venue
  end
  slug = "/auth/account/organisations.json"
  json = get(slug)
  objects = Array.new
  json.each do |obj|
    objects << object.new( obj ) if obj[:_type] == orm_type
  end
  return objects
end