Class: Printavo::Resources::CustomAddresses

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

Constant Summary collapse

ALL_QUERY =
File.read(File.join(__dir__, '../graphql/custom_addresses/all.graphql')).freeze
FIND_QUERY =
File.read(File.join(__dir__, '../graphql/custom_addresses/find.graphql')).freeze
CREATE_MUTATION =
File.read(File.join(__dir__, '../graphql/custom_addresses/create.graphql')).freeze
CREATES_MUTATION =
File.read(File.join(__dir__, '../graphql/custom_addresses/creates.graphql')).freeze
UPDATE_MUTATION =
File.read(File.join(__dir__, '../graphql/custom_addresses/update.graphql')).freeze
UPDATES_MUTATION =
File.read(File.join(__dir__, '../graphql/custom_addresses/updates.graphql')).freeze
DELETE_MUTATION =
File.read(File.join(__dir__, '../graphql/custom_addresses/delete.graphql')).freeze
DELETES_MUTATION =
File.read(File.join(__dir__, '../graphql/custom_addresses/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



16
17
18
# File 'lib/printavo/resources/custom_addresses.rb', line 16

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

#create(**input) ⇒ Object



25
26
27
28
# File 'lib/printavo/resources/custom_addresses.rb', line 25

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

#creates(inputs) ⇒ Object



30
31
32
33
# File 'lib/printavo/resources/custom_addresses.rb', line 30

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

#delete(id) ⇒ Object



45
46
47
48
# File 'lib/printavo/resources/custom_addresses.rb', line 45

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

#deletes(ids) ⇒ Object



50
51
52
53
# File 'lib/printavo/resources/custom_addresses.rb', line 50

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

#find(id) ⇒ Object



20
21
22
23
# File 'lib/printavo/resources/custom_addresses.rb', line 20

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

#update(id, **input) ⇒ Object



35
36
37
38
# File 'lib/printavo/resources/custom_addresses.rb', line 35

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

#updates(inputs) ⇒ Object



40
41
42
43
# File 'lib/printavo/resources/custom_addresses.rb', line 40

def updates(inputs)
  data = @graphql.mutate(UPDATES_MUTATION, variables: { inputs: inputs.map { |i| camelize_keys(i) } })
  data['customAddressUpdates'].map { |attrs| Printavo::CustomAddress.new(attrs) }
end