Class: Wikiscript::Client

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/wikiscript/client.rb

Constant Summary collapse

SITE_BASE =
'http://{lang}.wikipedia.org/w/index.php'

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

API_BASE = ‘en.wikipedia.org/w/api.php



13
14
15
16
# File 'lib/wikiscript/client.rb', line 13

def initialize( opts={} )
  @opts   = opts
  @worker = Fetcher::Worker.new
end

Instance Method Details

#text(title, lang: Wikiscript.lang) ⇒ Object

change to: wikitext or raw why? why not? or to raw? why? why not?



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/wikiscript/client.rb', line 19

def text( title, lang: Wikiscript.lang )
  ## todo/fix: convert spaces to _ if not present for wikipedia page title - why ?? why not ???

  ## note: replace lang w/ lang config if present e.g.
  ##   http://{lang}.wikipedia.org/w/index.php
  # becomes
  #   http://en.wikipedia.org/w/index.php  or
  #   http://de.wikipedia.org/w/index.php  etc
  base_url = SITE_BASE.gsub( "{lang}", lang )
  params   = { action: 'raw',
               title:  title }

  get( base_url, params )
end