Module: Sirius
- Extended by:
- Sirius
- Included in:
- Sirius
- Defined in:
- lib/sirius.rb,
lib/sirius/post.rb,
lib/sirius/boards.rb,
lib/sirius/thread.rb,
lib/sirius/version.rb,
lib/sirius/attribute.rb
Overview
Top level module for Sirius
Warning
All methods throws Exception
-
when page not found
-
when timeout error
-
when json parse error
-
otherwise?
Wow!
Possible call methods for each board
Example
# Returns pages count
Sirius::PR::pages # => 20
# Returns all threads
Sirius::PR::page # => [<Thread>...<Thread>]
# Returns all posts from thread
Sirius::PR::thread(1) # => [<Post>...<Posts>]
Defined Under Namespace
Modules: Attribute, Boards Classes: Post, Thread
Constant Summary collapse
- URL =
Default URL for request
"http://2ch.hk"
- TIME =
Default time for request
4
- VERSION =
"0.0.1"
Instance Method Summary collapse
-
#page(board, page_num = nil) ⇒ Object
(also: #threads)
Get all threads from page.
-
#pages(board) ⇒ Object
Get count pages for
board
Return Fixnum. -
#thread(board, num) ⇒ Object
Get all posts from thread Return Array of posts.
Instance Method Details
#page(board, page_num = nil) ⇒ Object Also known as: threads
Get all threads from page. Return Array of threads for board
from page
.
Attributes
-
board
- board for request -
page_num
- page_num, default is ‘nil`[wakaba page or 0]
Example
# Return all threads from 0 page for `pr`
Sirius::page('pr') #=> [<Thread>...<Thread>]
# For `b`, 1st page
Sirius::page('b', 1) #=> [<Thread>...<Thread>]
68 69 70 |
# File 'lib/sirius.rb', line 68 def page(board, page_num = nil) get(board, page_num)[:threads].inject([]){|m, z| m << Thread.new(z.merge({:board => board})) } end |
#pages(board) ⇒ Object
Get count pages for board
Return Fixnum
Attributes
-
board
- board for request
Example
# Return pages count from `pr`
Sirius::pages('pr') #=> 20
113 114 115 |
# File 'lib/sirius.rb', line 113 def pages(board) get(board, 1)[:pages].size end |
#thread(board, num) ⇒ Object
Get all posts from thread Return Array of posts
Attributes
-
board
- board -
num
- num of thread
Example
# Return all posts for 1st thread
Sirius::thread('pr', 1) #=> [<Post>...<Post>]
97 98 99 |
# File 'lib/sirius.rb', line 97 def thread(board, num) get("#{board}/res", num)[:thread].inject([]){|m, z| m << Thread.new({:board => board, :posts => [z]}) } end |