Sha256: 46685f863a9f099d7ef54a9ca4bc62d47d418224594c7d86ca8bab0f0eb38656

Contents?: true

Size: 860 Bytes

Versions: 1

Compression:

Stored size: 860 Bytes

Contents

module Troo
  class CreateCard
    class << self
      def for(list, name = nil, description = nil)
        new(list, name, description).perform
      end
    end

    def initialize(list, name = nil, description = nil)
      @list        = list
      @name        = name
      @description = description
    end

    def perform
      create_local
    end

    private

    attr_reader :list, :name, :description

    def create_local
      return Persistence::Card.for(create_remote) if create_remote
      false
    end

    def create_remote
      @card ||= Trello::Card.create(attributes)
    rescue Trello::InvalidAccessToken
      raise Troo::InvalidAccessToken
    rescue Trello::Error
      false
    end

    def attributes
      {
        name:    name,
        list_id: list.external_list_id,
        desc:    description
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
troo-0.0.8 lib/troo/actions/create_card.rb