class TransferTo::Reply

Public Class Methods

new(reply) click to toggle source

“reply” as received from Faraday's request

# File lib/transfer_to/reply.rb, line 5
def initialize(reply)
  @response = reply.to_hash[:response]
end

Public Instance Methods

auth_key() click to toggle source
# File lib/transfer_to/reply.rb, line 63
def auth_key
  data[:authentication_key]
end
data() click to toggle source

get the actual data returned by the TransferTo API

# 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() click to toggle source
# File lib/transfer_to/reply.rb, line 37
def error_code
  data[:error_code]
end
error_message() click to toggle source
# File lib/transfer_to/reply.rb, line 41
def error_message
  data[:error_txt]
end
format_it() click to toggle source
# 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() click to toggle source
# File lib/transfer_to/reply.rb, line 67
def headers
  @response.headers
end
information() click to toggle source
# 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() click to toggle source
# File lib/transfer_to/reply.rb, line 59
def message
  information[:info_txt]
end
raw() click to toggle source
# File lib/transfer_to/reply.rb, line 71
def raw
  @response.body
end
status() click to toggle source
# File lib/transfer_to/reply.rb, line 33
def status
  @response.status
end
success?() click to toggle source
# File lib/transfer_to/reply.rb, line 45
def success?
  status == 200 && error_code == 0
end
url() click to toggle source
# File lib/transfer_to/reply.rb, line 49
def url
  @response.env[:url].to_s
end