Class: Printavo::Resources::PresetTaskGroups

Inherits:
Base
  • Object
show all
Defined in:
lib/printavo/resources/preset_task_groups.rb

Constant Summary collapse

ALL_QUERY =
File.read(File.join(__dir__, '../graphql/preset_task_groups/all.graphql')).freeze
FIND_QUERY =
File.read(File.join(__dir__, '../graphql/preset_task_groups/find.graphql')).freeze
CREATE_MUTATION =
File.read(File.join(__dir__, '../graphql/preset_task_groups/create.graphql')).freeze
UPDATE_MUTATION =
File.read(File.join(__dir__, '../graphql/preset_task_groups/update.graphql')).freeze
DELETE_MUTATION =
File.read(File.join(__dir__, '../graphql/preset_task_groups/delete.graphql')).freeze
APPLY_MUTATION =
File.read(File.join(__dir__, '../graphql/preset_task_groups/apply.graphql')).freeze

Instance Method Summary collapse

Methods inherited from Base

#all_pages, #each_page, #initialize

Constructor Details

This class inherits a constructor from Printavo::Resources::Base

Instance Method Details

#all(first: 25, after: nil) ⇒ Object



14
15
16
# File 'lib/printavo/resources/preset_task_groups.rb', line 14

def all(first: 25, after: nil)
  fetch_page(first: first, after: after).records
end

#apply(id, order_id:) ⇒ Object



38
39
40
41
# File 'lib/printavo/resources/preset_task_groups.rb', line 38

def apply(id, order_id:)
  data = @graphql.mutate(APPLY_MUTATION, variables: { id: id.to_s, orderId: order_id.to_s })
  data['presetTaskGroupApply'].map { |attrs| Printavo::Task.new(attrs) }
end

#create(**input) ⇒ Object



23
24
25
26
# File 'lib/printavo/resources/preset_task_groups.rb', line 23

def create(**input)
  data = @graphql.mutate(CREATE_MUTATION, variables: { input: camelize_keys(input) })
  Printavo::PresetTaskGroup.new(data['presetTaskGroupCreate'])
end

#delete(id) ⇒ Object



33
34
35
36
# File 'lib/printavo/resources/preset_task_groups.rb', line 33

def delete(id)
  @graphql.mutate(DELETE_MUTATION, variables: { id: id.to_s })
  nil
end

#find(id) ⇒ Object



18
19
20
21
# File 'lib/printavo/resources/preset_task_groups.rb', line 18

def find(id)
  data = @graphql.query(FIND_QUERY, variables: { id: id.to_s })
  Printavo::PresetTaskGroup.new(data['presetTaskGroup'])
end

#update(id, **input) ⇒ Object



28
29
30
31
# File 'lib/printavo/resources/preset_task_groups.rb', line 28

def update(id, **input)
  data = @graphql.mutate(UPDATE_MUTATION, variables: { id: id.to_s, input: camelize_keys(input) })
  Printavo::PresetTaskGroup.new(data['presetTaskGroupUpdate'])
end