mediawiki_api 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -7
- data/lib/mediawiki_api/exceptions.rb +9 -5
- data/lib/mediawiki_api/version.rb +1 -1
- data/spec/exceptions_spec.rb +49 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4033e20e939a4e529667d68f9980dbecbf546e39
|
|
4
|
+
data.tar.gz: 26a103f6d54867b344c0e8542d42cbb58ae5ecb1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3b9163974f7c7dcbfcf57de36c9339c978a856c5d199d2cd4706ac3a06d34e4ef8b4c110975fd601a27f5d1c0e19936c24d116f4fb8bd3f7195e68f34954d1fa
|
|
7
|
+
data.tar.gz: 7cc523a723658d551cff463f92aa20d78810fd21f2e66bab690aa229815619bd75bcaf1254ea6b0a39c90b13a8c813a74d3af83342d0a9e7609ccdec7948017e
|
data/README.md
CHANGED
|
@@ -32,8 +32,8 @@ client.get_wikitext "title"
|
|
|
32
32
|
client.protect_page "title", "reason", "protections" # protections are optional, default is "edit=sysop|move=sysop"
|
|
33
33
|
client.delete_page "title", "reason"
|
|
34
34
|
client.upload_image "filename", "path", "comment", "ignorewarnings"
|
|
35
|
-
client.
|
|
36
|
-
client.
|
|
35
|
+
client.watch_page "title"
|
|
36
|
+
client.unwatch_page "title"
|
|
37
37
|
client.meta :siteinfo, siprop: "extensions"
|
|
38
38
|
client.prop :info, titles: "Some page"
|
|
39
39
|
client.query titles: ["Some page", "Some other page"]
|
|
@@ -49,10 +49,10 @@ By default, the client will attempt to get a csrf token before attempting the
|
|
|
49
49
|
action. For actions that do not require a token, you can specify
|
|
50
50
|
`token_type: false` to avoid requesting the unnecessary token before the real
|
|
51
51
|
request. For example:
|
|
52
|
-
```client.action :parse, page: 'Main Page', token_type: false
|
|
53
|
-
```
|
|
54
|
-
|
|
55
52
|
|
|
53
|
+
```ruby
|
|
54
|
+
client.action :parse, page: 'Main Page', token_type: false
|
|
55
|
+
```
|
|
56
56
|
|
|
57
57
|
## Links
|
|
58
58
|
|
|
@@ -65,11 +65,14 @@ See https://www.mediawiki.org/wiki/Gerrit
|
|
|
65
65
|
|
|
66
66
|
## Release notes
|
|
67
67
|
|
|
68
|
+
### 0.4.1 2015-06-17
|
|
69
|
+
- Allow for response-less ApiError exceptions to make mocking in tests easier
|
|
70
|
+
|
|
68
71
|
### 0.4.0 2015-06-16
|
|
69
|
-
-
|
|
72
|
+
- Use action=query&meta=tokens to fetch tokens, instead of deprecated action=tokens
|
|
70
73
|
|
|
71
74
|
### 0.3.1 2015-01-06
|
|
72
|
-
-
|
|
75
|
+
- Actions now automatically refresh token and re-submit action if first attempt returns 'badtoken'.
|
|
73
76
|
|
|
74
77
|
### 0.3.0 2014-10-14
|
|
75
78
|
|
|
@@ -3,16 +3,16 @@ module MediawikiApi
|
|
|
3
3
|
class ApiError < StandardError
|
|
4
4
|
attr_reader :response
|
|
5
5
|
|
|
6
|
-
def initialize(response)
|
|
6
|
+
def initialize(response = nil)
|
|
7
7
|
@response = response
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def code
|
|
11
|
-
|
|
11
|
+
response_data['code'] || '000'
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def info
|
|
15
|
-
|
|
15
|
+
response_data['info'] || 'unknown API error'
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def to_s
|
|
@@ -21,8 +21,12 @@ module MediawikiApi
|
|
|
21
21
|
|
|
22
22
|
private
|
|
23
23
|
|
|
24
|
-
def
|
|
25
|
-
@response
|
|
24
|
+
def response_data
|
|
25
|
+
if @response
|
|
26
|
+
@response.data || {}
|
|
27
|
+
else
|
|
28
|
+
{}
|
|
29
|
+
end
|
|
26
30
|
end
|
|
27
31
|
end
|
|
28
32
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module MediawikiApi
|
|
4
|
+
describe ApiError do
|
|
5
|
+
def mock_error_response(data = {})
|
|
6
|
+
instance_double(Response, data: data)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe '#code' do
|
|
10
|
+
it 'returns the code from `error/code` in the response' do
|
|
11
|
+
error = ApiError.new(mock_error_response('code' => '123'))
|
|
12
|
+
|
|
13
|
+
expect(error.code).to eq('123')
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'defaults to "000" when a code is not present in the response' do
|
|
17
|
+
error = ApiError.new(mock_error_response)
|
|
18
|
+
|
|
19
|
+
expect(error.code).to eq('000')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'defaults to "000" when a response is not provided' do
|
|
23
|
+
error = ApiError.new
|
|
24
|
+
|
|
25
|
+
expect(error.code).to eq('000')
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe '#info' do
|
|
30
|
+
it 'returns the info from `error/info` in the response' do
|
|
31
|
+
error = ApiError.new(mock_error_response('info' => 'some error'))
|
|
32
|
+
|
|
33
|
+
expect(error.info).to eq('some error')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'defaults to "unknown API error" when info is not present in the response' do
|
|
37
|
+
error = ApiError.new(mock_error_response)
|
|
38
|
+
|
|
39
|
+
expect(error.info).to eq('unknown API error')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'defaults to "unknown API error" when a response is not provided' do
|
|
43
|
+
error = ApiError.new
|
|
44
|
+
|
|
45
|
+
expect(error.info).to eq('unknown API error')
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mediawiki_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Amir Aharoni
|
|
@@ -14,7 +14,7 @@ authors:
|
|
|
14
14
|
autorequire:
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
|
-
date: 2015-06-
|
|
17
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
|
18
18
|
dependencies:
|
|
19
19
|
- !ruby/object:Gem::Dependency
|
|
20
20
|
name: faraday
|
|
@@ -195,6 +195,7 @@ files:
|
|
|
195
195
|
- lib/mediawiki_api/version.rb
|
|
196
196
|
- mediawiki_api.gemspec
|
|
197
197
|
- spec/client_spec.rb
|
|
198
|
+
- spec/exceptions_spec.rb
|
|
198
199
|
- spec/response_spec.rb
|
|
199
200
|
- spec/spec_helper.rb
|
|
200
201
|
- spec/support/request_helpers.rb
|
|
@@ -224,6 +225,7 @@ specification_version: 4
|
|
|
224
225
|
summary: A library for interacting with MediaWiki API from Ruby.
|
|
225
226
|
test_files:
|
|
226
227
|
- spec/client_spec.rb
|
|
228
|
+
- spec/exceptions_spec.rb
|
|
227
229
|
- spec/response_spec.rb
|
|
228
230
|
- spec/spec_helper.rb
|
|
229
231
|
- spec/support/request_helpers.rb
|