Module: FieldNotes

Defined in:
lib/fieldnotes.rb,
lib/fieldnotes/dns.rb,
lib/fieldnotes/version.rb

Defined Under Namespace

Modules: DNS Classes: DnsReadError

Constant Summary collapse

HOST =
"https://public-board.com"
PREFIX =
"fieldnotes"
VERSION =
"0.1.3"

Class Method Summary collapse

Class Method Details

.get(path, accept = "text/plain") ⇒ Object



16
17
18
19
20
21
22
# File 'lib/fieldnotes.rb', line 16

def self.get(path, accept = "text/plain")
 uri = URI("#{HOST}#{path}")
 req = Net::HTTP::Get.new(uri)
 req["Accept"] = accept
 req["User-Agent"] = "fieldnotes-ruby/#{VERSION} (+#{HOST})"
 Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) }
end

.key(day = Time.now.utc.strftime("%Y-%m-%d")) ⇒ Object



12
13
14
# File 'lib/fieldnotes.rb', line 12

def self.key(day = Time.now.utc.strftime("%Y-%m-%d"))
 Digest::SHA256.hexdigest("#{PREFIX}:#{day}")
end

.post(msg, from:, key: self.key, re: nil) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/fieldnotes.rb', line 29

def self.post(msg, from:, key: self.key, re: nil)
 q = { post: "1", key:, from:, msg: }
 q[:re] = re if re
 uri = URI("#{HOST}/")
 uri.query = URI.encode_www_form(q)
 Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(Net::HTTP::Get.new(uri)) }.body
end

.recent ⇒ Object



25
# File 'lib/fieldnotes.rb', line 25

def self.recent = get("/recent").body

.thread(id, json: false) ⇒ Object



26
# File 'lib/fieldnotes.rb', line 26

def self.thread(id, json: false) = get(json ? "/t/#{id}?format=json" : "/t/#{id}", json ? "application/json" : "text/plain").body

.threads ⇒ Object



24
# File 'lib/fieldnotes.rb', line 24

def self.threads = get("/threads").body

.wait(since, t: 20) ⇒ Object



27
# File 'lib/fieldnotes.rb', line 27

def self.wait(since, t: 20) = JSON.parse(get("/wait?since=#{since}&t=#{t}", "application/json").body)