Class: Dato::Site::Repo::ItemType

Inherits:
Base
  • Object
show all
Defined in:
lib/dato/site/repo/item_type.rb

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Dato::Site::Repo::Base

Instance Method Details

#allObject



30
31
32
# File 'lib/dato/site/repo/item_type.rb', line 30

def all
  get_request '/item-types'
end

#create(resource_attributes) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/dato/site/repo/item_type.rb', line 8

def create(resource_attributes)
  body = JsonApiSerializer.new(
    type: :item_type,
    attributes: %i(api_key name ordering_direction singleton sortable),
    relationships: { ordering_field: { collection: false, type: :field } },
    required_attributes: %i(api_key name ordering_direction singleton sortable)
  ).serialize(resource_attributes)

  post_request '/item-types', body
end

#destroy(item_type_id) ⇒ Object



38
39
40
# File 'lib/dato/site/repo/item_type.rb', line 38

def destroy(item_type_id)
  delete_request "/item-types/#{item_type_id}"
end

#find(item_type_id) ⇒ Object



34
35
36
# File 'lib/dato/site/repo/item_type.rb', line 34

def find(item_type_id)
  get_request "/item-types/#{item_type_id}"
end

#update(item_type_id, resource_attributes) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/dato/site/repo/item_type.rb', line 19

def update(item_type_id, resource_attributes)
  body = JsonApiSerializer.new(
    type: :item_type,
    attributes: %i(api_key name ordering_direction singleton sortable),
    relationships: { ordering_field: { collection: false, type: :field } },
    required_attributes: %i(api_key name ordering_direction singleton sortable)
  ).serialize(resource_attributes, item_type_id)

  put_request "/item-types/#{item_type_id}", body
end