Sha256: 0cdb94132b095264ae6618afb97f57075771d73ae942db3655cd54c2da3cd43a

Contents?: true

Size: 805 Bytes

Versions: 4

Compression:

Stored size: 805 Bytes

Contents

module TrelloFlow
  module Api
    class Card < Base
      has_many :checklists

      def self.fields
        [:name]
      end

      def self.find_by_url(url)
        id = url.scan(/\/c\/(.+)\//).flatten.first
        find(id)
      end

      def self.for(user)
        with("members/:username/cards/open").where(username: user.username)
      end

      def add_member(user)
        return if member_ids.include?(user.id)
        self.class.with("cards/:id/members").where(id: id, value: user.id).post
      end

      def find_or_create_checklist
        Table.pick(checklists) || Checklist.create(idCard: id, name: "To-Do")
      end

      def url
        attributes[:shortUrl]
      end

      private

        def member_ids
          attributes["idMembers"] || []
        end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
trello_flow-1.3.0 lib/trello_flow/api/card.rb
trello_flow-1.2.2 lib/trello_flow/api/card.rb
trello_flow-1.2.1 lib/trello_flow/api/card.rb
trello_flow-1.2.0 lib/trello_flow/api/card.rb