This repository has been archived by the owner on Nov 1, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathupload.rb
100 lines (83 loc) · 2.91 KB
/
upload.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env ruby
require "form_poster"
require 'net/https'
require "rubygems"
require 'xmlsimple'
# require 'httparty'
require "time"
require "multipart"
user = `git config --global github.user`.strip
token = `git config --global github.token`.strip
filename = "rand#{rand(10000000)}.zip"
`cp upload.rb #{filename}`
# `cp LimeChat.app.zip #{filename}`
# raise "No file specified" unless filename = ARGV[0]
raise "Target file does not exist" unless File.size?(filename)
url = URI.parse "https://github.com/"
http = Net::HTTP.new url.host, url.port
http.use_ssl = url.scheme == 'https'
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
res = http.post_form("/tekkub/github-upload/downloads", {
:file_size => File.size(filename),
:content_type => 'application/octet-stream',
:file_name => filename,
:description => '',
:login => user,
:token => token,
})
date = res["Date"]
data = XmlSimple.xml_in(res.body)
# p RestClient.post('http://rest-test.heroku.com/',
data, headers = Multipart::Post.prepare_query(
"key" => "#{data["prefix"].first}#{filename}",
"Filename" => filename,
"policy" => data["policy"].first,
"AWSAccessKeyId" => data["accesskeyid"].first,
'Content-Type' => 'application/octet-stream',
"signature" => data["signature"].first,
"acl" => data["acl"].first,
"file" => File.new(filename),
"success_action_status" => 201
)
puts data
Net::HTTP.start("github.s3.amazonaws.com") do |http|
res = http.post("/", data, headers)
puts res.body
end
raise "HI!"
mp.post("http://github.s3.amazonaws.com/")
p RestClient.post('http://github.s3.amazonaws.com/',
"file" => File.new(filename),
#Net::HTTP.start("github.s3.amazonaws.com") do |http|
# headers = {
# "Host" => "github.s3.amazonaws.com",
# 'Content-Type' => 'text/plain; charset=utf-8',
# 'Content-Length' => File.size(filename).to_s,
# 'Accept-Types' => 'text/*',
"Filename" => filename,
"key" => "#{data["prefix"].first}#{filename}",
"acl" => data["acl"].first,
'Content-Type' => 'application/octet-stream',
"policy" => data["policy"].first,
# "success_action_status" => "201",
"AWSAccessKeyId" => data["accesskeyid"].first,
"signature" => data["signature"].first
# "Authorization" => "AWS #{data["accesskeyid"].first}:#{data["signature"].first}",
# "x-amz-date" => date
)
# put_data = File.read(filename)
# response = http.send_request('PUT', "/#{data["prefix"].first}#{filename}", put_data, headers)
# puts "Response #{response.code} #{response.message}:\n#{response.body}"
# res = File.open(filename, "rb") do |file|
# http.post_multipart("/", {
# # 'Accept-Types' => 'text/*',
# # :Filename => filename,
# :policy => data["policy"].first,
# # :success_action_status => 201,
# :key => "#{data["prefix"].first}#{filename}",
# :AWSAccessKeyId => data["accesskeyid"].first,
# :signature => data["signature"].first,
# :acl => data["acl"].first,
# :file => file
# })
#end