Sha256: 0b1daacde04261b4a81b4b030ab12e2a800b10cea141dc92d92d7c776aba675a

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 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).create_local
          end
        end

        # @param  [String]
        # @param  []
        # @return [Troo::Remote::Persistence::Comment]
        def initialize(external_card_id, comment)
          @external_card_id = external_card_id
          @comment          = comment
        end

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

        private

        attr_reader :external_card_id, :comment

        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

4 entries across 4 versions & 1 rubygems

Version Path
troo-0.0.15 lib/troo/remote/persistence/comment.rb
troo-0.0.14 lib/troo/remote/persistence/comment.rb
troo-0.0.13 lib/troo/remote/persistence/comment.rb
troo-0.0.12 lib/troo/remote/persistence/comment.rb