Class: MediaWiktory::Wikipedia::Api

Inherits:
Object
  • Object
show all
Includes:
Actions
Defined in:
lib/mediawiktory/wikipedia/api.rb

Overview

Base API class for Wikipedia.

Example of usage:

# For Wikipedia
api = MediaWiktory::Wikipedia::Api.new
api.some_action.some_param(value).other_param(*more_values).perform
# => returns raw response of MediaWiki API
api.some_action.some_param(value).other_param(*more_values).response
# => returns an instance of Response, parsed from JSON

# For any other site:
api = MediaWiktory::Wikipedia::Api.new('https://some.site/w/api.php')
# ...the same as above

Actions module lists all available API actions and refers to corresponding classes and their options.

See also Response for working with return values and MediaWiktory::Wikipedia::Actions::Base for working with actions.

Instance Method Summary collapse

Methods included from Actions

#abusefiltercheckmatch, #abusefilterchecksyntax, #abusefilterevalexpression, #abusefilterunblockautopromote, #addstudents, #antispoof, #block, #bouncehandler, #categorytree, #centralauthtoken, #centralnoticechoicedata, #centralnoticequerycampaign, #changeauthenticationdata, #checktoken, #cirrus_config_dump, #cirrus_mapping_dump, #cirrus_settings_dump, #clearhasmsg, #clientlogin, #compare, #createaccount, #cspreport, #cxconfiguration, #cxdelete, #cxpublish, #cxsave, #cxsuggestionlist, #cxtoken, #delete, #deleteeducation, #deleteglobalaccount, #echomarkread, #echomarkseen, #edit, #editmassmessagelist, #emailuser, #enlist, #expandtemplates, #fancycaptchareload, #featuredfeed, #feedcontributions, #feedrecentchanges, #feedwatchlist, #filerevert, #flagconfig, #globalblock, #globaluserrights, #graph, #help, #imagerotate, #import, #jsonconfig, #jsondata, #languagesearch, #linkaccount, #liststudents, #login, #logout, #managetags, #massmessage, #mergehistory, #mobileview, #move, #oathvalidate, #opensearch, #options, #pagetriageaction, #pagetriagelist, #pagetriagestats, #pagetriagetagging, #pagetriagetemplate, #paraminfo, #parse, #parsoid_batch, #patrol, #protect, #purge, #query, #refresheducation, #removeauthenticationdata, #resetpassword, #review, #reviewactivity, #revisiondelete, #rollback, #rsd, #sanitize_mapdata, #scribunto_console, #setglobalaccountstatus, #setnotificationtimestamp, #setpagelanguage, #shortenurl, #sitematrix, #spamblacklist, #stabilize, #stashedit, #strikevote, #tag, #templatedata, #thank, #titleblacklist, #tokens, #transcodereset, #ulslocalization, #unblock, #undelete, #unlinkaccount, #upload, #userrights, #validatepassword, #visualeditor, #visualeditoredit, #watch, #webapp_manifest, #wikilove, #zeroconfig

Constructor Details

#initialize(url = 'https://en.wikipedia.org/w/api.php', **defaults) ⇒ Api

Returns a new instance of Api.

Parameters:

  • url (String) (defaults to: 'https://en.wikipedia.org/w/api.php')

    Source URL for this API, by default "". Note that most of MediaWiki installations have source URL at /w/api.php, but some are just /api.php, others use /wiki/api.php and so on.

  • defaults (Hash)

    Default options for all API queries. Default param values also can be set by subsequent MediaWiktory::Wikipedia::Actions::Base methods, like api.some_action.json(callback: 'mycallbackname')...

Options Hash (**defaults):



69
70
71
72
# File 'lib/mediawiktory/wikipedia/api.rb', line 69

def initialize(url = 'https://en.wikipedia.org/w/api.php', **defaults)
  client_options, @defaults = defaults.partition { |k, _| CLIENT_OPTIONS.include?(k) }.map(&:to_h)
  @client = Client.new(url, **client_options)
end

Instance Method Details

#inspectObject



74
75
76
# File 'lib/mediawiktory/wikipedia/api.rb', line 74

def inspect
  "#<#{self.class.name}(#{@client.url})>"
end