Sha256: c5a3a2b6a979d755a806afe6ef275414fb4f028f3fe071c7fb904d4a6ad3a437

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

module Troo
  module External
    class Board
      class << self
        def fetch(external_id, options = {})
          new(external_id, options).fetch_by_external_id.map do |resource|
            Troo::BoardPersistence.for(resource) unless closed?(resource)
          end
        end

        def fetch_all
          new.fetch_all.map do |resource|
            Troo::BoardPersistence.for(resource) unless closed?(resource)
          end
        end

        private

        def closed?(resource)
          resource.nil? || resource.closed?
        end
      end

      def initialize(external_id = nil, options = {})
        @external_id = external_id
        @options     = options
      end

      def fetch_by_external_id
        [Trello::Board.find(external_id)]
      rescue Trello::InvalidAccessToken
        raise Troo::InvalidAccessToken
      rescue Trello::Error
        []
      end

      def fetch_all
        Trello::Board.all
      rescue Trello::InvalidAccessToken
        raise Troo::InvalidAccessToken
      rescue Trello::Error
        []
      end

      private
      attr_reader :external_id
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
troo-0.0.3 lib/troo/external/board.rb
troo-0.0.2 lib/troo/external/board.rb