Sha256: 7ea09d50834154ee3599585d17592e00ee0d3cf7814cab72e6029e7965941935

Contents?: true

Size: 1.49 KB

Versions: 4

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

module MediaWiktory::Wikipedia
  module Actions
    # Get tokens for data-modifying actions.
    #
    # Usage:
    #
    # ```ruby
    # api.tokens.type(value).perform # returns string with raw output
    # # or
    # api.tokens.type(value).response # returns output parsed and wrapped into Response object
    # ```
    #
    # See {Base} for generic explanation of working with MediaWiki actions and
    # {MediaWiktory::Wikipedia::Response} for working with action responses.
    #
    # All action's parameters are documented as its public methods, see below.
    #
    class Tokens < MediaWiktory::Wikipedia::Actions::Get

      # Types of token to request.
      #
      # @param values [Array<String>] Allowed values: "block", "createaccount", "csrf", "delete", "deleteglobalaccount", "edit", "email", "import", "login", "move", "options", "patrol", "protect", "rollback", "setglobalaccountstatus", "unblock", "userrights", "watch".
      # @return [self]
      def type(*values)
        values.inject(self) { |res, val| res._type(val) or fail ArgumentError, "Unknown value for type: #{val}" }
      end

      # @private
      def _type(value)
        defined?(super) && super || ["block", "createaccount", "csrf", "delete", "deleteglobalaccount", "edit", "email", "import", "login", "move", "options", "patrol", "protect", "rollback", "setglobalaccountstatus", "unblock", "userrights", "watch"].include?(value.to_s) && merge(type: value.to_s, replace: false)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mediawiktory-0.1.3 lib/mediawiktory/wikipedia/actions/tokens.rb
mediawiktory-0.1.2 lib/mediawiktory/wikipedia/actions/tokens.rb
mediawiktory-0.1.1 lib/mediawiktory/wikipedia/actions/tokens.rb
mediawiktory-0.1.0 lib/mediawiktory/wikipedia/actions/tokens.rb