mediawiki_api 0.2.1 → 0.3.0
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/.gitignore +2 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +102 -0
- data/.yardopts +1 -0
- data/README.md +5 -0
- data/lib/mediawiki_api/client.rb +10 -2
- data/lib/mediawiki_api/exceptions.rb +18 -0
- data/lib/mediawiki_api/version.rb +1 -1
- data/mediawiki_api.gemspec +2 -0
- data/spec/client_spec.rb +55 -9
- data/spec/support/request_helpers.rb +2 -0
- metadata +33 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20db69d02e685dd6c01f43a617e783310b884784
|
4
|
+
data.tar.gz: 8ea86db0e30f32006981ba4e04779f0e8eb1b73c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5c9196a44d8975fb8081273791487d88188ed4f452c892d656d2de940fc9e1049b61dd64ec14d2a71e7c0c6935109bfb006378eb697bd189f70536d10ed80b9
|
7
|
+
data.tar.gz: cd1f86124b668e951ec1a608be92ec7c6aee66273eb3c360da85b546ffd460d87427d16a4dcac23c5e0c476c5f77c207cdce673af3053bb4b9a9a3ce03bc21c9
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2014-09-10 11:44:33 -0700 using RuboCop version 0.26.0.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 3
|
9
|
+
Lint/UselessAssignment:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
# Offense count: 1
|
13
|
+
# Configuration parameters: CountComments.
|
14
|
+
Metrics/ClassLength:
|
15
|
+
Max: 122
|
16
|
+
|
17
|
+
# Offense count: 1
|
18
|
+
Metrics/CyclomaticComplexity:
|
19
|
+
Max: 7
|
20
|
+
|
21
|
+
# Offense count: 53
|
22
|
+
# Configuration parameters: AllowURI.
|
23
|
+
Metrics/LineLength:
|
24
|
+
Max: 182
|
25
|
+
|
26
|
+
# Offense count: 3
|
27
|
+
# Configuration parameters: CountComments.
|
28
|
+
Metrics/MethodLength:
|
29
|
+
Max: 13
|
30
|
+
|
31
|
+
# Offense count: 1
|
32
|
+
# Cop supports --auto-correct.
|
33
|
+
Style/Alias:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
# Offense count: 9
|
37
|
+
# Cop supports --auto-correct.
|
38
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
39
|
+
Style/BracesAroundHashParameters:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
# Offense count: 1
|
43
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
44
|
+
Style/ClassAndModuleChildren:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
# Offense count: 6
|
48
|
+
Style/Documentation:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
# Offense count: 30
|
52
|
+
# Cop supports --auto-correct.
|
53
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
54
|
+
Style/DotPosition:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
# Offense count: 2
|
58
|
+
# Cop supports --auto-correct.
|
59
|
+
Style/LeadingCommentSpace:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
# Offense count: 2
|
63
|
+
# Cop supports --auto-correct.
|
64
|
+
# Configuration parameters: PreferredDelimiters.
|
65
|
+
Style/PercentLiteralDelimiters:
|
66
|
+
Enabled: false
|
67
|
+
|
68
|
+
# Offense count: 1
|
69
|
+
Style/RegexpLiteral:
|
70
|
+
MaxSlashes: 0
|
71
|
+
|
72
|
+
# Offense count: 6
|
73
|
+
# Cop supports --auto-correct.
|
74
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
75
|
+
Style/SignalException:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
# Offense count: 9
|
79
|
+
# Cop supports --auto-correct.
|
80
|
+
Style/SpaceInsideParens:
|
81
|
+
Enabled: false
|
82
|
+
|
83
|
+
# Offense count: 1
|
84
|
+
# Cop supports --auto-correct.
|
85
|
+
Style/SpecialGlobalVars:
|
86
|
+
Enabled: false
|
87
|
+
|
88
|
+
# Offense count: 299
|
89
|
+
# Cop supports --auto-correct.
|
90
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
91
|
+
Style/StringLiterals:
|
92
|
+
Enabled: false
|
93
|
+
|
94
|
+
# Offense count: 2
|
95
|
+
# Cop supports --auto-correct.
|
96
|
+
Style/UnneededPercentQ:
|
97
|
+
Enabled: false
|
98
|
+
|
99
|
+
# Offense count: 4
|
100
|
+
# Cop supports --auto-correct.
|
101
|
+
Style/WordArray:
|
102
|
+
MinSize: 2
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--title "MediaWiki Ruby API"
|
data/README.md
CHANGED
@@ -54,6 +54,11 @@ See https://www.mediawiki.org/wiki/Gerrit
|
|
54
54
|
|
55
55
|
## Release notes
|
56
56
|
|
57
|
+
### 0.3.0 2014-10-14
|
58
|
+
|
59
|
+
- HTTP 400 and 500 responses now result in an HttpError exception.
|
60
|
+
- Edit failures now result in an EditError exception.
|
61
|
+
|
57
62
|
### 0.2.1 2014-08-26
|
58
63
|
|
59
64
|
- Fix error handling for token requests
|
data/lib/mediawiki_api/client.rb
CHANGED
@@ -37,8 +37,10 @@ module MediawikiApi
|
|
37
37
|
|
38
38
|
response = @conn.send(method, "", params.merge(action: name, format: FORMAT))
|
39
39
|
|
40
|
+
raise HttpError, response.status if response.status >= 400
|
41
|
+
|
40
42
|
if response.headers.include?("mediawiki-api-error")
|
41
|
-
raise ApiError
|
43
|
+
raise ApiError, Response.new(response, ["error"])
|
42
44
|
end
|
43
45
|
|
44
46
|
Response.new(response, envelope)
|
@@ -64,13 +66,19 @@ module MediawikiApi
|
|
64
66
|
end
|
65
67
|
|
66
68
|
def create_page(title, content)
|
67
|
-
|
69
|
+
edit(title: title, text: content)
|
68
70
|
end
|
69
71
|
|
70
72
|
def delete_page(title, reason)
|
71
73
|
action(:delete, title: title, reason: reason)
|
72
74
|
end
|
73
75
|
|
76
|
+
def edit(params = {})
|
77
|
+
response = action(:edit, params)
|
78
|
+
raise EditError, response if response.data["result"] == "Failure"
|
79
|
+
response
|
80
|
+
end
|
81
|
+
|
74
82
|
def get_wikitext(title)
|
75
83
|
@conn.get "/w/index.php", { action: "raw", title: title }
|
76
84
|
end
|
@@ -28,6 +28,24 @@ module MediawikiApi
|
|
28
28
|
class CreateAccountError < StandardError
|
29
29
|
end
|
30
30
|
|
31
|
+
class HttpError < StandardError
|
32
|
+
attr_reader :status
|
33
|
+
|
34
|
+
def initialize(status)
|
35
|
+
@status = status
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
"unexpected HTTP response (#{status})"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class EditError < ApiError
|
44
|
+
def to_s
|
45
|
+
"check the response data for details"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
31
49
|
class LoginError < StandardError
|
32
50
|
end
|
33
51
|
|
data/mediawiki_api.gemspec
CHANGED
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "rake", "~> 0"
|
25
25
|
spec.add_development_dependency "rspec", "~> 3.0", ">= 3.0.0"
|
26
26
|
spec.add_development_dependency "webmock", "~> 1.17", ">= 1.17.2"
|
27
|
+
spec.add_development_dependency "redcarpet"
|
28
|
+
spec.add_development_dependency "yard"
|
27
29
|
end
|
data/spec/client_spec.rb
CHANGED
@@ -18,7 +18,8 @@ describe MediawikiApi::Client do
|
|
18
18
|
let(:token_type) { action }
|
19
19
|
let(:params) { {} }
|
20
20
|
|
21
|
-
let(:response) { { headers: response_headers, body: response_body.to_json } }
|
21
|
+
let(:response) { { status: response_status, headers: response_headers, body: response_body.to_json } }
|
22
|
+
let(:response_status) { 200 }
|
22
23
|
let(:response_headers) { nil }
|
23
24
|
let(:response_body) { { "something" => {} } }
|
24
25
|
|
@@ -100,6 +101,22 @@ describe MediawikiApi::Client do
|
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
104
|
+
context "when the response status is in the 400 range" do
|
105
|
+
let(:response_status) { 403 }
|
106
|
+
|
107
|
+
it "raises an HttpError" do
|
108
|
+
expect { subject }.to raise_error(MediawikiApi::HttpError, "unexpected HTTP response (403)")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "when the response status is in the 500 range" do
|
113
|
+
let(:response_status) { 502 }
|
114
|
+
|
115
|
+
it "raises an HttpError" do
|
116
|
+
expect { subject }.to raise_error(MediawikiApi::HttpError, "unexpected HTTP response (502)")
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
103
120
|
context "when the response is an error" do
|
104
121
|
let(:response_headers) { { "MediaWiki-API-Error" => "code" } }
|
105
122
|
let(:response_body) { { error: { info: "detailed message", code: "code" } } }
|
@@ -189,17 +206,21 @@ describe MediawikiApi::Client do
|
|
189
206
|
end
|
190
207
|
|
191
208
|
describe "#create_page" do
|
209
|
+
subject { client.create_page(title, text) }
|
210
|
+
|
211
|
+
let(:title) { "Test" }
|
212
|
+
let(:text) { "test123" }
|
213
|
+
let(:response) { {} }
|
214
|
+
|
192
215
|
before do
|
193
|
-
|
194
|
-
|
195
|
-
to_return(body:
|
196
|
-
@edit_req = stub_request(:post, api_url).
|
197
|
-
with(body: { format: "json", action: "edit", title: "Test", text: "test123", token: "t123" })
|
216
|
+
stub_token_request(:edit)
|
217
|
+
@edit_request = stub_action_request(:edit, title: title, text: text).
|
218
|
+
to_return(body: response.to_json)
|
198
219
|
end
|
199
220
|
|
200
|
-
it "
|
201
|
-
subject
|
202
|
-
expect(@
|
221
|
+
it "makes the right request" do
|
222
|
+
subject
|
223
|
+
expect(@edit_request).to have_been_requested
|
203
224
|
end
|
204
225
|
end
|
205
226
|
|
@@ -220,6 +241,31 @@ describe MediawikiApi::Client do
|
|
220
241
|
# evaluate results
|
221
242
|
end
|
222
243
|
|
244
|
+
describe "#edit" do
|
245
|
+
subject { client.edit(params) }
|
246
|
+
|
247
|
+
let(:params) { {} }
|
248
|
+
let(:response) { { edit: {} } }
|
249
|
+
|
250
|
+
before do
|
251
|
+
stub_token_request(:edit)
|
252
|
+
@edit_request = stub_action_request(:edit).to_return(body: response.to_json)
|
253
|
+
end
|
254
|
+
|
255
|
+
it "makes the request" do
|
256
|
+
subject
|
257
|
+
expect(@edit_request).to have_been_requested
|
258
|
+
end
|
259
|
+
|
260
|
+
context "upon an edit failure" do
|
261
|
+
let(:response) { { edit: { result: "Failure" } } }
|
262
|
+
|
263
|
+
it "raises an EditError" do
|
264
|
+
expect { subject }.to raise_error(MediawikiApi::EditError)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
223
269
|
describe "#get_wikitext" do
|
224
270
|
before do
|
225
271
|
@get_req = stub_request(:get, index_url).with(query: { action: "raw", title: "Test" })
|
@@ -12,6 +12,8 @@ module MediawikiApi::RequestHelpers
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def stub_api_request(method, params)
|
15
|
+
params = params.each.with_object({}) { |(k, v), p| p[k] = v.to_s }
|
16
|
+
|
15
17
|
stub_request(method, api_url).
|
16
18
|
with((method == :post ? :body : :query) => params.merge(format: "json"))
|
17
19
|
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
|
+
version: 0.3.0
|
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-
|
16
|
+
date: 2014-10-14 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: faraday
|
@@ -123,6 +123,34 @@ dependencies:
|
|
123
123
|
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: 1.17.2
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: redcarpet
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: yard
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
126
154
|
description: Uses adapter-agnostic Faraday gem to talk to MediaWiki API.
|
127
155
|
email:
|
128
156
|
- amir.aharoni@mail.huji.ac.il
|
@@ -138,6 +166,9 @@ files:
|
|
138
166
|
- ".gitignore"
|
139
167
|
- ".gitreview"
|
140
168
|
- ".rspec"
|
169
|
+
- ".rubocop.yml"
|
170
|
+
- ".rubocop_todo.yml"
|
171
|
+
- ".yardopts"
|
141
172
|
- CREDITS
|
142
173
|
- Gemfile
|
143
174
|
- LICENSE.txt
|