Sha256: 55f84efd6ece6188f3eade1c00b66121b2622e9cd3803961452f8693870b498f

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

module Troo
  module Remote
    module Persistence
      class Comment
        class << self
          # @param  [String]
          # @param  []
          # @return []
          def with(external_card_id, comment)
            new(external_card_id, comment).perform
          end
        end

        # @param  [String]
        # @param  []
        # @return []
        def initialize(external_card_id, comment)
          @external_card_id = external_card_id
          @comment          = comment
        end

        # @return []
        def perform
          create_local
        end

        private

        attr_reader :external_card_id, :comment

        def create_local
          return Troo::Persistence::Local
            .with_collection(resource).first if any?
          false
        end

        def any?
          resource.any?
        end

        def resource
          @resource ||= API::Client.perform(parameters)
        end

        def parameters
          {
            verb:          :post,
            endpoint:      :create_comment,
            interpolation: interpolation,
            query:         query,
            model:         Remote::Comment
          }
        end

        def interpolation
          { external_id: external_card_id }
        end

        def query
          { text: comment }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
troo-0.0.11 lib/troo/remote/persistence/comment.rb