Sha256: dbadd4f51af2da4e7f6ce54680ab544455436eb65d3f1dda48646609ed81188b

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

module Troo
  module Remote
    module Persistence
      class List
        class << self
          # @param  [String]
          # @param  [String]
          # @return []
          def with(external_board_id, name)
            new(external_board_id, name).create_local
          end
        end

        # @param  [String]
        # @param  [String]
        # @return [Troo::Remote::Persistence::List]
        def initialize(external_board_id, name)
          @external_board_id = external_board_id
          @name              = name
        end

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

        private

        attr_reader :external_board_id, :name

        def any?
          resource.any?
        end

        def resource
          @resource ||= API::Client.perform(parameters)
        end

        def parameters
          {
            verb:          :post,
            endpoint:      :create_list,
            interpolation: {},
            query:         query,
            model:         Remote::List
          }
        end

        def query
          {
            name:     name,
            board_id: external_board_id
          }
        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/list.rb
troo-0.0.14 lib/troo/remote/persistence/list.rb
troo-0.0.13 lib/troo/remote/persistence/list.rb
troo-0.0.12 lib/troo/remote/persistence/list.rb