mediawiki_api 0.2.0 → 0.2.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 +5 -5
- data/lib/mediawiki_api/client.rb +3 -1
- data/lib/mediawiki_api/version.rb +1 -1
- data/spec/client_spec.rb +22 -1
- data/spec/support/request_helpers.rb +5 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05fde886762b19553fe636b7e7d8cccb220a7481
|
4
|
+
data.tar.gz: 37036c78dcbd186c31f9da0a08f754f7931d1daa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab02ae9dd0aaca8aac8c4d4bd08a8a9dabe2e907b2b6f656575d1ee29be059f4a39eb8802e720360c36b301e198a8579648802d4accfaf132d5416961d50ab50
|
7
|
+
data.tar.gz: e18cd950e866512999fb22e86fc7021ce260d99935f8f558b782ef75c38ad6e7aa4fa2df03e99970742e165f9bc17dd4033320c0785cc7948f760453b7c0cf4c
|
data/README.md
CHANGED
@@ -50,14 +50,14 @@ MediaWiki API gem at: [Gerrit](https://gerrit.wikimedia.org/r/#/admin/projects/m
|
|
50
50
|
|
51
51
|
## Contributing
|
52
52
|
|
53
|
-
|
54
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
-
3. Commit your changes (`git commit -am "Add some feature"`)
|
56
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
-
5. Create new Pull Request
|
53
|
+
See https://www.mediawiki.org/wiki/Gerrit
|
58
54
|
|
59
55
|
## Release notes
|
60
56
|
|
57
|
+
### 0.2.1 2014-08-26
|
58
|
+
|
59
|
+
- Fix error handling for token requests
|
60
|
+
|
61
61
|
### 0.2.0 2014-08-06
|
62
62
|
|
63
63
|
- Automatic response parsing.
|
data/lib/mediawiki_api/client.rb
CHANGED
@@ -146,7 +146,9 @@ module MediawikiApi
|
|
146
146
|
unless @tokens.include?(type)
|
147
147
|
response = action(:tokens, type: type, http_method: :get, token_type: false)
|
148
148
|
|
149
|
-
|
149
|
+
if response.warnings? && response.warnings.grep(/Unrecognized value for parameter 'type'/).any?
|
150
|
+
raise TokenError, response.warnings.join(", ")
|
151
|
+
end
|
150
152
|
|
151
153
|
@tokens[type] = response.data["#{type}token"]
|
152
154
|
end
|
data/spec/client_spec.rb
CHANGED
@@ -15,14 +15,17 @@ describe MediawikiApi::Client do
|
|
15
15
|
subject { client.action(action, params) }
|
16
16
|
|
17
17
|
let(:action) { "something" }
|
18
|
+
let(:token_type) { action }
|
18
19
|
let(:params) { {} }
|
19
20
|
|
20
21
|
let(:response) { { headers: response_headers, body: response_body.to_json } }
|
21
22
|
let(:response_headers) { nil }
|
22
23
|
let(:response_body) { { "something" => {} } }
|
23
24
|
|
25
|
+
let(:token_warning) { nil }
|
26
|
+
|
24
27
|
before do
|
25
|
-
@token_request = stub_token_request(
|
28
|
+
@token_request = stub_token_request(token_type, token_warning)
|
26
29
|
@request = stub_api_request(:post, action: action, token: mock_token).to_return(response)
|
27
30
|
end
|
28
31
|
|
@@ -105,6 +108,24 @@ describe MediawikiApi::Client do
|
|
105
108
|
expect { subject }.to raise_error(MediawikiApi::ApiError, "detailed message (code)")
|
106
109
|
end
|
107
110
|
end
|
111
|
+
|
112
|
+
context "given a bad token type" do
|
113
|
+
let(:params) { { token_type: token_type } }
|
114
|
+
let(:token_type) { "badtoken" }
|
115
|
+
let(:token_warning) { "Unrecognized value for parameter 'type': badtoken" }
|
116
|
+
|
117
|
+
it "raises a TokenError" do
|
118
|
+
expect { subject }.to raise_error(MediawikiApi::TokenError, token_warning)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "when the token response includes only other types of warnings (see bug 70066)" do
|
123
|
+
let(:token_warning) { "action=tokens has been deprecated. Please use action=query&meta=tokens instead." }
|
124
|
+
|
125
|
+
it "raises no exception" do
|
126
|
+
expect { subject }.to_not raise_error
|
127
|
+
end
|
128
|
+
end
|
108
129
|
end
|
109
130
|
|
110
131
|
describe "#log_in" do
|
@@ -22,8 +22,11 @@ module MediawikiApi::RequestHelpers
|
|
22
22
|
stub_api_request(method, params.merge(action: action, token: mock_token))
|
23
23
|
end
|
24
24
|
|
25
|
-
def stub_token_request(type)
|
25
|
+
def stub_token_request(type, warning = nil)
|
26
|
+
response = { tokens: { "#{type}token" => mock_token } }
|
27
|
+
response[:warnings] = { type => { "*" => [warning] } } unless warning.nil?
|
28
|
+
|
26
29
|
stub_api_request(:get, action: "tokens", type: type).
|
27
|
-
to_return(body:
|
30
|
+
to_return(body: response.to_json)
|
28
31
|
end
|
29
32
|
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amir Aharoni
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2014-08-
|
16
|
+
date: 2014-08-27 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: faraday
|