Sha256: 57ffc85df494ce191aa98c5298af172a643d342f2616adc3f902a5c0fe96adbf

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

module Troo
  module Remote
    module Persistence
      class Card
        class << self
          # @param  [String]
          # @param  [String, NilClass]
          # @param  [String, NilClass]
          # @return []
          def with(external_list_id, name = nil, description = nil)
            new(external_list_id, name, description).perform
          end
        end

        # @param  [String]
        # @param  [String, NilClass]
        # @param  [String, NilClass]
        # @return []
        def initialize(external_list_id, name = nil, description = nil)
          @external_list_id = external_list_id
          @name             = name
          @description      = description
        end

        # @return []
        def perform
          create_local
        end

        private

        attr_reader :external_list_id, :name, :description

        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_card,
            interpolation: {},
            query:         query,
            model:         Remote::Card
          }
        end

        def query
          {
            name:    name,
            list_id: external_list_id,
            desc:    description
          }
        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/card.rb