vpsmatrix 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afded7fd885dfdc8278a33fc8de70910cc7d03ee
4
- data.tar.gz: 380d795e363890d61db609b159e8c92074703321
3
+ metadata.gz: 72c161a134c74fe3af5b21abcfcde1975f95e017
4
+ data.tar.gz: d41715644f3009c2c67b1e9a808f49bf9dd32ab1
5
5
  SHA512:
6
- metadata.gz: b92a221065b57ba25103400c4c3e70f51fcccf25f8ad03a665aee278a9e813d196a7f544f923ed331d05f698f5ea42a00ad01dfbc9af50860fb0406d4470ffd8
7
- data.tar.gz: d0ee500900f8a37dff48ae8c44abb49ba8b922242673b43427de89285972c837bd3bc5628a291e681d9854762f933a086e12b001d2c5d8b4250e65ab084127c7
6
+ metadata.gz: 5d83c10ad596f91a2af58b9ad9af19c2954d6ba403955bf3455dbdca429b12f9d4a4ecacbefe6c75f645c26796a1b22d1415cb0ffdd8ef95fbfa3b2a2ae6dd9b
7
+ data.tar.gz: cc07abe804ff98f2a43ab1694a557984cd009433e29750c066a03b7763c2fac2139e5e2aa063afa99e8199059e18231ad9f2992db57e12cc2d566ab82f83ca5c
@@ -1,6 +1,7 @@
1
1
  require 'digest'
2
2
  require 'net/http'
3
3
  require 'uri'
4
+ require 'securerandom'
4
5
  require_relative 'config'
5
6
 
6
7
  class Starter
@@ -53,9 +54,9 @@ class Starter
53
54
  Config.new.write 'api_key', api_key
54
55
  end
55
56
 
56
- register_email
57
- #read_files
58
- #stream_file
57
+ #register_email
58
+ read_files
59
+ stream_file
59
60
 
60
61
  # https://api.vpsmatrix.net/uploads/get_new_files
61
62
 
@@ -76,21 +77,31 @@ class Starter
76
77
  end
77
78
 
78
79
  def read_files
80
+ @multipart_boundary = '-'*16 + SecureRandom.hex(32)
79
81
 
80
82
  puts 'Writing files to temporary file'
81
83
  # TODO check size of directory
82
84
  working_dir = Dir.pwd
83
85
  list_of_files = Dir.glob "#{working_dir}/**/*"
84
- list_of_files.reject! {|path| path =~ /\/log|\/tmp/}
85
- File.open("files_to_send", 'w') do |temp_file|
86
+ list_of_files.reject! {|path| path =~ /#{working_dir}\/log|#{working_dir}\/tmp/}
87
+ unless Dir.exists?("tmp")
88
+ Dir.mkdir("tmp")
89
+ end
90
+ File.open("tmp/files_to_send", 'w') do |temp_file|
91
+ temp_file.write "#{@multipart_boundary}\n"
86
92
  list_of_files.each do |file|
87
93
  if File.file? file
88
- file_content = File.read(file)
89
- temp_file.write "#{file}\n"
94
+ file_content = File.read(file, mode: 'rb')
95
+ temp_file.write "#{working_dir.split('/').last + file.split(working_dir).last}\n"
96
+ temp_file.write "#{file_content.size}\n"
90
97
  temp_file.write "#{file_content}\n"
91
98
  temp_file.write "#{Digest::SHA256.hexdigest(file_content)}\n"
99
+ else
100
+ temp_file.write "#{working_dir.split('/').last + file.split(working_dir).last}\n"
101
+ temp_file.write "DIR\n"
92
102
  end
93
103
  end
104
+ temp_file.write "#{@multipart_boundary}\n"
94
105
  end
95
106
  end
96
107
 
@@ -99,17 +110,19 @@ class Starter
99
110
  uri = URI.parse("https://api.vpsmatrix.net/uploads/send_new_files")
100
111
 
101
112
  # stream version
102
- Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
113
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true, :read_timeout => 500) do |http|
103
114
  req = Net::HTTP::Put.new(uri)
115
+ req.add_field("Content-Type","multipart/form-data; boundary=#{@multipart_boundary}")
104
116
  req.add_field('Transfer-Encoding', 'chunked')
105
117
  req.basic_auth("test_app", "test_app")
106
- req.body_stream = File.open("files_to_send")
118
+ req.body_stream = File.open("tmp/files_to_send")
107
119
 
108
120
  http.request req do |response|
109
121
  # puts response
110
122
  response.read_body do |chunk|
111
123
  puts chunk
112
124
  end
125
+ puts response.code
113
126
  end
114
127
  end
115
128
  end
@@ -121,7 +134,7 @@ class Starter
121
134
  Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
122
135
  request = Net::HTTP::Put.new(uri.request_uri)
123
136
  request.basic_auth("test_app", "test_app")
124
- request.set_form_data({"file" => File.read("files_to_send")})
137
+ request.set_form_data({"file" => File.read("tmp/files_to_send")})
125
138
  http.request request
126
139
  end
127
140
  end
@@ -1,3 +1,3 @@
1
1
  module Vpsmatrix
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vpsmatrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - mousse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-22 00:00:00.000000000 Z
11
+ date: 2016-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler