class ALD::API::UserCollection
Public: Represents a collection of users on an ALD
server.
Constants
- ARRAY_CONDITIONS
Internal: filter conditions that allow specifying an array.
- LOCAL_CONDITIONS
Internal: filter conditions that can be handled locally.
- RANGE_CONDITIONS
Internal: filter conditions that allow specifying a range. See
where
.
Public Class Methods
Internal: Create a new collection instance. Library consumers should not directly call this, but instead obtain new instances from API#users
or where
.
api - the ALD::API
instance this collection belongs to conditions - the Hash of conditions users in this collection must meet data - an Array of Hashes containing the data about the users in
the collection. May be nil.
ALD::API::Collection::new
# File lib/ALD/user_collection.rb, line 18 def initialize(api, conditions = {}, data = nil) super(api, conditions, data) end
Private Instance Methods
Internal: Used by Collection#each
and Collection#[]
to create new users.
hash - a Hash describing the item, with the keys ‘id’ and ‘name’ initialized - a Boolean indicating if the given Hash already contains
all information about the user or only name and id.
# File lib/ALD/user_collection.rb, line 120 def entry(hash, initialized = false) @api.user(hash, initialized) end
Internal: Implements user access for []
. See Collection#entry_filter
for more information.
UserCollection
allows access by ID (String) or name (String).
# File lib/ALD/user_collection.rb, line 128 def entry_filter(args) unless args.length == 1 && args.first.is_a?(String) raise ArgumentError end if /^[0-9a-fA-F]{32}$/ =~ args.first { id: @api.normalize_id(args.first) } else { name: args.first } end end
Internal: Make a HTTP request to the ALD
server to get the list of user hashes matching this collection’s conditions.
Returns nothing.
# File lib/ALD/user_collection.rb, line 82 def request data = [ range_condition_queries(%w[joined]), array_queries(%w[privileges]), sort_query, range_query ].reduce({}, :merge) url = "/items/#{data.empty? ? '' : '?'}#{URI.encode_www_form(data)}" @data = @api.request(url).map do |hash| hash['id'] = @api.normalize_id(hash['id']) hash end end
Internal: Make a HTTP request to the ALD
server to get a single user. Used by Collection#[]
.
filter - a filter Hash as returned by entry_filter
Returns a Hash with all information about the user.
Raises ArgumentError if the filters cannot be handled.
# File lib/ALD/user_collection.rb, line 105 def request_entry(filter) url = if %w[id name].any? { |k| filter.key?(k.to_sym) } "/users/#{filter[:id] || filter[:name]}" else raise ArgumentError end @api.request(url) end