Class: Apocalyse::Client::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/apocalypse-client/response.rb

Constant Summary collapse

RESULT_OK =
0
RESULT_CLIENT_OUTDATED =
1001

Class Method Summary collapse

Class Method Details

.parse!(response) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/apocalypse-client/response.rb', line 7

def self.parse!(response)
  return if response.code.to_i == 401
  
  if response.code.to_i == 200
    response_obj = JSON.parse(response.body)
    unless response_obj["code"] == RESULT_OK
      perform!(response_obj["code"])
    end
  else
    resolve_invalid_response
  end
  
rescue => e 
  resolve_invalid_response
end

.perform!(result_code) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/apocalypse-client/response.rb', line 23

def self.perform!(result_code)
  case result_code
    when RESULT_CLIENT_OUTDATED
      puts "Received update result code"            
      ::Apocalyse::Client::Install.new.self_update!

    else
      resolve_invalid_response
    end
end

.resolve_invalid_responseObject



34
35
36
37
# File 'lib/apocalypse-client/response.rb', line 34

def self.resolve_invalid_response
  puts "Invalid response, let's try to update."
  ::Apocalyse::Client::Install.new.self_update!
end