Class: Zold::Pull

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/commands/pull.rb

Overview

Wallet pulling command

Instance Method Summary collapse

Constructor Details

#initialize(wallet:, log: Log::Quiet.new) ⇒ Pull

Returns a new instance of Pull.



30
31
32
33
# File 'lib/zold/commands/pull.rb', line 30

def initialize(wallet:, log: Log::Quiet.new)
  @wallet = wallet
  @log = log
end

Instance Method Details

#runObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/zold/commands/pull.rb', line 35

def run
  request = Net::HTTP::Get.new("/wallets/#{@wallet.id}")
  response = Net::HTTP.new('b1.zold.io', 80).start do |http|
    http.request(request)
  end
  unless response.code.to_i == 200
    raise "Failed to pull from the the node, code=#{response.code}"
  end
  File.write(@wallet.path, response.body)
  @log.info("The #{@wallet} pulled from the server")
  @wallet
end