Module: Infoboxer

Extended by:
Infoboxer
Included in:
Infoboxer
Defined in:
lib/infoboxer.rb,
lib/infoboxer/tree.rb,
lib/infoboxer/parser.rb,
lib/infoboxer/version.rb,
lib/infoboxer/tree/ref.rb,
lib/infoboxer/templates.rb,
lib/infoboxer/tree/html.rb,
lib/infoboxer/tree/list.rb,
lib/infoboxer/tree/math.rb,
lib/infoboxer/tree/node.rb,
lib/infoboxer/tree/text.rb,
lib/infoboxer/wiki_path.rb,
lib/infoboxer/media_wiki.rb,
lib/infoboxer/navigation.rb,
lib/infoboxer/tree/image.rb,
lib/infoboxer/tree/nodes.rb,
lib/infoboxer/tree/table.rb,
lib/infoboxer/parser/html.rb,
lib/infoboxer/parser/util.rb,
lib/infoboxer/tree/inline.rb,
lib/infoboxer/parser/image.rb,
lib/infoboxer/parser/table.rb,
lib/infoboxer/tree/gallery.rb,
lib/infoboxer/parser/inline.rb,
lib/infoboxer/templates/set.rb,
lib/infoboxer/tree/compound.rb,
lib/infoboxer/tree/document.rb,
lib/infoboxer/tree/linkable.rb,
lib/infoboxer/tree/template.rb,
lib/infoboxer/tree/wikilink.rb,
lib/infoboxer/parser/context.rb,
lib/infoboxer/templates/base.rb,
lib/infoboxer/media_wiki/page.rb,
lib/infoboxer/parser/template.rb,
lib/infoboxer/tree/paragraphs.rb,
lib/infoboxer/media_wiki/traits.rb,
lib/infoboxer/navigation/lookup.rb,
lib/infoboxer/parser/paragraphs.rb,
lib/infoboxer/navigation/sections.rb,
lib/infoboxer/navigation/selector.rb,
lib/infoboxer/navigation/wikipath.rb,
lib/infoboxer/navigation/shortcuts.rb,
lib/infoboxer/definitions/en.wikipedia.org.rb

Overview

rubocop:disable Layout/EmptyLinesAroundArguments

Defined Under Namespace

Modules: Navigation, Templates, Tree Classes: MediaWiki, Parser

Constant Summary collapse

WIKIMEDIA_PROJECTS =
{
  wikipedia: 'wikipedia.org',
  wikivoyage: 'wikivoyage.org',
  wikiquote: 'wikiquote.org',
  wiktionary: 'wiktionary.org',
  wikibooks: 'wikibooks.org',
  wikinews: 'wikinews.org',
  wikiversity: 'wikiversity.org',
  wikisource: 'wikisource.org'
}.freeze
WIKIMEDIA_COMMONS =
{
  commons: 'commons.wikimedia.org',
  species: 'species.wikimedia.org',
}.freeze
MAJOR =
0
MINOR =
4
PATCH =
0
PRE =
nil
VERSION =
[MAJOR, MINOR, PATCH, PRE].compact.join('.')

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.user_agent=(ua) ⇒ Object

Sets user agent string globally. Default user agent is Infoboxer::MediaWiki::UA.

User agent can also be rewriten as an option to #wiki method (and its shortcuts like #wikipedia), or by using Infoboxer::MediaWiki#initialize explicitly.



241
242
243
# File 'lib/infoboxer.rb', line 241

def self.user_agent=(ua)
  MediaWiki.user_agent = ua
end

Instance Method Details

#commons(options = {}) ⇒ Object

Includeable version of #commons



# File 'lib/infoboxer.rb', line 99

#species(options = {}) ⇒ Object

Includeable version of #species



# File 'lib/infoboxer.rb', line 135

#url_for(symbol, lang = 'en') ⇒ String

Returns URL of API entry-point for a well-known Wiki-project (wikipedia, wikivoyage etc.) by project's name.

Parameters:

Returns:

  • (String)


190
191
192
193
194
195
196
# File 'lib/infoboxer.rb', line 190

def url_for(symbol, lang = 'en')
  if (domain = WIKIMEDIA_PROJECTS[symbol])
    "https://#{lang}.#{domain}/w/api.php"
  elsif (domain = WIKIMEDIA_COMMONS[symbol])
    "https://#{domain}/w/api.php"
  end
end

#wiki(api_url, options = {}) ⇒ MediaWiki

Default method for creating MediaWiki API client.

Parameters:

  • api_url

    should be URL of api.php for your MediaWiki

  • options (defaults to: {})

    list of options. The only recognized option for now, though, is

    • :user_agent (also aliased as :ua) -- custom User-Agent header.

Returns:

  • (MediaWiki)

    an instance of API client, which you can further use like this:

    Infoboxer.wiki('some_url').get('Some page title')
    


73
74
75
# File 'lib/infoboxer.rb', line 73

def wiki(api_url, **options)
  wikis[api_url] ||= MediaWiki.new(api_url, **options)
end

#wikia(*domains) ⇒ Object

Includeable version of #wikia



# File 'lib/infoboxer.rb', line 146

#wikibooks(lang = 'en', options = {}) ⇒ Object

Includeable version of #wikibooks



# File 'lib/infoboxer.rb', line 105

#wikinews(lang = 'en', options = {}) ⇒ Object

Includeable version of #wikinews



# File 'lib/infoboxer.rb', line 130

#wikipedia(lang = 'en', options = {}) ⇒ Object Also known as: wp

Includeable version of #wikipedia



# File 'lib/infoboxer.rb', line 92

#wikiquote(lang = 'en', options = {}) ⇒ Object

Includeable version of #wikiquote



# File 'lib/infoboxer.rb', line 110

#wikisObject



68
69
70
# File 'lib/infoboxer.rb', line 68

def wikis
  @wikis ||= {}
end

#wikisource(lang = 'en', options = {}) ⇒ Object

Includeable version of #wikisource



# File 'lib/infoboxer.rb', line 120

#wikiversity(lang = 'en', options = {}) ⇒ Object

Includeable version of #wikiversity



# File 'lib/infoboxer.rb', line 115

#wikivoyage(lang = 'en', options = {}) ⇒ Object

Includeable version of #wikivoyage



# File 'lib/infoboxer.rb', line 125

#wiktionary(lang = 'en', options = {}) ⇒ Object

Includeable version of #wiktionary



# File 'lib/infoboxer.rb', line 141