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 = api_url

  @_api_cache[[url, user]] ||= MediawikiApi::Client.new(url).tap do |client|
    client.(user, password)
  end
end

#api_urlString

URL to the API endpoint for the current wiki.

Returns:

  • (String)


26
27
28
# File 'lib/mediawiki_selenium/support/modules/api_helper.rb', line 26

def api_url
  lookup(:mediawiki_api_url, default: -> { api_url_from(lookup(:mediawiki_url)) })
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.



36
37
38
39
40
# File 'lib/mediawiki_selenium/support/modules/api_helper.rb', line 36

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:

Yield Parameters:

  • wiki_url (String)

    Alternative wiki URL.

  • api_url (String)

    Alternative API URL.

See Also:



52
53
54
55
56
57
# File 'lib/mediawiki_selenium/support/modules/api_helper.rb', line 52

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