Sha256: 9fabb5026a741935df9cd1429382a0fcfc9af8fa6df5f1e6248e4e29502bbd98

Contents?: true

Size: 1.75 KB

Versions: 14

Compression:

Stored size: 1.75 KB

Contents

module TheCity

  class WebHookList 

    include Enumerable

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

    # Constructor.
    #
    # @param options A hash of options for loading the list.
    # 
    # Options:
    #   :page - The page number to get.
    #   :reader - The Reader to use to load the data.
    #
    #
    # Examples:
    #   WebHookListReader.new
    #
    #   UserSkillList.new({:page => 2})
    #    
    def initialize(options = {}) 
      options[:page] ||= 1
      reader = options[:reader] || TheCity::WebHookListReader.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
    

    # All the web_hooks in the list.
    #
    # @return array of web_hook names.
    def all_web_hooks
      return [] if @json_data['web_hooks'].nil?
      @json_data['web_hooks'].collect { |web_hook| [web_hook['object'], web_hook['event']].join('::') }
    end
    alias :web_hooks :all_web_hooks
        
    
    # Get the specified web hook.
    #
    # @param index The index of the web hook to get.
    #
    # @return [WebHook]
    def [](index)
      WebHook.new( @json_data['web_hooks'][index] ) if @json_data['web_hooks'][index]
    end


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

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
the-city-admin-0.5.2 lib/api/web_hook_list.rb
the-city-admin-0.5.1 lib/api/web_hook_list.rb
the-city-admin-0.5.0 lib/api/web_hook_list.rb
the-city-admin-0.4.0 lib/api/web_hook_list.rb
the-city-admin-0.3.1 lib/api/web_hook_list.rb
the-city-admin-0.3.0 lib/api/web_hook_list.rb
the-city-admin-0.2.1 lib/api/web_hook_list.rb
the-city-admin-0.2.0 lib/api/web_hook_list.rb
the-city-admin-0.1.5 lib/api/web_hook_list.rb
the-city-admin-0.1.4 lib/api/web_hook_list.rb
the-city-admin-0.1.3 lib/api/web_hook_list.rb
the-city-admin-0.1.2 lib/api/web_hook_list.rb
the-city-admin-0.1.1 lib/api/web_hook_list.rb
the-city-admin-0.1.0 lib/api/web_hook_list.rb