Class: VBulletin::Search
- Inherits:
-
Base
- Object
- Base
- VBulletin::Search
show all
- Defined in:
- lib/vbulletin/search.rb
Instance Attribute Summary
Attributes inherited from Base
#debug, #mechanize, #uri
Instance Method Summary
collapse
Methods inherited from Base
#construct_full_url, #construct_url, #forums, #get_index, #login, #search
Constructor Details
#initialize(api, options = {}) ⇒ Search
4
5
6
7
|
# File 'lib/vbulletin/search.rb', line 4
def initialize(api, options = {})
@api = api
@debug = options[:debug] || false
end
|
Instance Method Details
#find_posts_by_user_id(user_id, options = {}) ⇒ Object
9
10
11
12
|
# File 'lib/vbulletin/search.rb', line 9
def find_posts_by_user_id(user_id, options = {})
@perpage = options[:perpage] || 10
parse_index(@api.construct_full_url("search.php", { 'do' => 'finduser', 'u' => user_id }), @perpage)
end
|
#find_thread_by_post_id(post_id) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/vbulletin/search.rb', line 14
def find_thread_by_post_id(post_id)
if (result = @api.mechanize.get(@api.construct_full_url("printthread.php", { 'p' => post_id, 'pp' => 1 })))
thread_link = result.search('//a[@accesskey="3"]').first
thread_title = thread_link.content
thread_id = CGI.parse(URI.parse(thread_link['href']).query)['t'][0]
thread_author = result.search('//td[@class="page"]/table/tr/td').first
thread_created_at = result.search('//td[@class="page"]/table/tr/td[@class="smallfont"]').first.inner_html
forum = result.links_with(:href => /forumdisplay.php/).first
thread_forum_name = forum.text
thread_forum_id = CGI.parse(URI.parse(forum.href).query)['f'][0]
forum = VBulletin::Forum.new(:id => thread_forum_id, :name => thread_forum_name)
VBulletin::Thread.new(:id => thread_id, :title => thread_title, :created_at => thread_created_at, :forum => forum)
end
end
|