Class: MediaWiki::Gateway
- Inherits:
-
Object
- Object
- MediaWiki::Gateway
- Defined in:
- lib/media_wiki/gateway.rb,
lib/media_wiki/gateway/site.rb,
lib/media_wiki/gateway/files.rb,
lib/media_wiki/gateway/pages.rb,
lib/media_wiki/gateway/query.rb,
lib/media_wiki/gateway/users.rb
Defined Under Namespace
Modules: Files, Pages, Query, Site, Users
Constant Summary collapse
- USER_AGENT =
"#{self}/#{VERSION}"
Class Attribute Summary collapse
-
.default_user_agent ⇒ Object
Returns the value of attribute default_user_agent.
Instance Attribute Summary collapse
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#wiki_url ⇒ Object
readonly
Returns the value of attribute wiki_url.
Instance Method Summary collapse
-
#initialize(url, options = {}, http_options = {}) ⇒ Gateway
constructor
Set up a MediaWiki::Gateway for a given MediaWiki installation.
-
#send_request(form_data, continue_xpath = nil) ⇒ Object
Make generic request to API.
Methods included from Users
#contributions, #create_account, #email_user, #login, #options, #set_groups, #users
Methods included from Query
#custom_query, #search, #semantic_query
Methods included from Pages
#backlinks, #category_members, #create, #delete, #edit, #get, #langlink_for_lang, #langlinks, #list, #move, #protect, #purge, #redirect?, #render, #review, #revision, #undelete
Methods included from Files
#download, #image_info, #images, #upload
Methods included from Site
#export, #extensions, #import, #namespaces_by_prefix, #siteinfo, #version
Constructor Details
#initialize(url, options = {}, http_options = {}) ⇒ Gateway
Set up a MediaWiki::Gateway for a given MediaWiki installation
- url
-
Path to API of target MediaWiki (eg. ‘en.wikipedia.org/w/api.php’)
- options
-
Hash of options
- http_options
-
Hash of options for RestClient::Request (via http_send)
Options:
- :bot
-
When set to true, executes API queries with the bot parameter (see www.mediawiki.org/wiki/API:Edit#Parameters). Defaults to false.
- :ignorewarnings
-
Log API warnings and invalid page titles, instead throwing MediaWiki::APIError
- :limit
-
Maximum number of results returned per search (see www.mediawiki.org/wiki/API:Query_-_Lists#Limits), defaults to the MediaWiki default of 500.
- :logdevice
-
Log device to use. Defaults to STDERR
- :loglevel
-
Log level to use, defaults to Logger::WARN. Set to Logger::DEBUG to dump every request and response to the log.
- :maxlag
-
Maximum allowed server lag (see www.mediawiki.org/wiki/Manual:Maxlag_parameter), defaults to 5 seconds.
- :retry_count
-
Number of times to try before giving up if MediaWiki returns 503 Service Unavailable, defaults to 3 (original request plus two retries).
- :retry_delay
-
Seconds to wait before retry if MediaWiki returns 503 Service Unavailable, defaults to 10 seconds.
- :user_agent
-
User-Agent header to send with requests, defaults to ::default_user_agent or nil.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/media_wiki/gateway.rb', line 34 def initialize(url, = {}, = {}) @options = { bot: false, limit: 500, logdevice: STDERR, loglevel: Logger::WARN, max_results: 500, maxlag: 5, retry_count: 3, retry_delay: 10, user_agent: self.class.default_user_agent }.merge() @log = Logger.new(@options[:logdevice]) @log.level = @options[:loglevel] @http_options, @wiki_url, @cookies, @headers = , url, {}, { 'User-Agent' => [@options[:user_agent], USER_AGENT].compact.join(' '), 'Accept-Encoding' => 'gzip' } end |
Class Attribute Details
.default_user_agent ⇒ Object
Returns the value of attribute default_user_agent.
14 15 16 |
# File 'lib/media_wiki/gateway.rb', line 14 def default_user_agent @default_user_agent end |
Instance Attribute Details
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
56 57 58 |
# File 'lib/media_wiki/gateway.rb', line 56 def @cookies end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
56 57 58 |
# File 'lib/media_wiki/gateway.rb', line 56 def headers @headers end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
56 57 58 |
# File 'lib/media_wiki/gateway.rb', line 56 def log @log end |
#wiki_url ⇒ Object (readonly)
Returns the value of attribute wiki_url.
56 57 58 |
# File 'lib/media_wiki/gateway.rb', line 56 def wiki_url @wiki_url end |
Instance Method Details
#send_request(form_data, continue_xpath = nil) ⇒ Object
Make generic request to API
- form_data
-
hash of attributes to post
- continue_xpath
-
XPath selector for query continue parameter
Returns XML document
64 65 66 |
# File 'lib/media_wiki/gateway.rb', line 64 def send_request(form_data, continue_xpath = nil) make_api_request(form_data, continue_xpath).first end |