Class: SocketLabs::InjectionApi::SendResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/socketlabs/injectionapi/send_response.rb

Overview

The response of an SocketLabsClient send request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result = nil, transaction_receipt = nil, address_results = nil, response_message = nil) ⇒ SendResponse

Returns a new instance of SendResponse.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/socketlabs/injectionapi/send_response.rb', line 15

def initialize (
    result = nil,
    transaction_receipt= nil,
    address_results= nil,
    response_message= nil
)
  @result = result
  @transaction_receipt = transaction_receipt
  @address_results = []

  unless address_results.nil?
    @address_results = address_results
  end

end

Instance Attribute Details

#address_resultsObject

A Array of AddressResult objects that contain the status of each address that failed. If no messages failed this array is empty.



13
14
15
# File 'lib/socketlabs/injectionapi/send_response.rb', line 13

def address_results
  @address_results
end

#resultObject

The result [SendResult] of the SocketLabsClient send request.



7
8
9
# File 'lib/socketlabs/injectionapi/send_response.rb', line 7

def result
  @result
end

#transaction_receiptObject

The unique key generated by the Injection API if an unexpected error occurs during the SocketLabsClient send request. This unique key can be used by SocketLabs support to troubleshoot the issue.



10
11
12
# File 'lib/socketlabs/injectionapi/send_response.rb', line 10

def transaction_receipt
  @transaction_receipt
end

Instance Method Details

#response_messageObject

A message detailing why the SocketLabsClient send request failed.



32
33
34
35
36
# File 'lib/socketlabs/injectionapi/send_response.rb', line 32

def response_message
  unless @result.nil?
    @result[:message]
  end
end

#response_nameObject



38
39
40
41
42
# File 'lib/socketlabs/injectionapi/send_response.rb', line 38

def response_name
  unless @result.nil?
    @result[:name]
  end
end

#to_jsonObject

build json hash for SendResponse



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/socketlabs/injectionapi/send_response.rb', line 50

def to_json(*)
  json = {
      :result => @result.to_json,
      :transactionReceipt => @transaction_receipt,
      :responseMessage => response_message
  }
  if @address_results.length > 0
    e = Array.new
    @address_results.each do |value|
      e.push(value.to_json)
    end
    json[:messageResults] = e
  end
  json.to_json
end

#to_sObject

Represents the SendResponse as a str.



45
46
47
# File 'lib/socketlabs/injectionapi/send_response.rb', line 45

def to_s
  "#{response_name}: #{response_message}"
end