mediawiki_api 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2e13c62db930923fbfd515cb2029d9d43508b9a
4
- data.tar.gz: dada9ee27c4c09a1a2c7a157828e16079beace62
3
+ metadata.gz: dd5041d5380d783963ff227ea117400d7ad7c942
4
+ data.tar.gz: b9019f1481fc05e4eeea1061cf09fd42f45ff20c
5
5
  SHA512:
6
- metadata.gz: 145fc6da63febab8ffc18b4d32a6eda108232052fd927380357a7fdfc375eb482681c1ac339e3299f4fee62c3f05fac2e03d766cd401a891991af74a5eb35111
7
- data.tar.gz: eba8ace9d4a58f8148c7e5601d6e216475fc0bce8612bd78bea5fab637a63ed46ffcd4b042cb9bad82d0ace755685d025c0b1d89ccf84567c9fc698aeccbf23e
6
+ metadata.gz: 222b03e90a95dbd7b8c65b9e6e05ab99d7e1edd404975c96d1dc1555db66c04fd4686e8d8c7c98d84d10f6237977123cf1287917b318fd3b15bef497f7f0fdca
7
+ data.tar.gz: af192c8a05c649a1d22bfcb97c9342bd6bb1ef6c0dec3fc7638c4dc2c0eec6f7c36dcf43d61c5e9aad7b8f9feae810bc0ee2d0c6328e94a224a2cadacd400cea
data/.rubocop.yml CHANGED
@@ -1,24 +1,9 @@
1
- Metrics/AbcSize:
2
- Enabled: false
3
-
4
- Metrics/ClassLength:
5
- Enabled: false
6
-
7
- Metrics/MethodLength:
8
- Enabled: false
9
-
10
- Metrics/ParameterLists:
11
- Enabled: false
1
+ AllCops:
2
+ StyleGuideCopsOnly: true
12
3
 
13
4
  Metrics/LineLength:
14
5
  Max: 100
15
6
 
16
- Metrics/CyclomaticComplexity:
17
- Enabled: false
18
-
19
- Metrics/PerceivedComplexity:
20
- Enabled: false
21
-
22
7
  Metrics/MethodLength:
23
8
  Enabled: false
24
9
 
@@ -26,8 +11,13 @@ Style/Alias:
26
11
  Enabled: false
27
12
 
28
13
  Style/DotPosition:
29
- Enabled: true
30
14
  EnforcedStyle: trailing
31
15
 
32
16
  Style/SignalException:
33
17
  Enabled: false
18
+
19
+ Style/StringLiterals:
20
+ EnforcedStyle: single_quotes
21
+
22
+ Style/TrivialAccessors:
23
+ ExactNameMatch: true
data/README.md CHANGED
@@ -26,12 +26,14 @@ require "mediawiki_api"
26
26
 
27
27
  client = MediawikiApi::Client.new "http://127.0.0.1:8080/w/api.php"
28
28
  client.log_in "username", "password" # default Vagrant username and password are "Admin", "vagrant"
29
- client.create_account "username", "password"
29
+ client.create_account "username", "password" # will not work on wikis that require CAPTCHA, like Wikipedia
30
30
  client.create_page "title", "content"
31
31
  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.watch "title"
36
+ client.unwatch "title"
35
37
  client.meta :siteinfo, siprop: "extensions"
36
38
  client.prop :info, titles: "Some page"
37
39
  client.query titles: ["Some page", "Some other page"]
@@ -43,6 +45,15 @@ Any API action can be requested using `#action`. See the
43
45
  [MediaWiki API documentation](http://www.mediawiki.org/wiki/API) for supported
44
46
  actions and parameters.
45
47
 
48
+ By default, the client will attempt to get a csrf token before attempting the
49
+ action. For actions that do not require a token, you can specify
50
+ `token_type: false` to avoid requesting the unnecessary token before the real
51
+ request. For example:
52
+ ```client.action :parse, page: 'Main Page', token_type: false
53
+ ```
54
+
55
+
56
+
46
57
  ## Links
47
58
 
48
59
  MediaWiki API gem at: [Gerrit](https://gerrit.wikimedia.org/r/#/admin/projects/mediawiki/ruby/api), [GitHub](https://github.com/wikimedia/mediawiki-ruby-api), [RubyGems](https://rubygems.org/gems/mediawiki_api), [Code Climate](https://codeclimate.com/github/wikimedia/mediawiki-ruby-api).
@@ -54,6 +65,9 @@ See https://www.mediawiki.org/wiki/Gerrit
54
65
 
55
66
  ## Release notes
56
67
 
68
+ ### 0.4.0 2015-06-16
69
+ - use action=query&meta=tokens to fetch tokens, instead of deprecated action=tokens
70
+
57
71
  ### 0.3.1 2015-01-06
58
72
  - actions now automatically refresh token and re-submit action if first attempt returns 'badtoken'.
59
73
 
@@ -114,18 +114,18 @@ module MediawikiApi
114
114
  end
115
115
 
116
116
  def unwatch_page(title)
117
- action(:watch, titles: title, unwatch: true)
117
+ action(:watch, token_type: 'watch', titles: title, unwatch: true)
118
118
  end
119
119
 
120
120
  def upload_image(filename, path, comment, ignorewarnings)
121
121
  file = Faraday::UploadIO.new(path, 'image/png')
122
122
  action(:upload,
123
- token_type: 'edit', filename: filename, file: file, comment: comment,
123
+ filename: filename, file: file, comment: comment,
124
124
  ignorewarnings: ignorewarnings)
125
125
  end
126
126
 
127
127
  def watch_page(title)
128
- action(:watch, titles: title)
128
+ action(:watch, token_type: 'watch', titles: title)
129
129
  end
130
130
 
131
131
  protected
@@ -145,14 +145,14 @@ module MediawikiApi
145
145
 
146
146
  def get_token(type)
147
147
  unless @tokens.include?(type)
148
- response = action(:tokens, type: type, http_method: :get, token_type: false)
148
+ response = query(meta: 'tokens', type: type)
149
149
  parameter_warning = /Unrecognized value for parameter 'type'/
150
150
 
151
151
  if response.warnings? && response.warnings.grep(parameter_warning).any?
152
152
  raise TokenError, response.warnings.join(', ')
153
153
  end
154
154
 
155
- @tokens[type] = response.data["#{type}token"]
155
+ @tokens[type] = response.data['tokens']["#{type}token"]
156
156
  end
157
157
 
158
158
  @tokens[type]
@@ -182,7 +182,7 @@ module MediawikiApi
182
182
  token_type = params.delete(:token_type)
183
183
  envelope = (params.delete(:envelope) || [name]).map(&:to_s)
184
184
 
185
- params[:token] = get_token(token_type || name) unless token_type == false
185
+ params[:token] = get_token(token_type || :csrf) unless token_type == false
186
186
  params = compile_parameters(params)
187
187
 
188
188
  send_request(method, params.merge(action: name, format: FORMAT), envelope)
@@ -1,4 +1,4 @@
1
1
  # MediaWiki Ruby API
2
2
  module MediawikiApi
3
- VERSION = '0.3.1'
3
+ VERSION = '0.4.0'
4
4
  end
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'bundler', '~> 1.3'
31
31
  spec.add_development_dependency 'rake', '~> 0'
32
32
  spec.add_development_dependency 'rspec', '~> 3.0', '>= 3.0.0'
33
- spec.add_development_dependency 'rubocop', '~> 0.26.1'
33
+ spec.add_development_dependency 'rubocop', '~> 0.29.1'
34
34
  spec.add_development_dependency 'webmock', '~> 1.17', '>= 1.17.2'
35
35
  spec.add_development_dependency 'redcarpet'
36
36
  spec.add_development_dependency 'yard'
data/spec/client_spec.rb CHANGED
@@ -15,7 +15,7 @@ describe MediawikiApi::Client do
15
15
  subject { client.action(action, params) }
16
16
 
17
17
  let(:action) { 'something' }
18
- let(:token_type) { action }
18
+ let(:token_type) { 'csrf' }
19
19
  let(:params) { {} }
20
20
 
21
21
  let(:response) do
@@ -221,7 +221,7 @@ describe MediawikiApi::Client do
221
221
  end
222
222
 
223
223
  it 'does not log in' do
224
- expect { subject.log_in 'Test', 'qwe123' }.to raise_error
224
+ expect { subject.log_in 'Test', 'qwe123' }.to raise_error(MediawikiApi::LoginError)
225
225
  expect(subject.logged_in).to be false
226
226
  end
227
227
 
@@ -240,7 +240,7 @@ describe MediawikiApi::Client do
240
240
  let(:response) { {} }
241
241
 
242
242
  before do
243
- stub_token_request(:edit)
243
+ stub_token_request('csrf')
244
244
  @edit_request = stub_action_request(:edit, title: title, text: text).
245
245
  to_return(body: response.to_json)
246
246
  end
@@ -254,8 +254,8 @@ describe MediawikiApi::Client do
254
254
  describe '#delete_page' do
255
255
  before do
256
256
  stub_request(:get, api_url).
257
- with(query: { format: 'json', action: 'tokens', type: 'delete' }).
258
- to_return(body: { tokens: { deletetoken: 't123' } }.to_json)
257
+ with(query: { format: 'json', action: 'query', meta: 'tokens', type: 'csrf' }).
258
+ to_return(body: { query: { tokens: { csrftoken: 't123' } } }.to_json)
259
259
  @delete_req = stub_request(:post, api_url).
260
260
  with(body: { format: 'json', action: 'delete',
261
261
  title: 'Test', reason: 'deleting', token: 't123' })
@@ -276,7 +276,7 @@ describe MediawikiApi::Client do
276
276
  let(:response) { { edit: {} } }
277
277
 
278
278
  before do
279
- stub_token_request(:edit)
279
+ stub_token_request('csrf')
280
280
  @edit_request = stub_action_request(:edit).to_return(body: response.to_json)
281
281
  end
282
282
 
@@ -363,8 +363,8 @@ describe MediawikiApi::Client do
363
363
  describe '#watch_page' do
364
364
  before do
365
365
  stub_request(:get, api_url).
366
- with(query: { format: 'json', action: 'tokens', type: 'watch' }).
367
- to_return(body: { tokens: { watchtoken: 't123' } }.to_json)
366
+ with(query: { format: 'json', action: 'query', meta: 'tokens', type: 'watch' }).
367
+ to_return(body: { query: { tokens: { watchtoken: 't123' } } }.to_json)
368
368
  @watch_req = stub_request(:post, api_url).
369
369
  with(body: { format: 'json', token: 't123', action: 'watch', titles: 'Test' })
370
370
  end
@@ -378,8 +378,8 @@ describe MediawikiApi::Client do
378
378
  describe '#unwatch_page' do
379
379
  before do
380
380
  stub_request(:get, api_url).
381
- with(query: { format: 'json', action: 'tokens', type: 'watch' }).
382
- to_return(body: { tokens: { watchtoken: 't123' } }.to_json)
381
+ with(query: { format: 'json', action: 'query', meta: 'tokens', type: 'watch' }).
382
+ to_return(body: { query: { tokens: { watchtoken: 't123' } } }.to_json)
383
383
  @watch_req = stub_request(:post, api_url).
384
384
  with(body: { format: 'json', token: 't123', action: 'watch',
385
385
  titles: 'Test', unwatch: 'true' })
@@ -27,10 +27,10 @@ module MediawikiApi
27
27
  end
28
28
 
29
29
  def stub_token_request(type, warning = nil)
30
- response = { tokens: { "#{type}token" => mock_token } }
30
+ response = { query: { tokens: { "#{type}token" => mock_token } } }
31
31
  response[:warnings] = { type => { '*' => [warning] } } unless warning.nil?
32
32
 
33
- stub_api_request(:get, action: 'tokens', type: type).
33
+ stub_api_request(:get, action: 'query', meta: 'tokens', type: type).
34
34
  to_return(body: response.to_json)
35
35
  end
36
36
  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.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amir Aharoni
@@ -14,156 +14,156 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2015-03-03 00:00:00.000000000 Z
17
+ date: 2015-06-16 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: faraday
21
21
  requirement: !ruby/object:Gem::Requirement
22
22
  requirements:
23
- - - ~>
23
+ - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0.9'
26
- - - '>='
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: 0.9.0
29
29
  type: :runtime
30
30
  prerelease: false
31
31
  version_requirements: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ~>
33
+ - - "~>"
34
34
  - !ruby/object:Gem::Version
35
35
  version: '0.9'
36
- - - '>='
36
+ - - ">="
37
37
  - !ruby/object:Gem::Version
38
38
  version: 0.9.0
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: faraday-cookie_jar
41
41
  requirement: !ruby/object:Gem::Requirement
42
42
  requirements:
43
- - - ~>
43
+ - - "~>"
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0.0'
46
- - - '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: 0.0.6
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ~>
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0.0'
56
- - - '>='
56
+ - - ">="
57
57
  - !ruby/object:Gem::Version
58
58
  version: 0.0.6
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: bundler
61
61
  requirement: !ruby/object:Gem::Requirement
62
62
  requirements:
63
- - - ~>
63
+ - - "~>"
64
64
  - !ruby/object:Gem::Version
65
65
  version: '1.3'
66
66
  type: :development
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
69
69
  requirements:
70
- - - ~>
70
+ - - "~>"
71
71
  - !ruby/object:Gem::Version
72
72
  version: '1.3'
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: rake
75
75
  requirement: !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - ~>
77
+ - - "~>"
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
80
  type: :development
81
81
  prerelease: false
82
82
  version_requirements: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - ~>
84
+ - - "~>"
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: rspec
89
89
  requirement: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - ~>
91
+ - - "~>"
92
92
  - !ruby/object:Gem::Version
93
93
  version: '3.0'
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 3.0.0
97
97
  type: :development
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '3.0'
104
- - - '>='
104
+ - - ">="
105
105
  - !ruby/object:Gem::Version
106
106
  version: 3.0.0
107
107
  - !ruby/object:Gem::Dependency
108
108
  name: rubocop
109
109
  requirement: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - ~>
111
+ - - "~>"
112
112
  - !ruby/object:Gem::Version
113
- version: 0.26.1
113
+ version: 0.29.1
114
114
  type: :development
115
115
  prerelease: false
116
116
  version_requirements: !ruby/object:Gem::Requirement
117
117
  requirements:
118
- - - ~>
118
+ - - "~>"
119
119
  - !ruby/object:Gem::Version
120
- version: 0.26.1
120
+ version: 0.29.1
121
121
  - !ruby/object:Gem::Dependency
122
122
  name: webmock
123
123
  requirement: !ruby/object:Gem::Requirement
124
124
  requirements:
125
- - - ~>
125
+ - - "~>"
126
126
  - !ruby/object:Gem::Version
127
127
  version: '1.17'
128
- - - '>='
128
+ - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: 1.17.2
131
131
  type: :development
132
132
  prerelease: false
133
133
  version_requirements: !ruby/object:Gem::Requirement
134
134
  requirements:
135
- - - ~>
135
+ - - "~>"
136
136
  - !ruby/object:Gem::Version
137
137
  version: '1.17'
138
- - - '>='
138
+ - - ">="
139
139
  - !ruby/object:Gem::Version
140
140
  version: 1.17.2
141
141
  - !ruby/object:Gem::Dependency
142
142
  name: redcarpet
143
143
  requirement: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - '>='
145
+ - - ">="
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0'
148
148
  type: :development
149
149
  prerelease: false
150
150
  version_requirements: !ruby/object:Gem::Requirement
151
151
  requirements:
152
- - - '>='
152
+ - - ">="
153
153
  - !ruby/object:Gem::Version
154
154
  version: '0'
155
155
  - !ruby/object:Gem::Dependency
156
156
  name: yard
157
157
  requirement: !ruby/object:Gem::Requirement
158
158
  requirements:
159
- - - '>='
159
+ - - ">="
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0'
162
162
  type: :development
163
163
  prerelease: false
164
164
  version_requirements: !ruby/object:Gem::Requirement
165
165
  requirements:
166
- - - '>='
166
+ - - ">="
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  description: Uses adapter-agnostic Faraday gem to talk to MediaWiki API.
@@ -179,11 +179,11 @@ executables: []
179
179
  extensions: []
180
180
  extra_rdoc_files: []
181
181
  files:
182
- - .gitignore
183
- - .gitreview
184
- - .rspec
185
- - .rubocop.yml
186
- - .yardopts
182
+ - ".gitignore"
183
+ - ".gitreview"
184
+ - ".rspec"
185
+ - ".rubocop.yml"
186
+ - ".yardopts"
187
187
  - CREDITS
188
188
  - Gemfile
189
189
  - LICENSE.txt
@@ -208,17 +208,17 @@ require_paths:
208
208
  - lib
209
209
  required_ruby_version: !ruby/object:Gem::Requirement
210
210
  requirements:
211
- - - '>='
211
+ - - ">="
212
212
  - !ruby/object:Gem::Version
213
213
  version: '0'
214
214
  required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  requirements:
216
- - - '>='
216
+ - - ">="
217
217
  - !ruby/object:Gem::Version
218
218
  version: '0'
219
219
  requirements: []
220
220
  rubyforge_project:
221
- rubygems_version: 2.0.14
221
+ rubygems_version: 2.4.3
222
222
  signing_key:
223
223
  specification_version: 4
224
224
  summary: A library for interacting with MediaWiki API from Ruby.