Sha256: 400ed2844a8cb45aecefa4d6eb526cf24636729b44ef931f7f758d50eff5514e

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

module Troo
  module Remote
    module Persistence
      class Card
        class << self
          def with(external_list_id, name = nil, description = nil)
            new(external_list_id, name, description).perform
          end
        end

        def initialize(external_list_id, name = nil, description = nil)
          @external_list_id = external_list_id
          @name             = name
          @description      = description
        end

        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

2 entries across 2 versions & 1 rubygems

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