Class: Printavo::Resources::ProductionFiles

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

Constant Summary collapse

ALL_QUERY =
File.read(File.join(__dir__, '../graphql/production_files/all.graphql')).freeze
FIND_QUERY =
File.read(File.join(__dir__, '../graphql/production_files/find.graphql')).freeze
CREATE_MUTATION =
File.read(File.join(__dir__, '../graphql/production_files/create.graphql')).freeze
CREATES_MUTATION =
File.read(File.join(__dir__, '../graphql/production_files/creates.graphql')).freeze
DELETE_MUTATION =
File.read(File.join(__dir__, '../graphql/production_files/delete.graphql')).freeze
DELETES_MUTATION =
File.read(File.join(__dir__, '../graphql/production_files/deletes.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(order_id:, first: 25, after: nil) ⇒ Object



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

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

#create(**input) ⇒ Object



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

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

#creates(inputs) ⇒ Object



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

def creates(inputs)
  data = @graphql.mutate(CREATES_MUTATION, variables: { inputs: inputs.map { |i| camelize_keys(i) } })
  data['productionFileCreates'].map { |attrs| Printavo::ProductionFile.new(attrs) }
end

#delete(id) ⇒ Object



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

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

#deletes(ids) ⇒ Object



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

def deletes(ids)
  @graphql.mutate(DELETES_MUTATION, variables: { ids: ids.map(&:to_s) })
  nil
end

#find(id) ⇒ Object



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

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