Class: Paubox::EmailDisposition

Inherits:
Object
  • Object
show all
Defined in:
lib/paubox/email_disposition.rb

Overview

Parses email dispositions from /v1/message_reciept response to friendly Ruby

Defined Under Namespace

Classes: MessageDelivery, MessageDeliveryStatus, MessageMultiDeliveryStatus, ResponseError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ EmailDisposition

Returns a new instance of EmailDisposition.



15
16
17
18
19
20
21
22
23
# File 'lib/paubox/email_disposition.rb', line 15

def initialize(response)
  @response = response
  @raw_json_response = response.to_json
  @source_tracking_id = response.dig('sourceTrackingId')
  @message_data = response.dig('data', 'message')
  @message_id = @message_data ? @message_data['id'] : nil
  @message_deliveries ||= build_message_deliveries
  @errors ||= build_errors
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/paubox/email_disposition.rb', line 7

def errors
  @errors
end

#message_deliveriesObject (readonly)

Returns the value of attribute message_deliveries.



7
8
9
# File 'lib/paubox/email_disposition.rb', line 7

def message_deliveries
  @message_deliveries
end

#message_idObject (readonly)

Returns the value of attribute message_id.



7
8
9
# File 'lib/paubox/email_disposition.rb', line 7

def message_id
  @message_id
end

#raw_json_responseObject (readonly)

Returns the value of attribute raw_json_response.



7
8
9
# File 'lib/paubox/email_disposition.rb', line 7

def raw_json_response
  @raw_json_response
end

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/paubox/email_disposition.rb', line 7

def response
  @response
end

#source_tracking_idObject (readonly)

Returns the value of attribute source_tracking_id.



7
8
9
# File 'lib/paubox/email_disposition.rb', line 7

def source_tracking_id
  @source_tracking_id
end

Instance Method Details

#build_errorsObject



29
30
31
32
33
34
# File 'lib/paubox/email_disposition.rb', line 29

def build_errors
  return [] unless response['errors']

  errors = response['errors']
  errors.map { |e| ResponseError.new(e['code'], e['status'], e['title'], e['details']) }
end

#errors?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/paubox/email_disposition.rb', line 25

def errors?
  errors.any?
end