Class: TelephoneAppointments::SummaryDocumentActivity

Inherits:
Object
  • Object
show all
Defined in:
lib/telephone_appointments/summary_document_activity.rb

Defined Under Namespace

Classes: InvalidDeliveryMethod

Constant Summary collapse

VALID_DELIVERY_METHODS =
%w(postal digital).freeze
PATH =
'/api/v1/summary_documents'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(appointment_id:, owner_uid:, delivery_method:) ⇒ SummaryDocumentActivity

Returns a new instance of SummaryDocumentActivity.



8
9
10
11
12
13
14
# File 'lib/telephone_appointments/summary_document_activity.rb', line 8

def initialize(appointment_id:, owner_uid:, delivery_method:)
  raise(InvalidDeliveryMethod, delivery_method) unless VALID_DELIVERY_METHODS.include?(delivery_method)

  @appointment_id = appointment_id
  @owner_uid = owner_uid
  @delivery_method = delivery_method
end

Instance Method Details

#errorsObject



26
27
28
29
# File 'lib/telephone_appointments/summary_document_activity.rb', line 26

def errors
  @response || raise(TelephoneAppointments::UnsavedObject, 'Please save the object before accessing the errors')
  @response.errors
end

#saveObject



16
17
18
19
20
21
22
23
24
# File 'lib/telephone_appointments/summary_document_activity.rb', line 16

def save
  @response = TelephoneAppointments.api.post(
    PATH,
    appointment_id: @appointment_id,
    owner_uid: @owner_uid,
    delivery_method: @delivery_method
  )
  @response.success?
end