Class: Zold::Push

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

Overview

Wallet pushing command

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Push.



32
33
34
35
36
# File 'lib/zold/commands/push.rb', line 32

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

Instance Method Details

#run(_ = []) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/zold/commands/push.rb', line 38

def run(_ = [])
  raise 'The wallet is absent' unless @wallet.exists?
  remote = @remotes.all[0]
  uri = URI("#{remote[:home]}/wallet/#{@wallet.id}")
  response = Http.new(uri).put(File.read(@wallet.path))
  unless response.code == '200'
    raise "Failed to push to #{uri}: #{response.code}/#{response.message}"
  end
  @log.info("The #{@wallet.id} pushed to #{uri}")
end