-
Notifications
You must be signed in to change notification settings - Fork 0
/
mclient_write.rb
42 lines (32 loc) · 1010 Bytes
/
mclient_write.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
#!/usr/local/env ruby
# coding: utf-8
http_proxy = nil
# use HTTPS
mastodon_server = "mstdn-workers.com"
ENV["SSL_CERT_FILE"] = "cacert.pem"
require 'net/https'
require 'uri'
require 'json'
client_id = nil
client_secret = nil
token = nil
File.open("mclient.token","r"){|f|
token = f.gets.chomp
}
uri = URI.parse("https://" + mastodon_server + "/api/v1/statuses");
proxy_uri = { "addr" => nil, "port" => nil, "user" => nil, "pass" => nil }
if (http_proxy != nil)
puri = URI.parse(http_proxy)
proxy_uri['addr'] = puri.host
proxy_uri['port'] = puri.port
proxy_uri['user'] = puri.user
proxy_uri['pass'] = puri.password
end
http = Net::HTTP.new(uri.host, uri.port,proxy_uri['addr'],proxy_uri['port'],proxy_uri['user'],proxy_uri['pass'])
http.use_ssl = true
req = Net::HTTP::Post.new(uri.path);
#req['Authorization'] = "Bearer " + token
puts "write :"
input = gets
req.set_form_data({'status' => input.encode("UTF-8"), 'visibility' => 'public','bearer_token' => token})
res = http.request(req)