Sha256: 85d069f0e9206e5b1eb2d3501c87add1887c3a2ce2fdfc311443a40da8d42e99

Contents?: true

Size: 1.06 KB

Versions: 1

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[:description],
                                'idBoard'   => @board_id,
                                'idList'    => args[:list_id],
                                'idMembers' => member_ids.join(",")
        card.save
      end

      private

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

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trello_cli-0.3.0 lib/trello_cli/requests/create_card.rb