Sha256: 1dc54edd26188fed8fafe9c5e217631b26aa5747e73b0d90745f61ef33470350

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

module TrelloCli
  module Requests
    class CreateCard

      include Shared

      def initialize
        connect_to_trello
      end

      def create(args)
        @board_id = args[:board_id]

        args[:members].each do |member_username|
          unless members.member_exists_in_board? member_username
            msg = "member '#{member_username}' does not exist in board '#{@board_id}'."
            raise Errors.new msg
          end
        end

        member_ids = args[:members].map do |member_username|
          m = members.find_member_by_username_in_board member_username
          m.attributes[:id]
        end

        card = Trello::Card.new 'name'      => args[:name],
                                'desc'      => args[:desc],
                                'idBoard'   => @board_id,
                                'idList'    => args[:list_id],
                                'idMembers' => member_ids.join(",")
        card.save

        card
      end

      private

      def members
        @members ||= Members.new @board_id
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trello_cli-0.5.0 lib/trello_cli/requests/create_card.rb
trello_cli-0.4.1 lib/trello_cli/requests/create_card.rb
trello_cli-0.4.0 lib/trello_cli/requests/create_card.rb