module Fourchan::Kit::API

This module contains methods for the 4chan API.

They all parse the JSON 4chan delivers and returns an Array object.

Public Class Methods

get_boards() click to toggle source

Returns information for all boards across 4chan.

@return [Array] information for all boards.

# File lib/fourchan/kit/api.rb, line 16
def self.get_boards
  JSON.parse(open("http://a.4cdn.org/boards.json").read)['boards']
end
get_catalog(board) click to toggle source

Returns information for all threads on specified board.

@param board [String] the board. @return [Array] all threads for a board.

# File lib/fourchan/kit/api.rb, line 25
def self.get_catalog(board)
  JSON.parse(open("http://a.4cdn.org/#{board}/catalog.json").read)
end
get_page(board, page) click to toggle source

Returns the threads at a page number on specified board.

4chan stopped using zero-index pages in April. Instead of first page is at 0, it is now at 1. 0 returns nothing.

@param board [String] the board. @param page [Integer] the thread number. @return [Array] all threads from a page.

# File lib/fourchan/kit/api.rb, line 57
def self.get_page(board, page)
  JSON.parse(open("http://a.4cdn.org/#{board}/#{page}.json").read)['threads']
end
get_thread(board, thread) click to toggle source

Returns all posts for the specified thread.

@param board [String] the board. @param thread [Integer] the thread number. @return [Array] the posts in from a thread.

# File lib/fourchan/kit/api.rb, line 44
def self.get_thread(board, thread)
  JSON.parse(open("http://a.4cdn.org/#{board}/thread/#{thread}.json").read)['posts']
end
get_threads(board) click to toggle source

Returns only id and time for threads on specified board.

@param board [String] the board. @return [Array] the id and time for all threads.

# File lib/fourchan/kit/api.rb, line 34
def self.get_threads(board)
  JSON.parse(open("http://a.4cdn.org/#{board}/threads.json").read)
end