jenkins-bot has submitted this change and it was merged.

Change subject: Add get_wikitext and make logging optional
......................................................................


Add get_wikitext and make logging optional

Added a simple get_wikitext which can be used to fetch a page's wikitext.
This is really useful for Cirrus because it doesn't want to blindly create
pages.  It pretty frequently just verifies that pages have the text you
expect.

Making logging optional just allows you to clean up the terminal output.

Change-Id: Id0eb49fe3ac1aee3d320e9a1a6a52c7d89f7e2b9
---
M Gemfile.lock
M lib/mediawiki_api/client.rb
M spec/client_spec.rb
M spec/spec_helper.rb
4 files changed, 25 insertions(+), 5 deletions(-)

Approvals:
  Chad: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Gemfile.lock b/Gemfile.lock
index 50bf67b..98ffebd 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,7 +1,7 @@
 PATH
   remote: .
   specs:
-    mediawiki_api (0.1.0)
+    mediawiki_api (0.1.1)
       faraday (~> 0.9, >= 0.9.0)
       faraday-cookie_jar (~> 0.0, >= 0.0.6)
 
@@ -12,7 +12,7 @@
     crack (0.4.2)
       safe_yaml (~> 1.0.0)
     diff-lcs (1.2.5)
-    domain_name (0.5.16)
+    domain_name (0.5.18)
       unf (>= 0.0.5, < 1.0.0)
     faraday (0.9.0)
       multipart-post (>= 1.2, < 3)
@@ -32,7 +32,7 @@
       diff-lcs (>= 1.1.3, < 2.0)
     rspec-mocks (2.14.6)
     safe_yaml (1.0.1)
-    unf (0.1.3)
+    unf (0.1.4)
       unf_ext
     unf_ext (0.0.6)
     webmock (1.17.4)
diff --git a/lib/mediawiki_api/client.rb b/lib/mediawiki_api/client.rb
index 33c9092..c71e5bd 100644
--- a/lib/mediawiki_api/client.rb
+++ b/lib/mediawiki_api/client.rb
@@ -15,10 +15,12 @@
   class Client
     attr_accessor :logged_in
 
-    def initialize(url)
+    def initialize(url, log=false)
       @conn = Faraday.new(url: url) do |faraday|
         faraday.request :url_encoded
-        faraday.response :logger
+        if log then
+          faraday.response :logger
+        end
         faraday.use :cookie_jar
         faraday.adapter Faraday.default_adapter
       end
@@ -69,6 +71,10 @@
       resp = @conn.post "", { action: "delete", title: title, reason: reason, 
token: token, format: "json" }
     end
 
+    def get_wikitext(title)
+      resp = @conn.get "/w/index.php", { action: "raw", title: title }
+    end
+
     protected
 
     def get_token(type)
diff --git a/spec/client_spec.rb b/spec/client_spec.rb
index 9e8809d..12f9fa3 100644
--- a/spec/client_spec.rb
+++ b/spec/client_spec.rb
@@ -101,6 +101,17 @@
     # evaluate results
   end
 
+  describe "#get_wikitext" do
+    before do
+      @get_req = stub_request(:get, index_url).with(query: { action: "raw", 
title: "Test" })
+    end
+
+    it "fetches a page" do
+      subject.get_wikitext("Test")
+      @get_req.should have_been_requested
+    end
+  end
+
   describe "#create_account" do
     it "creates an account when API returns Success" do
       stub_request(:post, api_url).
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 003e694..29836fa 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -6,6 +6,9 @@
   def api_url
     "http://localhost/api.php";
   end
+  def index_url
+    "http://localhost/w/index.php";
+  end
 end
 
 RSpec.configure do |conf|

-- 
To view, visit https://gerrit.wikimedia.org/r/124384
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id0eb49fe3ac1aee3d320e9a1a6a52c7d89f7e2b9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/ruby/api
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: Zfilipin <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to