Sha256: e975f943355ab45ac28763aca53a53ba1f72588645a5006d6d03ec02db5bc10f

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

require "cp8_cli/storyable"

module Cp8Cli
  module Trello
    class Card < Base
      include Storyable

      belongs_to :board, foreign_key: "idBoard"

      def self.fields
        [:title]
      end

      def self.find_by_url(url)
        card = Card.new(url: url)
        find(card.short_link)
      end

      def title
        name
      end

      def pr_title
        "#{title} [Delivers ##{short_link}]"
      end

      def summary
        "Trello: #{short_url}"
      end

      def start
        move_to board.lists.started
        assign CurrentUser.new
      end

      def short_link
        url.scan(/\/c\/(.+)\//).flatten.first
      end

      # Used by CP-8 bot
      def attach(url:)
        self.class.request(:post, "cards/#{id}/attachments", url: url)
      end

      private

        def short_url
          attributes[:shortUrl]
        end

        def assign(user)
          return if member_ids.include?(user.trello_id)
          self.class.request(:post, "cards/#{id}/members", value: user.trello_id)
        end

        def move_to(list)
          self.class.with("cards/:id/idList").where(id: id, value: list.id).put
        end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cp8_cli-6.0.1 lib/cp8_cli/trello/card.rb
cp8_cli-6.0.0 lib/cp8_cli/trello/card.rb
cp8_cli-5.0.0 lib/cp8_cli/trello/card.rb