Sha256: 1fbf4df0729b9dd726566083cfec7867b43dbdbb6f9d156c343b7fb8e1497ee4

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

module Troo
  module Remote
    module Persistence
      class Comment
        class << self
          def with(external_card_id, comment)
            new(external_card_id, comment).perform
          end
        end

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

        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

2 entries across 2 versions & 1 rubygems

Version Path
troo-0.0.10 lib/troo/remote/persistence/comment.rb
troo-0.0.9 lib/troo/remote/persistence/comment.rb