summaryrefslogtreecommitdiff
path: root/social
blob: db1685c976985eeea2de69569880ff1d0e07e9ed (plain)
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
#!/usr/bin/env ruby
require 'net/http'
require 'uri'

USER = "pdp8"
WWW_DOMAIN = "pdp8.info"
SOCIAL_DOMAIN = "social.#{WWW_DOMAIN}"
SOCIAL_URL = "https://#{SOCIAL_DOMAIN}"

def post path, body
  uri = URI.parse(File.join SOCIAL_URL, path)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  header = { 'Content-Type' => 'text/plain' }
  request = Net::HTTP::Post.new(uri.request_uri, header)
  usr = File.read(".usr").chomp
  pwd = File.read(".pwd").chomp
  request.basic_auth(usr, pwd)
  request.body = body
  response = http.request(request)
  # TODO return error if response.code > 400
  puts(response.body, response.code)
end

def get path
  uri = URI.parse(File.join SOCIAL_URL, path)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  header = { 'Accept' => 'text/plain' }
  request = Net::HTTP::Get.new(uri.request_uri, header)
  usr = File.read(".usr").chomp
  pwd = File.read(".pwd").chomp
  request.basic_auth(usr, pwd)
  response = http.request(request)
  # TODO return error if response.code > 400
  puts(response.code, response.body)
end

# cmd = ARGV.shift
case ARGV.shift
when "post"
  post "outbox", File.read(ARGV[0])
when "follow"
  post "follow", ARGV.join(" ")
when "unfollow"
  post "unfollow", ARGV.join(" ")
when "inbox"
  get "inbox"
end