Class: MediaWiki::FakeWiki::ApiToken
- Inherits:
-
Object
- Object
- MediaWiki::FakeWiki::ApiToken
- Defined in:
- lib/media_wiki/fake_wiki.rb
Constant Summary collapse
- ADMIN_TOKEN =
"admin_token+\\"
- REGULAR_TOKEN =
"regular_token+\\"
- BLANK_TOKEN =
"+\\"
Instance Method Summary collapse
- #edittoken ⇒ Object (also: #optionstoken)
- #importtoken ⇒ Object (also: #deletetoken, #undeletetoken, #userrightstoken, #createusertoken)
-
#initialize(params) ⇒ ApiToken
constructor
A new instance of ApiToken.
- #request(user) ⇒ Object
- #requested_token_type ⇒ Object
- #set_type(type) ⇒ Object
- #validate ⇒ Object
- #validate_admin ⇒ Object
Constructor Details
#initialize(params) ⇒ ApiToken
Returns a new instance of ApiToken.
552 553 554 555 |
# File 'lib/media_wiki/fake_wiki.rb', line 552 def initialize(params) @token_str = params[:token] @token_in = params[:intoken] end |
Instance Method Details
#edittoken ⇒ Object Also known as: optionstoken
596 597 598 599 600 601 602 |
# File 'lib/media_wiki/fake_wiki.rb', line 596 def edittoken if @user REGULAR_TOKEN else BLANK_TOKEN end end |
#importtoken ⇒ Object Also known as: deletetoken, undeletetoken, userrightstoken, createusertoken
583 584 585 586 587 588 589 |
# File 'lib/media_wiki/fake_wiki.rb', line 583 def importtoken if @user && @user[:is_admin] ADMIN_TOKEN else nil end end |
#request(user) ⇒ Object
574 575 576 577 |
# File 'lib/media_wiki/fake_wiki.rb', line 574 def request(user) @user = user respond_to?(requested_token_type) ? send(requested_token_type) : nil end |
#requested_token_type ⇒ Object
579 580 581 |
# File 'lib/media_wiki/fake_wiki.rb', line 579 def requested_token_type "#{@token_in}token".to_sym end |
#set_type(type) ⇒ Object
557 558 559 |
# File 'lib/media_wiki/fake_wiki.rb', line 557 def set_type(type) @token_in = type end |
#validate ⇒ Object
561 562 563 564 565 |
# File 'lib/media_wiki/fake_wiki.rb', line 561 def validate unless @token_str raise ApiError.new("notoken", "The token parameter must be set") end end |
#validate_admin ⇒ Object
567 568 569 570 571 572 |
# File 'lib/media_wiki/fake_wiki.rb', line 567 def validate_admin validate if @token_str != ADMIN_TOKEN raise ApiError.new("badtoken", "Invalid token") end end |