lib/zold/commands/push.rb in zold-0.0.5 vs lib/zold/commands/push.rb in zold-0.0.6
- old
+ new
@@ -16,10 +16,11 @@
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+require 'net/http'
require_relative '../log.rb'
# PUSH command.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2018 Zerocracy, Inc.
@@ -32,9 +33,17 @@
@log = log
end
def run
raise 'The wallet is absent' unless @wallet.exists?
- raise 'PUSH is not implemented yet'
+ request = Net::HTTP::Put.new("/wallets/#{@wallet.id}")
+ request.body = File.read(@wallet.path)
+ response = Net::HTTP.new('b1.zold.io', 80).start do |http|
+ http.request(request)
+ end
+ unless response.code.to_i == 200
+ raise "Failed to push to the node, code=#{response.code}"
+ end
+ @log.info("The #{@wallet.id} pushed to the server")
end
end
end