Class: Printavo::Resources::Customers
- Defined in:
- lib/printavo/resources/customers.rb
Constant Summary collapse
- ALL_QUERY =
File.read(File.join(__dir__, '../graphql/customers/all.graphql')).freeze
- FIND_QUERY =
File.read(File.join(__dir__, '../graphql/customers/find.graphql')).freeze
- CREATE_MUTATION =
File.read(File.join(__dir__, '../graphql/customers/create.graphql')).freeze
- DELETE_MUTATION =
File.read(File.join(__dir__, '../graphql/customers/delete.graphql')).freeze
- UPDATE_MUTATION =
File.read(File.join(__dir__, '../graphql/customers/update.graphql')).freeze
Instance Method Summary collapse
- #all(first: 25, after: nil) ⇒ Object
-
#create(primary_contact:, **input) ⇒ Printavo::Customer
Creates a new customer.
-
#delete(id) ⇒ nil
Permanently deletes a customer by ID.
- #find(id) ⇒ Object
-
#update(id, **input) ⇒ Printavo::Customer
Updates an existing customer by ID.
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
13 14 15 |
# File 'lib/printavo/resources/customers.rb', line 13 def all(first: 25, after: nil) fetch_page(first: first, after: after).records end |
#create(primary_contact:, **input) ⇒ Printavo::Customer
Creates a new customer. Requires a primary_contact hash with at least
firstName and email. Optional keyword arguments map to CustomerCreateInput.
33 34 35 36 37 |
# File 'lib/printavo/resources/customers.rb', line 33 def create(primary_contact:, **input) variables = { input: camelize_keys(input).merge(primaryContact: primary_contact) } data = @graphql.mutate(CREATE_MUTATION, variables: variables) build_customer(data['customerCreate']) end |
#delete(id) ⇒ nil
Permanently deletes a customer by ID.
59 60 61 62 |
# File 'lib/printavo/resources/customers.rb', line 59 def delete(id) @graphql.mutate(DELETE_MUTATION, variables: { id: id.to_s }) nil end |
#find(id) ⇒ Object
17 18 19 20 |
# File 'lib/printavo/resources/customers.rb', line 17 def find(id) data = @graphql.query(FIND_QUERY, variables: { id: id.to_s }) Printavo::Customer.new(data['customer']) end |
#update(id, **input) ⇒ Printavo::Customer
Updates an existing customer by ID.
46 47 48 49 50 |
# File 'lib/printavo/resources/customers.rb', line 46 def update(id, **input) data = @graphql.mutate(UPDATE_MUTATION, variables: { id: id.to_s, input: camelize_keys(input) }) build_customer(data['customerUpdate']) end |