Module: Fourchan::Kit::API

Defined in:
lib/fourchan/kit/api.rb

Overview

This module contains methods for the 4chan API.

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

Class Method Summary (collapse)

Class Method Details

+ (Array) get_boards

Returns information for all boards across 4chan.

Returns:

  • (Array)

    information for all boards.



16
17
18
# File 'lib/fourchan/kit/api.rb', line 16

def self.get_boards
  JSON.parse(open("http://a.4cdn.org/boards.json").read)['boards']
end

+ (Array) get_catalog(board)

Returns information for all threads on specified board.

Parameters:

  • board (String)

    the board.

Returns:

  • (Array)

    all threads for a board.



25
26
27
# 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

+ (Array) get_page(board, page)

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.

Parameters:

  • board (String)

    the board.

  • page (Integer)

    the thread number.

Returns:

  • (Array)

    all threads from a page.



57
58
59
# 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

+ (Array) get_thread(board, thread)

Returns all posts for the specified thread.

Parameters:

  • board (String)

    the board.

  • thread (Integer)

    the thread number.

Returns:

  • (Array)

    the posts in from a thread.



44
45
46
# 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

+ (Array) get_threads(board)

Returns only id and time for threads on specified board.

Parameters:

  • board (String)

    the board.

Returns:

  • (Array)

    the id and time for all threads.



34
35
36
# 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