Sha256: ddeff962b92308204567b74ec5de17d8d9f71a96a4a6ae3e78313dd60d6747e0

Contents?: true

Size: 1.52 KB

Versions: 4

Compression:

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

        # @param  [String]
        # @param  [String, NilClass]
        # @param  [String, NilClass]
        # @return [Troo::Remote::Persistence::Card]
        def initialize(external_list_id, name = nil, description = nil)
          @external_list_id = external_list_id
          @name             = name
          @description      = description
        end

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

        private

        attr_reader :external_list_id, :name, :description

        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

4 entries across 4 versions & 1 rubygems

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