Class: TransferTo::Reply

Inherits:
Object
  • Object
show all
Defined in:
lib/transfer_to/reply.rb

Instance Method Summary collapse

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_keyObject



63
64
65
# File 'lib/transfer_to/reply.rb', line 63

def auth_key
  data[:authentication_key]
end

#dataObject

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_codeObject



37
38
39
# File 'lib/transfer_to/reply.rb', line 37

def error_code
  data[:error_code]
end

#error_messageObject



41
42
43
# File 'lib/transfer_to/reply.rb', line 41

def error_message
  data[:error_txt]
end

#format_itObject



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

#headersObject



67
68
69
# File 'lib/transfer_to/reply.rb', line 67

def headers
  @response.headers
end

#informationObject



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

#messageObject



59
60
61
# File 'lib/transfer_to/reply.rb', line 59

def message
  information[:info_txt]
end

#rawObject



71
72
73
# File 'lib/transfer_to/reply.rb', line 71

def raw
  @response.body
end

#statusObject



33
34
35
# File 'lib/transfer_to/reply.rb', line 33

def status
  @response.status
end

#success?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/transfer_to/reply.rb', line 45

def success?
  status == 200 && error_code == 0
end

#urlObject



49
50
51
# File 'lib/transfer_to/reply.rb', line 49

def url
  @response.env[:url].to_s
end