Sha256: 063f0216f3e825e7b447f94b68f4f65a5ee4012a58acaa6594e966f4df19c587

Contents?: true

Size: 1.54 KB

Versions: 7

Compression:

Stored size: 1.54 KB

Contents

module TheCity

  class InvitationList 

    include Enumerable

    attr_reader :total_entries, :total_pages, :per_page, :current_page

    # Constructor.
    #
    # @param options A hash of options for loading the list.
    # 
    # Options:
    #   :group_id - The ID of the group to load the roles for. (required)
    #   :page - The page number to get.
    #   :reader - The Reader to use to load the data.
    #
    #
    # Examples:
    #   InvitationList.new({:group_id => 12345})
    #
    #   InvitationList.new({:group_id => 12345, :page => 2})
    #    
    def initialize(options = {}) 
      reader = options[:reader] || TheCity::InvitationListReader.new(options)  
      @json_data = reader.load_feed

      @total_entries = @json_data['total_entries']
      @total_pages = @json_data['total_pages']
      @per_page = @json_data['per_page']
      @current_page = @json_data['current_page']      
    end
    
    
    # Get the specified group invitation.
    #
    # @param index The index of the group invitation to get.
    #
    # @return [Invitation]
    def [](index)
      Invitation.new( @json_data['invitations'][index] ) if @json_data['invitations'][index]
    end


    # This method is needed for Enumerable.
    def each &block
      @json_data['invitations'].each{ |invitation| yield( Invitation.new(invitation) )}
    end    
  
    # Alias the count method
    alias :size :count

    # Checks if the list is empty.
    #
    # @return True on empty, false otherwise.
    def empty?
      @json_data['invitations'].empty?
    end

  end
  
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
the-city-admin-0.5.2 lib/api/invitation_list.rb
the-city-admin-0.5.1 lib/api/invitation_list.rb
the-city-admin-0.5.0 lib/api/invitation_list.rb
the-city-admin-0.4.0 lib/api/invitation_list.rb
the-city-admin-0.3.1 lib/api/invitation_list.rb
the-city-admin-0.3.0 lib/api/invitation_list.rb
the-city-admin-0.2.1 lib/api/invitation_list.rb