Class: SocketLabs::InjectionApi::Core::InjectionResponseParser
- Inherits:
-
Object
- Object
- SocketLabs::InjectionApi::Core::InjectionResponseParser
- Includes:
- SocketLabs::InjectionApi, Serialization, Message
- Defined in:
- lib/socketlabs/injectionapi/core/injection_response_parser.rb
Constant Summary
Constants included from SocketLabs::InjectionApi
Instance Method Summary collapse
-
#determine_send_result(response_dto, response) ⇒ SendResult
Enumerated SendResult of the payload response from the Injection Api.
-
#get_injection_response_dto(response) ⇒ InjectionResponseDto
Get the InjectionResponseDto from the HttpResponse object.
-
#parse(response) ⇒ SendResponse
Parse the response from the Injection Api into SendResponse.
Instance Method Details
#determine_send_result(response_dto, response) ⇒ SendResult
Enumerated SendResult of the payload response from the Injection Api
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/socketlabs/injectionapi/core/injection_response_parser.rb', line 99 def determine_send_result(response_dto, response) # HttpStatusCode.OK if response.status_code == "200" result_enum = response_dto.error_code if result_enum.nil? || result_enum.empty? result_enum = SendResult.enum["UnknownError"] end # HttpStatusCode.Unauthorized elsif response.status_code == "500" result_enum = SendResult.enum["InternalError"] # HttpStatusCode.Unauthorized elsif response.status_code == "408" result_enum = SendResult.enum["Timeout"] # HttpStatusCode.Unauthorized else result_enum = SendResult.enum["InvalidAuthentication"] end result_enum end |
#get_injection_response_dto(response) ⇒ InjectionResponseDto
Get the InjectionResponseDto from the HttpResponse object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/socketlabs/injectionapi/core/injection_response_parser.rb', line 43 def get_injection_response_dto(response) hash_body = response.to_hash resp_dto = InjectionResponseDto.new if hash_body.key?(:ErrorCode) resp_dto.error_code = SendResult.enum[hash_body[:ErrorCode]] end if hash_body.key?(:TransactionReceipt) resp_dto.transaction_receipt = hash_body[:TransactionReceipt] end if hash_body.key?(:MessageResults) resp_dto. = Array.new = hash_body[:MessageResults] unless .nil? .each do |item| = MessageResultDto.new if item.key?(:Index) .index = item[:Index] end if item.key?(:AddressResults) address_results = item[:AddressResults] unless address_results.nil? address_results.each do |aitem| .address_results.push(SocketLabs::InjectionApi::AddressResult.new(aitem[:EmailAddress], aitem[:Accepted], aitem[:ErrorCode])) end end end if item.key?(:ErrorCode) .error_code = item[:ErrorCode] end resp_dto..push() end end resp_dto end end |
#parse(response) ⇒ SendResponse
Parse the response from the Injection Api into SendResponse
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/socketlabs/injectionapi/core/injection_response_parser.rb', line 17 def parse(response) injection_response = get_injection_response_dto(response) result_enum = determine_send_result(injection_response, response) new_response = SendResponse.new(result_enum) new_response.transaction_receipt = injection_response.transaction_receipt if result_enum == SendResult.enum["Warning"] unless injection_response..nil? || injection_response..length == 0 error_code = injection_response.[0].error_code result_enum = SendResult.enum[error_code] new_response.result = result_enum end end unless injection_response..nil? || injection_response..length == 0 new_response.address_results = injection_response.[0].address_results end new_response end |