Module: MediaWiki::Watch
- Included in:
- Butt
- Defined in:
- lib/mediawiki/watch.rb
Instance Method Summary collapse
-
#unwatch(titles) ⇒ Hash{String => Nil, Boolean}
Removes a page or an array of pages from the current user’s watchlist.
-
#watch(titles) ⇒ Hash{String => Nil, Boolean}
Adds a page or an array of pages to the current user’s watchlist.
-
#watch_request(titles, unwatch = false) ⇒ Hash{String => Nil, Boolean}
private
Submits a watch action request.
Instance Method Details
#unwatch(titles) ⇒ Hash{String => Nil, Boolean}
Removes a page or an array of pages from the current user’s watchlist.
16 17 18 |
# File 'lib/mediawiki/watch.rb', line 16 def unwatch(titles) watch_request(titles, true) end |
#watch(titles) ⇒ Hash{String => Nil, Boolean}
Adds a page or an array of pages to the current user’s watchlist.
8 9 10 |
# File 'lib/mediawiki/watch.rb', line 8 def watch(titles) watch_request(titles) end |
#watch_request(titles, unwatch = false) ⇒ Hash{String => Nil, Boolean} (private)
Submits a watch action request.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mediawiki/watch.rb', line 26 def watch_request(titles, unwatch = false) titles = titles.is_a?(Array) ? titles : [titles] params = { action: 'watch', titles: titles.shift(get_limited(titles.length, 50, 500)).join('|'), token: get_token('watch') } success_key = 'watched' if unwatch params[:unwatch] = 1 success_key = 'unwatched' end post(params)['watch'].inject({}) do |result, entry| title = entry['title'] if entry.key?(success_key) result[title] = entry.key?('missing') ? nil : true else result[title] = false end result end end |