Class: VBulletin::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/vbulletin/base.rb

Direct Known Subclasses

Forum, Post, Search, Thread

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
# File 'lib/vbulletin/base.rb', line 6

def initialize(url, options = {})
  @uri = URI::parse(url)
  @debug = options[:debug] || false
  @api = self
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



4
5
6
# File 'lib/vbulletin/base.rb', line 4

def debug
  @debug
end

#mechanizeObject

Returns the value of attribute mechanize.



4
5
6
# File 'lib/vbulletin/base.rb', line 4

def mechanize
  @mechanize
end

#uriObject

Returns the value of attribute uri.



4
5
6
# File 'lib/vbulletin/base.rb', line 4

def uri
  @uri
end

Instance Method Details

#construct_full_url(path, params = nil) ⇒ Object



48
49
50
# File 'lib/vbulletin/base.rb', line 48

def construct_full_url(path, params = nil)
  "#{self.uri.scheme}://#{self.uri.host}#{construct_url(path, params)}"
end

#construct_url(path, params = nil) ⇒ Object



44
45
46
# File 'lib/vbulletin/base.rb', line 44

def construct_url(path, params = nil)
  "#{self.uri.path}/#{path}#{VBulletin::Base.hash2get(params)}"
end

#forumsObject



34
35
36
# File 'lib/vbulletin/base.rb', line 34

def forums
  VBulletin::Forum.new(self)
end

#get_indexObject



29
30
31
32
# File 'lib/vbulletin/base.rb', line 29

def get_index
  index = self.mechanize.get(construct_full_url('index.php'))
  puts index.body
end

#login(username, password) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vbulletin/base.rb', line 12

def (username, password)
  mechanize = Mechanize.new
  mechanize.get(construct_full_url('login.php', { 'do' => 'login' })) do ||

    # Submit the login form
    .form_with(:action => 'login.php?do=login') do |f|
      f. = username
      f. = password
    end.click_button

  end

  #raise mechanize.inspect
  self.mechanize = mechanize

end

#searchObject



38
39
40
# File 'lib/vbulletin/base.rb', line 38

def search
  VBulletin::Search.new(self)
end