Sha256: 80981215777faaac69aa91e4d87b1e27b4a4bef60d71940518612834d4296a17

Contents?: true

Size: 907 Bytes

Versions: 1

Compression:

Stored size: 907 Bytes

Contents

module Troo
  class CreateComment
    class << self
      def for(card, comment)
        new(card, comment).perform
      end
    end

    def initialize(card, comment)
      @card    = card
      @comment = comment
    end

    def perform
      create_local
    end

    private

    attr_reader   :card, :comment
    attr_accessor :comment_resource

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

    def resource
      Remote::Comment.create(comment_resource)
    end

    def create_remote
      @comment_resource ||= Trello::Card.new
                              .update_fields(attributes)
                              .add_comment(comment)
    rescue Trello::InvalidAccessToken
      raise Troo::InvalidAccessToken
    rescue Trello::Error
      false
    end

    def attributes
      { 'id' => card.external_card_id }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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