Sha256: 8867851ecae2c18aff8b4830ff5cf5b7968a9524b03a16179eead4fb33dc1e48

Contents?: true

Size: 1.29 KB

Versions: 32

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true
require 'dato/site/repo/base'
require 'active_support/core_ext/hash/except'

module Dato
  module Site
    module Repo
      class Item < Base
        def create(resource_attributes)
          body = JsonApiSerializer.new(
            type: :item,
            attributes: resource_attributes.keys - [:item_type, :id],
            relationships: {
              item_type: { collection: false, type: 'item_type' }
            },
            required_relationships: %i(item_type)
          ).serialize(resource_attributes)

          post_request '/items', body
        end

        def update(item_id, resource_attributes)
          resource_attributes = resource_attributes.except(
            :id,
            :updated_at,
            :is_valid,
            :item_type
          )

          body = JsonApiSerializer.new(
            type: :item,
            attributes: resource_attributes.keys
          ).serialize(resource_attributes, item_id)

          put_request "/items/#{item_id}", body
        end

        def all(filters = {})
          get_request '/items', filters
        end

        def find(item_id)
          get_request "/items/#{item_id}"
        end

        def destroy(item_id)
          delete_request "/items/#{item_id}"
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
dato-0.3.3 lib/dato/site/repo/item.rb
dato-0.3.2 lib/dato/site/repo/item.rb
dato-0.3.1 lib/dato/site/repo/item.rb
dato-0.3.0 lib/dato/site/repo/item.rb
dato-0.2.7 lib/dato/site/repo/item.rb
dato-0.2.6 lib/dato/site/repo/item.rb
dato-0.2.4 lib/dato/site/repo/item.rb
dato-0.1.31 lib/dato/site/repo/item.rb
dato-0.1.30 lib/dato/site/repo/item.rb
dato-0.1.29 lib/dato/site/repo/item.rb
dato-0.1.28 lib/dato/site/repo/item.rb
dato-0.1.27 lib/dato/site/repo/item.rb
dato-0.1.26 lib/dato/site/repo/item.rb
dato-0.1.25 lib/dato/site/repo/item.rb
dato-0.1.24 lib/dato/site/repo/item.rb
dato-0.1.23 lib/dato/site/repo/item.rb
dato-0.1.22 lib/dato/site/repo/item.rb
dato-0.1.21 lib/dato/site/repo/item.rb
dato-0.1.20 lib/dato/site/repo/item.rb
dato-0.1.19 lib/dato/site/repo/item.rb