Class: Printavo::Resources::Threads

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

Constant Summary collapse

ALL_QUERY =
File.read(File.join(__dir__, '../graphql/threads/all.graphql')).freeze
FIND_QUERY =
File.read(File.join(__dir__, '../graphql/threads/find.graphql')).freeze
UPDATE_MUTATION =
File.read(File.join(__dir__, '../graphql/threads/update.graphql')).freeze
EMAIL_MESSAGE_CREATE_MUTATION =
File.read(File.join(__dir__, '../graphql/threads/email_message_create.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



13
14
15
# File 'lib/printavo/resources/threads.rb', line 13

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

#email_message_create(**input) ⇒ Object

Sends an email message on a thread. Returns the raw message hash. A dedicated EmailMessage model is planned for a future version.



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

def email_message_create(**input)
  data = @graphql.mutate(EMAIL_MESSAGE_CREATE_MUTATION,
                         variables: { input: camelize_keys(input) })
  data['emailMessageCreate']
end

#find(id) ⇒ Object



17
18
19
20
# File 'lib/printavo/resources/threads.rb', line 17

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

#update(id, **input) ⇒ Object



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

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