Sha256: bb5fc8cba83119df0d8ff8f2e95aa090b80c2bda6d6e07347a5f3bb43059b11b

Contents?: true

Size: 905 Bytes

Versions: 3

Compression:

Stored size: 905 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
      update_comments
    end

    private
    attr_reader :card, :comment

    def update_comments
      return CommentPersistence.for(parsed_json_response) if parsed_json_response
      false
    end

    def parsed_json_response
      return false unless create_comment
      resource = OpenStruct.new(JSON.parse(create_comment))
      resource.member_creator_id = resource.memberCreator.fetch("id", "")
      resource
    end

    def create_comment
      @comment_resource ||= Trello::Card.new.
        update_fields(attributes).add_comment(comment)
    rescue
      false
    end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
troo-0.0.7 lib/troo/actions/create_comment.rb
troo-0.0.6 lib/troo/actions/create_comment.rb
troo-0.0.5 lib/troo/actions/create_comment.rb