Class: TransferTo::Reply
- Inherits:
-
Object
- Object
- TransferTo::Reply
- Defined in:
- lib/transfer_to/reply.rb
Instance Method Summary collapse
- #auth_key ⇒ Object
-
#data ⇒ Object
get the actual data returned by the TransferTo API.
- #error_code ⇒ Object
- #error_message ⇒ Object
- #format_it ⇒ Object
- #headers ⇒ Object
- #information ⇒ Object
-
#initialize(reply) ⇒ Reply
constructor
“reply” as received from Faraday’s request.
- #message ⇒ Object
- #raw ⇒ Object
- #status ⇒ Object
- #success? ⇒ Boolean
- #url ⇒ Object
Constructor Details
#initialize(reply) ⇒ Reply
“reply” as received from Faraday’s request
5 6 7 |
# File 'lib/transfer_to/reply.rb', line 5 def initialize(reply) @response = reply.to_hash[:response] end |
Instance Method Details
#auth_key ⇒ Object
63 64 65 |
# File 'lib/transfer_to/reply.rb', line 63 def auth_key data[:authentication_key] end |
#data ⇒ Object
get the actual data returned by the TransferTo API
25 26 27 28 29 30 31 |
# File 'lib/transfer_to/reply.rb', line 25 def data hash = {} @response.body.lines.each do |line| key, value = line.strip.split "=" hash[key.to_sym] = (key == "error_code") ? value.to_i : value end; hash end |
#error_code ⇒ Object
37 38 39 |
# File 'lib/transfer_to/reply.rb', line 37 def error_code data[:error_code] end |
#error_message ⇒ Object
41 42 43 |
# File 'lib/transfer_to/reply.rb', line 41 def data[:error_txt] end |
#format_it ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/transfer_to/reply.rb', line 9 def format_it { data: data, status: status, success: success?, method: @response.env[:method], url: url, headers: headers, raw_response: raw } end |
#headers ⇒ Object
67 68 69 |
# File 'lib/transfer_to/reply.rb', line 67 def headers @response.headers end |
#information ⇒ Object
53 54 55 56 57 |
# File 'lib/transfer_to/reply.rb', line 53 def information data.reject do |key, value| [:authentication_key, :error_code, :error_txt].include?(key) end end |
#message ⇒ Object
59 60 61 |
# File 'lib/transfer_to/reply.rb', line 59 def information[:info_txt] end |
#raw ⇒ Object
71 72 73 |
# File 'lib/transfer_to/reply.rb', line 71 def raw @response.body end |
#status ⇒ Object
33 34 35 |
# File 'lib/transfer_to/reply.rb', line 33 def status @response.status end |
#success? ⇒ Boolean
45 46 47 |
# File 'lib/transfer_to/reply.rb', line 45 def success? status == 200 && error_code == 0 end |
#url ⇒ Object
49 50 51 |
# File 'lib/transfer_to/reply.rb', line 49 def url @response.env[:url].to_s end |