mediawiktory 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile.lock +63 -0
- data/README.md +103 -0
- data/bin/mediawiktory +13 -0
- data/doc/mediawiki_api_types.md +14 -0
- data/examples/query.rb +15 -0
- data/examples/query_generator.rb +15 -0
- data/lib/faraday/naive_cache.rb +40 -0
- data/lib/media_wiktory.rb +1 -0
- data/lib/mediawiktory/action.rb +48 -0
- data/lib/mediawiktory/array_with_keys.rb +41 -0
- data/lib/mediawiktory/client.rb +22 -0
- data/lib/mediawiktory/generated/abusefiltercheckmatch.rb +9 -0
- data/lib/mediawiktory/generated/abusefilterchecksyntax.rb +6 -0
- data/lib/mediawiktory/generated/abusefilterevalexpression.rb +6 -0
- data/lib/mediawiktory/generated/abusefilters.rb +12 -0
- data/lib/mediawiktory/generated/abusefilterunblockautopromote.rb +8 -0
- data/lib/mediawiktory/generated/abuselog.rb +14 -0
- data/lib/mediawiktory/generated/actions_mixin.rb +313 -0
- data/lib/mediawiktory/generated/addstudents.rb +9 -0
- data/lib/mediawiktory/generated/allcategories.rb +15 -0
- data/lib/mediawiktory/generated/alldeletedrevisions.rb +27 -0
- data/lib/mediawiktory/generated/allfileusages.rb +14 -0
- data/lib/mediawiktory/generated/allimages.rb +23 -0
- data/lib/mediawiktory/generated/alllinks.rb +15 -0
- data/lib/mediawiktory/generated/allmessages.rb +19 -0
- data/lib/mediawiktory/generated/allpages.rb +21 -0
- data/lib/mediawiktory/generated/allredirects.rb +15 -0
- data/lib/mediawiktory/generated/alltransclusions.rb +15 -0
- data/lib/mediawiktory/generated/allusers.rb +17 -0
- data/lib/mediawiktory/generated/antispoof.rb +6 -0
- data/lib/mediawiktory/generated/backlinks.rb +14 -0
- data/lib/mediawiktory/generated/betafeatures.rb +7 -0
- data/lib/mediawiktory/generated/block.rb +18 -0
- data/lib/mediawiktory/generated/blocks.rb +16 -0
- data/lib/mediawiktory/generated/bouncehandler.rb +7 -0
- data/lib/mediawiktory/generated/categories.rb +12 -0
- data/lib/mediawiktory/generated/categoryinfo.rb +7 -0
- data/lib/mediawiktory/generated/categorymembers.rb +23 -0
- data/lib/mediawiktory/generated/centralauthtoken.rb +5 -0
- data/lib/mediawiktory/generated/centralnoticechoicedata.rb +7 -0
- data/lib/mediawiktory/generated/centralnoticelogs.rb +11 -0
- data/lib/mediawiktory/generated/centralnoticequerycampaign.rb +6 -0
- data/lib/mediawiktory/generated/checktoken.rb +8 -0
- data/lib/mediawiktory/generated/checkuser.rb +14 -0
- data/lib/mediawiktory/generated/checkuserlog.rb +13 -0
- data/lib/mediawiktory/generated/cirrus-config-dump.rb +5 -0
- data/lib/mediawiktory/generated/cirrus-mapping-dump.rb +5 -0
- data/lib/mediawiktory/generated/cirrus-settings-dump.rb +5 -0
- data/lib/mediawiktory/generated/cirrus-suggest.rb +8 -0
- data/lib/mediawiktory/generated/clearhasmsg.rb +5 -0
- data/lib/mediawiktory/generated/close-open-topic.rb +10 -0
- data/lib/mediawiktory/generated/compare.rb +11 -0
- data/lib/mediawiktory/generated/contenttranslation.rb +12 -0
- data/lib/mediawiktory/generated/contenttranslationlangtrend.rb +8 -0
- data/lib/mediawiktory/generated/contenttranslationstats.rb +5 -0
- data/lib/mediawiktory/generated/contenttranslationsuggestions.rb +10 -0
- data/lib/mediawiktory/generated/contributors.rb +12 -0
- data/lib/mediawiktory/generated/coordinates.rb +12 -0
- data/lib/mediawiktory/generated/createaccount.rb +18 -0
- data/lib/mediawiktory/generated/cxconfiguration.rb +7 -0
- data/lib/mediawiktory/generated/cxdelete.rb +10 -0
- data/lib/mediawiktory/generated/cxpublish.rb +18 -0
- data/lib/mediawiktory/generated/cxpublishedtranslations.rb +9 -0
- data/lib/mediawiktory/generated/cxtoken.rb +7 -0
- data/lib/mediawiktory/generated/delete.rb +14 -0
- data/lib/mediawiktory/generated/deletedrevisions.rb +22 -0
- data/lib/mediawiktory/generated/deletedrevs.rb +20 -0
- data/lib/mediawiktory/generated/deleteeducation.rb +10 -0
- data/lib/mediawiktory/generated/deleteglobalaccount.rb +9 -0
- data/lib/mediawiktory/generated/duplicatefiles.rb +10 -0
- data/lib/mediawiktory/generated/echomarkread.rb +10 -0
- data/lib/mediawiktory/generated/echomarkseen.rb +8 -0
- data/lib/mediawiktory/generated/edit-header.rb +11 -0
- data/lib/mediawiktory/generated/edit-post.rb +12 -0
- data/lib/mediawiktory/generated/edit-title.rb +10 -0
- data/lib/mediawiktory/generated/edit-topic-summary.rb +11 -0
- data/lib/mediawiktory/generated/edit.rb +35 -0
- data/lib/mediawiktory/generated/editlist.rb +20 -0
- data/lib/mediawiktory/generated/editmassmessagelist.rb +10 -0
- data/lib/mediawiktory/generated/emailuser.rb +11 -0
- data/lib/mediawiktory/generated/embeddedin.rb +13 -0
- data/lib/mediawiktory/generated/enlist.rb +13 -0
- data/lib/mediawiktory/generated/expandtemplates.rb +11 -0
- data/lib/mediawiktory/generated/extlinks.rb +11 -0
- data/lib/mediawiktory/generated/extracts.rb +14 -0
- data/lib/mediawiktory/generated/exturlusage.rb +13 -0
- data/lib/mediawiktory/generated/fancycaptchareload.rb +5 -0
- data/lib/mediawiktory/generated/featuredfeed.rb +8 -0
- data/lib/mediawiktory/generated/featureusage.rb +10 -0
- data/lib/mediawiktory/generated/feedcontributions.rb +15 -0
- data/lib/mediawiktory/generated/feedrecentchanges.rb +21 -0
- data/lib/mediawiktory/generated/feedwatchlist.rb +14 -0
- data/lib/mediawiktory/generated/filearchive.rb +15 -0
- data/lib/mediawiktory/generated/filerepoinfo.rb +7 -0
- data/lib/mediawiktory/generated/filerevert.rb +10 -0
- data/lib/mediawiktory/generated/fileusage.rb +11 -0
- data/lib/mediawiktory/generated/flagconfig.rb +5 -0
- data/lib/mediawiktory/generated/flagged.rb +5 -0
- data/lib/mediawiktory/generated/flow-parsoid-utils.rb +10 -0
- data/lib/mediawiktory/generated/flow.rb +8 -0
- data/lib/mediawiktory/generated/flowinfo.rb +6 -0
- data/lib/mediawiktory/generated/flowthank.rb +8 -0
- data/lib/mediawiktory/generated/gadgetcategories.rb +8 -0
- data/lib/mediawiktory/generated/gadgets.rb +11 -0
- data/lib/mediawiktory/generated/geosearch.rb +15 -0
- data/lib/mediawiktory/generated/gettingstartedgetpages.rb +9 -0
- data/lib/mediawiktory/generated/globalallusers.rb +14 -0
- data/lib/mediawiktory/generated/globalblock.rb +12 -0
- data/lib/mediawiktory/generated/globalblocks.rb +14 -0
- data/lib/mediawiktory/generated/globalgroups.rb +7 -0
- data/lib/mediawiktory/generated/globalusage.rb +10 -0
- data/lib/mediawiktory/generated/globaluserinfo.rb +8 -0
- data/lib/mediawiktory/generated/globaluserrights.rb +12 -0
- data/lib/mediawiktory/generated/help.rb +10 -0
- data/lib/mediawiktory/generated/imageinfo.rb +19 -0
- data/lib/mediawiktory/generated/imagerotate.rb +5 -0
- data/lib/mediawiktory/generated/images.rb +10 -0
- data/lib/mediawiktory/generated/imageusage.rb +14 -0
- data/lib/mediawiktory/generated/import.rb +15 -0
- data/lib/mediawiktory/generated/info.rb +10 -0
- data/lib/mediawiktory/generated/iwbacklinks.rb +12 -0
- data/lib/mediawiktory/generated/iwlinks.rb +13 -0
- data/lib/mediawiktory/generated/jsonconfig.rb +8 -0
- data/lib/mediawiktory/generated/langbacklinks.rb +12 -0
- data/lib/mediawiktory/generated/langlinks.rb +14 -0
- data/lib/mediawiktory/generated/languagesearch.rb +7 -0
- data/lib/mediawiktory/generated/links.rb +11 -0
- data/lib/mediawiktory/generated/linkshere.rb +11 -0
- data/lib/mediawiktory/generated/listmembership.rb +10 -0
- data/lib/mediawiktory/generated/listpages.rb +14 -0
- data/lib/mediawiktory/generated/lists.rb +15 -0
- data/lib/mediawiktory/generated/liststudents.rb +9 -0
- data/lib/mediawiktory/generated/lock-topic.rb +10 -0
- data/lib/mediawiktory/generated/logevents.rb +19 -0
- data/lib/mediawiktory/generated/login.rb +11 -0
- data/lib/mediawiktory/generated/logout.rb +5 -0
- data/lib/mediawiktory/generated/managetags.rb +11 -0
- data/lib/mediawiktory/generated/massmessage.rb +10 -0
- data/lib/mediawiktory/generated/mmsites.rb +6 -0
- data/lib/mediawiktory/generated/mobileview.rb +21 -0
- data/lib/mediawiktory/generated/moderate-post.rb +11 -0
- data/lib/mediawiktory/generated/moderate-topic.rb +10 -0
- data/lib/mediawiktory/generated/move.rb +18 -0
- data/lib/mediawiktory/generated/new-topic.rb +11 -0
- data/lib/mediawiktory/generated/notifications.rb +17 -0
- data/lib/mediawiktory/generated/oldreviewedpages.rb +15 -0
- data/lib/mediawiktory/generated/opensearch.rb +12 -0
- data/lib/mediawiktory/generated/options.rb +12 -0
- data/lib/mediawiktory/generated/pageimages.rb +10 -0
- data/lib/mediawiktory/generated/pagepropnames.rb +8 -0
- data/lib/mediawiktory/generated/pageprops.rb +8 -0
- data/lib/mediawiktory/generated/pageswithprop.rb +11 -0
- data/lib/mediawiktory/generated/pageterms.rb +8 -0
- data/lib/mediawiktory/generated/pagetriageaction.rb +11 -0
- data/lib/mediawiktory/generated/pagetriagelist.rb +21 -0
- data/lib/mediawiktory/generated/pagetriagestats.rb +10 -0
- data/lib/mediawiktory/generated/pagetriagetagging.rb +13 -0
- data/lib/mediawiktory/generated/pagetriagetemplate.rb +7 -0
- data/lib/mediawiktory/generated/paraminfo.rb +11 -0
- data/lib/mediawiktory/generated/parse.rb +31 -0
- data/lib/mediawiktory/generated/parsoid-batch.rb +6 -0
- data/lib/mediawiktory/generated/patrol.rb +9 -0
- data/lib/mediawiktory/generated/prefixsearch.rb +10 -0
- data/lib/mediawiktory/generated/protect.rb +15 -0
- data/lib/mediawiktory/generated/protectedtitles.rb +14 -0
- data/lib/mediawiktory/generated/purge.rb +15 -0
- data/lib/mediawiktory/generated/query.rb +20 -0
- data/lib/mediawiktory/generated/querypage.rb +9 -0
- data/lib/mediawiktory/generated/random.rb +11 -0
- data/lib/mediawiktory/generated/recentchanges.rb +20 -0
- data/lib/mediawiktory/generated/redirects.rb +11 -0
- data/lib/mediawiktory/generated/refresheducation.rb +9 -0
- data/lib/mediawiktory/generated/reply.rb +11 -0
- data/lib/mediawiktory/generated/review.rb +10 -0
- data/lib/mediawiktory/generated/reviewactivity.rb +10 -0
- data/lib/mediawiktory/generated/revisiondelete.rb +14 -0
- data/lib/mediawiktory/generated/revisions.rb +25 -0
- data/lib/mediawiktory/generated/rollback.rb +13 -0
- data/lib/mediawiktory/generated/rsd.rb +5 -0
- data/lib/mediawiktory/generated/scribunto-console.rb +10 -0
- data/lib/mediawiktory/generated/search.rb +15 -0
- data/lib/mediawiktory/generated/setglobalaccountstatus.rb +12 -0
- data/lib/mediawiktory/generated/setnotificationtimestamp.rb +18 -0
- data/lib/mediawiktory/generated/siteinfo.rb +11 -0
- data/lib/mediawiktory/generated/sitematrix.rb +12 -0
- data/lib/mediawiktory/generated/spamblacklist.rb +6 -0
- data/lib/mediawiktory/generated/stabilize.rb +12 -0
- data/lib/mediawiktory/generated/stashedit.rb +14 -0
- data/lib/mediawiktory/generated/stashimageinfo.rb +12 -0
- data/lib/mediawiktory/generated/strikevote.rb +10 -0
- data/lib/mediawiktory/generated/tag.rb +13 -0
- data/lib/mediawiktory/generated/tags.rb +9 -0
- data/lib/mediawiktory/generated/templatedata.rb +13 -0
- data/lib/mediawiktory/generated/templates.rb +11 -0
- data/lib/mediawiktory/generated/thank.rb +9 -0
- data/lib/mediawiktory/generated/titleblacklist.rb +9 -0
- data/lib/mediawiktory/generated/tokens.rb +6 -0
- data/lib/mediawiktory/generated/transcludedin.rb +11 -0
- data/lib/mediawiktory/generated/transcodereset.rb +9 -0
- data/lib/mediawiktory/generated/transcodestatus.rb +5 -0
- data/lib/mediawiktory/generated/ulslocalization.rb +6 -0
- data/lib/mediawiktory/generated/unblock.rb +10 -0
- data/lib/mediawiktory/generated/undelete.rb +12 -0
- data/lib/mediawiktory/generated/undo-edit-header.rb +8 -0
- data/lib/mediawiktory/generated/undo-edit-post.rb +8 -0
- data/lib/mediawiktory/generated/undo-edit-topic-summary.rb +8 -0
- data/lib/mediawiktory/generated/upload.rb +26 -0
- data/lib/mediawiktory/generated/usercontribs.rb +18 -0
- data/lib/mediawiktory/generated/userdailycontribs.rb +8 -0
- data/lib/mediawiktory/generated/userinfo.rb +7 -0
- data/lib/mediawiktory/generated/userrights.rb +12 -0
- data/lib/mediawiktory/generated/users.rb +9 -0
- data/lib/mediawiktory/generated/videoinfo.rb +14 -0
- data/lib/mediawiktory/generated/view-header.rb +8 -0
- data/lib/mediawiktory/generated/view-post-history.rb +8 -0
- data/lib/mediawiktory/generated/view-post.rb +8 -0
- data/lib/mediawiktory/generated/view-topic-history.rb +7 -0
- data/lib/mediawiktory/generated/view-topic-summary.rb +8 -0
- data/lib/mediawiktory/generated/view-topic.rb +7 -0
- data/lib/mediawiktory/generated/view-topiclist.rb +15 -0
- data/lib/mediawiktory/generated/visualeditor.rb +13 -0
- data/lib/mediawiktory/generated/visualeditoredit.rb +19 -0
- data/lib/mediawiktory/generated/watch.rb +16 -0
- data/lib/mediawiktory/generated/watchlist.rb +20 -0
- data/lib/mediawiktory/generated/watchlistraw.rb +16 -0
- data/lib/mediawiktory/generated/wikibase.rb +7 -0
- data/lib/mediawiktory/generated/wikilove.rb +12 -0
- data/lib/mediawiktory/generated/wikisets.rb +10 -0
- data/lib/mediawiktory/generated/zeroconfig.rb +7 -0
- data/lib/mediawiktory/mw_module.rb +320 -0
- data/lib/mediawiktory/query.rb +60 -0
- data/lib/mediawiktory/version.rb +3 -0
- data/lib/mediawiktory.rb +16 -0
- data/lib/nokogiri/more.rb +72 -0
- data/mediawiktory.gemspec +30 -0
- data/script/data/api.yaml +40239 -0
- data/script/lib/api.rb +14 -0
- data/script/lib/module.rb +132 -0
- data/script/lib/parameter.rb +133 -0
- data/script/parse_api.rb +21 -0
- data/test/cache.rb +15 -0
- metadata +340 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3dbe24768ed1be0926f57bb4cd72e07e098c59b6
|
4
|
+
data.tar.gz: 230b1128fb7ae5b854d714dc564d7d60aaa6be08
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e2a9446d6a9a39c21d2b8f7fa3569a60c33e79607356929af29164201485ef892f84f60c7954713a7e27bf6f29d271f5454909234f69b39e2ada503a09d54142
|
7
|
+
data.tar.gz: 7ec9c4d535a690d2906a64cf81d401ab3bd1198a014a316180d11b7fced7270c9f4fb4eb1d5b3b80d9706d6b42bb29c1ae23ee9960235a955c288035ebc220db
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mediawiktory (0.0.1)
|
5
|
+
addressable
|
6
|
+
faraday
|
7
|
+
faraday_middleware
|
8
|
+
hashie
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
addressable (2.3.8)
|
14
|
+
crack (0.4.2)
|
15
|
+
safe_yaml (~> 1.0.0)
|
16
|
+
diff-lcs (1.2.5)
|
17
|
+
faker (1.5.0)
|
18
|
+
i18n (~> 0.5)
|
19
|
+
faraday (0.9.1)
|
20
|
+
multipart-post (>= 1.2, < 3)
|
21
|
+
faraday_middleware (0.10.0)
|
22
|
+
faraday (>= 0.7.4, < 0.10)
|
23
|
+
hashie (3.4.2)
|
24
|
+
i18n (0.7.0)
|
25
|
+
mini_portile (0.6.2)
|
26
|
+
multipart-post (2.0.0)
|
27
|
+
naught (1.1.0)
|
28
|
+
nokogiri (1.6.6.2)
|
29
|
+
mini_portile (~> 0.6.0)
|
30
|
+
rspec (3.3.0)
|
31
|
+
rspec-core (~> 3.3.0)
|
32
|
+
rspec-expectations (~> 3.3.0)
|
33
|
+
rspec-mocks (~> 3.3.0)
|
34
|
+
rspec-core (3.3.2)
|
35
|
+
rspec-support (~> 3.3.0)
|
36
|
+
rspec-expectations (3.3.1)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.3.0)
|
39
|
+
rspec-its (1.2.0)
|
40
|
+
rspec-core (>= 3.0.0)
|
41
|
+
rspec-expectations (>= 3.0.0)
|
42
|
+
rspec-mocks (3.3.2)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.3.0)
|
45
|
+
rspec-support (3.3.0)
|
46
|
+
rubygems-tasks (0.2.4)
|
47
|
+
safe_yaml (1.0.4)
|
48
|
+
webmock (1.21.0)
|
49
|
+
addressable (>= 2.3.6)
|
50
|
+
crack (>= 0.3.2)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
ruby
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
faker
|
57
|
+
mediawiktory!
|
58
|
+
naught
|
59
|
+
nokogiri
|
60
|
+
rspec
|
61
|
+
rspec-its
|
62
|
+
rubygems-tasks
|
63
|
+
webmock
|
data/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
**Warning! Even 0.0.1 unrealeased yet! Possible first release date
|
2
|
+
is Dec 3, 2015**
|
3
|
+
|
4
|
+
**MediaWiktory** is MediaWiki API client that doesn't suck. No, seriously.
|
5
|
+
|
6
|
+
[MediaWiki API](https://www.mediawiki.org/wiki/API:Main_page)
|
7
|
+
currently is very powerful and full-featured (thought not very easy to use).
|
8
|
+
Things like "fetch first 50 pages from that category alongside with their
|
9
|
+
revision history and interwiki links and mediafile stats" are typically done
|
10
|
+
with one carefully constructed request and return lots of useful information.
|
11
|
+
|
12
|
+
Yes, there already are [several](https://www.mediawiki.org/wiki/API:Client_code#Ruby)
|
13
|
+
API clients for Ruby, including ["official" one](https://github.com/wikimedia/mediawiki-ruby-api).
|
14
|
+
Typical approach for all of them is thick wrapper around some functionality
|
15
|
+
(like "login and edit pages" or "search and analyze pages"), and leave
|
16
|
+
all the other cool things for generic `query` method (at best), or
|
17
|
+
without any coverage at all.
|
18
|
+
|
19
|
+
MediaWiktory, on the contrary, does this:
|
20
|
+
* wraps all the functionality of all the modules of modern MediaWiki,
|
21
|
+
as per [this documentation](https://en.wikipedia.org/w/api.php?action=help&modules=main);
|
22
|
+
* and, for the record, provides sparse documentation for all modules
|
23
|
+
and possibilities;
|
24
|
+
* makes the wrapper reasonably thin, so you can always inspect raw responses
|
25
|
+
and raw request MediaWiktory will provide to the API;
|
26
|
+
* makes the wrapper reasonably smart, so things like "fetch next page for
|
27
|
+
this request" or "login with a token" are done with ease (but without
|
28
|
+
unnecessary "auto-magic", like fetching 500 pages of data without any
|
29
|
+
chance to control this);
|
30
|
+
* validates requests and simplifies parameters passing, while still
|
31
|
+
preserving abilitity to use any existing parameter and feature;
|
32
|
+
* it manages cookies and tokens for you, but can expose underlying
|
33
|
+
Faraday web client so the middleware can be added (like caching).
|
34
|
+
|
35
|
+
**Warning: Above is IDEAL state of the library. Current state, at
|
36
|
+
version 0.0.1 is far less impressive (yet already useful).**
|
37
|
+
|
38
|
+
## Structure and usage
|
39
|
+
|
40
|
+
MediaWiktory tries to resemble original API structure, but make its calls
|
41
|
+
more Ruby-ish. So, [Arel](https://github.com/rails/arel)-alike "chainable
|
42
|
+
query" approach is implemented.
|
43
|
+
|
44
|
+
Fast example:
|
45
|
+
|
46
|
+
**Goal**: fetch content for first 30 pages from category "Countries in
|
47
|
+
South America".
|
48
|
+
|
49
|
+
**Raw request** (split in lines for readability):
|
50
|
+
|
51
|
+
```
|
52
|
+
https://en.wikipedia.org/w/api.php?
|
53
|
+
action=query&
|
54
|
+
generator=categorymembers&
|
55
|
+
gcmtitle=Category:Countries_in_South_America&
|
56
|
+
gcmlimit=30&
|
57
|
+
prop=revisions&
|
58
|
+
rvprop=content
|
59
|
+
```
|
60
|
+
|
61
|
+
**MediaWiktory request**—almost the same, but structured and validated
|
62
|
+
on-the-fly, and without `gcm` and `rv` prefixes black magic:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
client = MediaWiktory::Client.new('https://en.wikipedia.org/w/api.php')
|
66
|
+
|
67
|
+
response = client.
|
68
|
+
query.
|
69
|
+
generator(categorymembers: {title: 'Category:Countries_in_South_America', limit: 30}).
|
70
|
+
prop(revisions: {prop: :content}).
|
71
|
+
perform
|
72
|
+
|
73
|
+
# MediaWiktory handles "next page fetching" for you, if you want
|
74
|
+
response.continue! while response.can_continue?
|
75
|
+
|
76
|
+
# MediaWiktory parses response and provides smart shortcuts
|
77
|
+
p response.pages.map(&:title)
|
78
|
+
```
|
79
|
+
|
80
|
+
The same approach works for ANY `action` described in [docs](https://en.wikipedia.org/w/api.php),
|
81
|
+
and all of its "modules" and "submodules".
|
82
|
+
|
83
|
+
**NB**: its 0.0.1, ok? Domain is complex and is still investigated. For
|
84
|
+
example, above statement definitely **wants** to look like
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
response = client.
|
88
|
+
query.
|
89
|
+
generator(categorymembers: 'Category:Countries_in_South_America').
|
90
|
+
limit(30).
|
91
|
+
prop(revisions: :content).
|
92
|
+
perform
|
93
|
+
```
|
94
|
+
|
95
|
+
...but it should be done without flexibility loss.
|
96
|
+
|
97
|
+
## Author
|
98
|
+
|
99
|
+
[Victor Shepelev](http://zverok.github.io)
|
100
|
+
|
101
|
+
## License
|
102
|
+
|
103
|
+
MIT.
|
data/bin/mediawiktory
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
7
|
+
require_relative '../lib/mediawiktory'
|
8
|
+
|
9
|
+
include MediaWiktory
|
10
|
+
|
11
|
+
require 'irb'
|
12
|
+
ARGV.shift until ARGV.empty?
|
13
|
+
IRB.start
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
* single value:
|
3
|
+
* boolean ("if the parameter is specified, regardless of value, it is considered true");
|
4
|
+
* string;
|
5
|
+
* integer;
|
6
|
+
* integer or "max";
|
7
|
+
* timestamp ([list of allowed formats](https://www.mediawiki.org/w/api.php?action=help&modules=main#main.2Fdatatypes));
|
8
|
+
* enum value (string of limited list);
|
9
|
+
* module (see below);
|
10
|
+
* list:
|
11
|
+
* of integers;
|
12
|
+
* of strings;
|
13
|
+
* of enum values;
|
14
|
+
* of modules.
|
data/examples/query.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$:.unshift 'lib'
|
2
|
+
require 'mediawiktory'
|
3
|
+
include MediaWiktory
|
4
|
+
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
c = Client.new('https://en.wikipedia.org/w/api.php')
|
8
|
+
res = c.query.
|
9
|
+
titles('Argentina', 'Chile').
|
10
|
+
prop(:categories).
|
11
|
+
perform
|
12
|
+
|
13
|
+
res.continue! while res.continue?
|
14
|
+
|
15
|
+
pp res.pages.map(&:to_h)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
$:.unshift 'lib'
|
2
|
+
require 'mediawiktory'
|
3
|
+
include MediaWiktory
|
4
|
+
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
c = Client.new('https://en.wikipedia.org/w/api.php')
|
8
|
+
res = c.query.
|
9
|
+
generator(categorymembers: {title: 'Category:Countries_in_South_America', limit: 50}).
|
10
|
+
prop(revisions: {prop: ['content']}).
|
11
|
+
perform
|
12
|
+
|
13
|
+
res.continue! while res.continue?
|
14
|
+
|
15
|
+
pp res.pages.map(&:title)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'addressable/uri'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Faraday
|
5
|
+
class NaiveCache < Middleware
|
6
|
+
BASE_PATH = 'tmp/cache' # FIXME, obviously
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
if response = from_cache(env[:url])
|
10
|
+
env[:response] = response
|
11
|
+
else
|
12
|
+
@app.call(env).on_complete do |env|
|
13
|
+
to_cache(env[:url], env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def from_cache(url)
|
21
|
+
path = cached_path(url)
|
22
|
+
File.exists?(path) ? Response.new(JSON.parse(File.read(path))) : nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_cache(url, env)
|
26
|
+
env.body = env.body.force_encoding('UTF-8')
|
27
|
+
|
28
|
+
path = cached_path(url)
|
29
|
+
FileUtils.mkdir_p File.dirname(path)
|
30
|
+
File.write path, env.to_hash.to_json
|
31
|
+
end
|
32
|
+
|
33
|
+
def cached_path(url)
|
34
|
+
uri = Addressable::URI.parse(url)
|
35
|
+
filename = [uri.path, uri.query].compact.join('?').gsub(/[?\/&]/, '-')
|
36
|
+
filename = '_root_' if filename.empty?
|
37
|
+
File.join(BASE_PATH, uri.host, filename)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative './mediawiktory'
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'hashie'
|
3
|
+
|
4
|
+
module MediaWiktory
|
5
|
+
class Action < MWModule
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
def initialize(client, **values)
|
9
|
+
@client = client
|
10
|
+
super(**values)
|
11
|
+
end
|
12
|
+
|
13
|
+
def dup
|
14
|
+
self.class.new(client, to_h)
|
15
|
+
end
|
16
|
+
|
17
|
+
def perform(params = {})
|
18
|
+
self.class::Response. # child classes can enrich and specialize their Response
|
19
|
+
from_json(self, @client.send(self.class.request_method, to_param.merge(params)))
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_param
|
23
|
+
super.merge('action' => self.class.symbol.to_s, 'format' => 'json')
|
24
|
+
end
|
25
|
+
|
26
|
+
class Response
|
27
|
+
def self.from_json(action, data)
|
28
|
+
new(action, JSON.parse(data))
|
29
|
+
end
|
30
|
+
|
31
|
+
attr_reader :action, :raw
|
32
|
+
|
33
|
+
def initialize(action, raw)
|
34
|
+
@action = action
|
35
|
+
@raw = Hashie::Mash.new(raw)
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize_copy(other)
|
39
|
+
@action = other.action
|
40
|
+
@raw = other.raw.dup
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_h
|
44
|
+
raw.to_h
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module MediaWiktory
|
2
|
+
# FIXME: maybe, its a wrongdoing
|
3
|
+
# But for now, I cant invent wiser structure for MediaWiki's
|
4
|
+
# {'numericpageid' => {page}} hash
|
5
|
+
#
|
6
|
+
# Having it as a hash complicates code (most time you just need a list
|
7
|
+
# of pages), dropping keys completely and using only values seem to
|
8
|
+
# have its own drawbacks.
|
9
|
+
#
|
10
|
+
class ArrayWithKeys < Array
|
11
|
+
def self.from_hash(hash)
|
12
|
+
new(hash.values, hash.keys)
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :keys
|
16
|
+
|
17
|
+
def initialize(values, keys)
|
18
|
+
super(values)
|
19
|
+
@keys = keys
|
20
|
+
end
|
21
|
+
|
22
|
+
def [](key)
|
23
|
+
case key
|
24
|
+
when Fixnum
|
25
|
+
super
|
26
|
+
else
|
27
|
+
idx = @keys.index(key)
|
28
|
+
idx && super(idx)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def push(value, key)
|
33
|
+
super(value)
|
34
|
+
@keys.push(key)
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_h
|
38
|
+
keys.zip(self).to_h
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative 'generated/actions_mixin'
|
2
|
+
|
3
|
+
module MediaWiktory
|
4
|
+
class Client
|
5
|
+
attr_reader :url
|
6
|
+
|
7
|
+
def initialize(url)
|
8
|
+
@url = Addressable::URI.parse(url)
|
9
|
+
@faraday = Faraday.new(url)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(params)
|
13
|
+
@faraday.get('', params).body
|
14
|
+
end
|
15
|
+
|
16
|
+
def post(params)
|
17
|
+
@faraday.post('', params).body
|
18
|
+
end
|
19
|
+
|
20
|
+
include ActionsMixin
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module MediaWiktory
|
2
|
+
class Abusefilters < MWModule
|
3
|
+
symbol :abusefilters
|
4
|
+
prefix "abf"
|
5
|
+
param :startid, Params::Integer
|
6
|
+
param :endid, Params::Integer
|
7
|
+
param :dir, Params::Enum["newer", "older"]
|
8
|
+
param :show, Params::List[Params::Enum["enabled", "!enabled", "deleted", "!deleted", "private", "!private"]]
|
9
|
+
param :limit, Params::IntegerOrMax
|
10
|
+
param :prop, Params::List[Params::Enum["id", "description", "pattern", "actions", "hits", "comments", "lasteditor", "lastedittime", "status", "private"]]
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MediaWiktory
|
2
|
+
class Abuselog < MWModule
|
3
|
+
symbol :abuselog
|
4
|
+
prefix "afl"
|
5
|
+
param :start, Params::Timestamp
|
6
|
+
param :end, Params::Timestamp
|
7
|
+
param :dir, Params::Enum["newer", "older"]
|
8
|
+
param :user, Params::String
|
9
|
+
param :title, Params::String
|
10
|
+
param :filter, Params::List[Params::String]
|
11
|
+
param :limit, Params::IntegerOrMax
|
12
|
+
param :prop, Params::List[Params::Enum["ids", "filter", "user", "ip", "title", "action", "details", "result", "timestamp", "hidden", "revid"]]
|
13
|
+
end
|
14
|
+
end
|