class Dangeru
Constants
- API
- Dummy_uri
Public Class Methods
new(url="dangeru.us", https=false)
click to toggle source
# File lib/dangeru.rb, line 13 def initialize(url="dangeru.us", https=false) @hostname = url @ssl = https end
Public Instance Methods
auth(name, pass)
click to toggle source
Used to authenticate as janitor Returns an auth cookie
# File lib/dangeru.rb, line 54 def auth(name, pass) res = post("/mod", nil, {"username": name, "password": pass}) jar = HTTP::CookieJar.new res.get_fields("Set-Cookie").each do |value| jar.parse(value, Dummy_uri) end jar end
find_post(board, title, cookie = nil)
click to toggle source
Used to find a post by title Returns the post on success, and false on failure
# File lib/dangeru.rb, line 42 def find_post(board, title, cookie = nil) get_board(board, cookie).each do |post| if post["title"] == title return post end end return false end
get(route, cookie = nil, params = nil)
click to toggle source
Helper functions
# File lib/dangeru.rb, line 124 def get(route, cookie = nil, params = nil) if @ssl then uri = URI("https://#{@hostname}/#{route}") else uri = URI("http://#{@hostname}/#{route}") end uri.query = URI.www_encode_form(params) if params Net::HTTP.start(@hostname, :use_ssl => @ssl) do |http| request = Net::HTTP::Get.new uri request["Cookie"] = HTTP::Cookie.cookie_value(cookie.cookies) if cookie http.request request end end
get_board(board, cookie = nil)
click to toggle source
Used to get entries from a board Returns a formatted JSON entry for the board
# File lib/dangeru.rb, line 21 def get_board(board, cookie = nil) JSON.parse(get(API + "/board/" + board, cookie).body) end
get_thread_metadata(id, cookie = nil)
click to toggle source
Used to get metadata from a thread Returns a formatted JSON entry for the metadata
# File lib/dangeru.rb, line 35 def get_thread_metadata(id, cookie = nil) JSON.parse(get(API + "/thread/" + id.to_s + "/metadata", cookie).body) end
get_thread_replies(id, cookie = nil)
click to toggle source
Used to get replies from a thread Returns a formatted JSON entry for the replies
# File lib/dangeru.rb, line 28 def get_thread_replies(id, cookie = nil) JSON.parse(get(API + "/thread/" + id.to_s + "/replies", cookie).body) end
lock(id, cookie)
click to toggle source
Used to lock a post Returns nothing
# File lib/dangeru.rb, line 104 def lock(id, cookie) get("/lock/" + id.to_s, cookie) end
move(id, to, cookie)
click to toggle source
Used to move a post Returns nothing
# File lib/dangeru.rb, line 118 def move(id, to, cookie) post("/move/" + id.to_s, cookie, {"board" => to}) end
post(route, cookie = nil, params = nil)
click to toggle source
# File lib/dangeru.rb, line 138 def post(route, cookie = nil, params = nil) Net::HTTP.start(@hostname, :use_ssl => @ssl) do |http| request = Net::HTTP::Post.new route request.set_form_data(params) if params request["Cookie"] = HTTP::Cookie.cookie_value(cookie.cookies) if cookie http.request request end end
post_op(board, title, comment, cookie=nil, capcode=false)
click to toggle source
Used to post an OP to a board Returns nothing
# File lib/dangeru.rb, line 66 def post_op(board, title, comment, cookie=nil, capcode=false) unless capcode then post("/post", cookie, {"board" => board, "title" => title, "comment" => comment}) else post("/post", cookie, {"board" => board, "title" => title, "comment" => comment, "capcode" => "true"}) end end
reply(parent_id, board, comment, cookie=nil, capcode=false)
click to toggle source
Used to reply to an OP Returns nothing
# File lib/dangeru.rb, line 77 def reply(parent_id, board, comment, cookie=nil, capcode=false) unless capcode then post("/reply", cookie, {"board" => board, "parent" => parent_id.to_s, "content" => comment}) else post("/reply", cookie, {"board" => board, "parent" => parent_id.to_s, "content" => comment, "capcode" => "true"}) end end
sticky(id, cookie, stickyness=1)
click to toggle source
Used to sticky a post Returns nothing
# File lib/dangeru.rb, line 90 def sticky(id, cookie, stickyness=1) post("/sticky/" + id.to_s, cookie, {"stickyness" => stickyness}) end
unlock(id, cookie)
click to toggle source
Used to unlock a post Returns nothing
# File lib/dangeru.rb, line 111 def unlock(id, cookie) get("/unlock/" + id.to_s, cookie) end
unsticky(id, cookie)
click to toggle source
Used to unsticky a post Returns nothing
# File lib/dangeru.rb, line 97 def unsticky(id, cookie) get("/unsticky/" + id.to_s, cookie) end