Module: MediawikiSelenium::ApiHelper
- Defined in:
- lib/mediawiki_selenium/support/modules/api_helper.rb
Overview
Provides more direct access to the API client from hooks and step definitions.
Instance Method Summary collapse
-
#api ⇒ MediawikiApi::Client
An authenticated MediaWiki API client.
-
#ensure_account(id) ⇒ Object
Ensures the given alternative account exists by attempting to create it via the API.
-
#on_wiki(id) {|wiki_url, api_url| ... } ⇒ Object
Extends parent implementation to also override the API URL.
Instance Method Details
#api ⇒ MediawikiApi::Client
An authenticated MediaWiki API client.
12 13 14 15 16 17 18 19 20 |
# File 'lib/mediawiki_selenium/support/modules/api_helper.rb', line 12 def api @_api_cache ||= {} url = lookup(:mediawiki_api_url, default: api_url_from(lookup(:mediawiki_url))) @_api_cache[[url, user]] ||= MediawikiApi::Client.new(url).tap do |client| client.log_in(user, password) end end |
#ensure_account(id) ⇒ Object
Ensures the given alternative account exists by attempting to create it via the API. Any errors related to the account already existing are swallowed.
28 29 30 31 32 |
# File 'lib/mediawiki_selenium/support/modules/api_helper.rb', line 28 def ensure_account(id) api.create_account(user(id), password(id)) rescue MediawikiApi::ApiError => e raise e unless e.code == 'userexists' end |
#on_wiki(id) {|wiki_url, api_url| ... } ⇒ Object
Extends parent implementation to also override the API URL. If no API URL is explicitly defined for the given alternative, one is constructed relative to the wiki URL.
44 45 46 47 48 49 |
# File 'lib/mediawiki_selenium/support/modules/api_helper.rb', line 44 def on_wiki(id, &blk) super(id) do |wiki_url| api_url = lookup(:mediawiki_api_url, id: id, default: -> { api_url_from(wiki_url) }) return with(mediawiki_url: wiki_url, mediawiki_api_url: api_url, &blk) end end |