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.1.18 lib/dato/site/repo/item.rb
dato-0.1.17 lib/dato/site/repo/item.rb
dato-0.1.16 lib/dato/site/repo/item.rb
dato-0.1.15 lib/dato/site/repo/item.rb
dato-0.1.14 lib/dato/site/repo/item.rb
dato-0.1.13 lib/dato/site/repo/item.rb
dato-0.1.12 lib/dato/site/repo/item.rb
dato-0.1.11 lib/dato/site/repo/item.rb
dato-0.1.10 lib/dato/site/repo/item.rb
dato-0.1.9 lib/dato/site/repo/item.rb
dato-0.1.8 lib/dato/site/repo/item.rb
dato-0.1.6 lib/dato/site/repo/item.rb