Dduvall has uploaded a new change for review.
https://gerrit.wikimedia.org/r/151977
Change subject: More direct interface to the API's edit action
......................................................................
More direct interface to the API's edit action
Provided a direct interface to the edit action to allow for more
advanced use such as appendtext, prependtext, etc.
Change-Id: Ifebd2c7395ea7e90d31207b67b6117155706db67
---
M lib/mediawiki_api/client.rb
M lib/mediawiki_api/exceptions.rb
M spec/client_spec.rb
3 files changed, 21 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/ruby/api
refs/changes/77/151977/1
diff --git a/lib/mediawiki_api/client.rb b/lib/mediawiki_api/client.rb
index a81398a..86b1dfc 100644
--- a/lib/mediawiki_api/client.rb
+++ b/lib/mediawiki_api/client.rb
@@ -45,13 +45,17 @@
end
def create_page(title, content)
- action(:edit, title: title, text: content)
+ edit(title: title, text: content)
end
def delete_page(title, reason)
action(:delete, title: title, reason: reason)
end
+ def edit(params = {})
+ action(:edit, params)
+ end
+
def get_wikitext(title)
@conn.get "/w/index.php", { action: "raw", title: title }
end
diff --git a/lib/mediawiki_api/exceptions.rb b/lib/mediawiki_api/exceptions.rb
index 21bc6e9..7174fe7 100644
--- a/lib/mediawiki_api/exceptions.rb
+++ b/lib/mediawiki_api/exceptions.rb
@@ -15,7 +15,7 @@
end
def to_s
- "#{self.class.name}: #{info} (#{code})"
+ "#{info} (#{code})"
end
private
diff --git a/spec/client_spec.rb b/spec/client_spec.rb
index 5028e1b..1c98195 100644
--- a/spec/client_spec.rb
+++ b/spec/client_spec.rb
@@ -100,6 +100,21 @@
# evaluate results
end
+ describe "#edit" do
+ before do
+ stub_request(:get, api_url).
+ with(query: { format: "json", action: "tokens", type: "edit" }).
+ to_return(body: { tokens: { edittoken: "t123" } }.to_json )
+ @edit_req = stub_request(:post, api_url).
+ with(body: { format: "json", token: "t123", action: "edit", title:
"Test", text: "test123" })
+ end
+
+ it "sends a valid edit request using the given parameters" do
+ subject.edit(title: "Test", text: "test123")
+ expect(@edit_req).to have_been_requested
+ end
+ end
+
describe "#get_wikitext" do
before do
@get_req = stub_request(:get, index_url).with(query: { action: "raw",
title: "Test" })
--
To view, visit https://gerrit.wikimedia.org/r/151977
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifebd2c7395ea7e90d31207b67b6117155706db67
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/ruby/api
Gerrit-Branch: master
Gerrit-Owner: Dduvall <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits