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

Instance Method Details

#apiMediawikiApi::Client

An authenticated MediaWiki API client.

Returns:

  • (MediawikiApi::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.(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.

Parameters:

  • id (Symbol)

    ID of alternative user.



28
29
30
31
32
# File 'lib/mediawiki_selenium/support/modules/api_helper.rb', line 28

def (id)
  api.(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.

Yields:

  • (wiki_url, api_url)

Yield Parameters:

  • wiki_url (String)

    Alternative wiki URL.

  • api_url (String)

    Alternative API URL.

See Also:



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