Skip to content

Commit

Permalink
Fixed and updated docs, update gradle build, add new sanity test
Browse files Browse the repository at this point in the history
  • Loading branch information
fastily committed Mar 30, 2017
1 parent 413c9da commit 53be2eb
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 45 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#jwiki
# jwiki
jwiki is a simple Java client library wrapping the [MediaWiki](https://www.mediawiki.org/wiki/MediaWiki) Web [API](https://www.mediawiki.org/wiki/API:Main_page). It can be used by developers to create bots and tools, or to perform analytics on just about any Wiki.

[![Build Status](https://travis-ci.org/fastily/jwiki.svg?branch=master)](https://travis-ci.org/fastily/jwiki)

##Features
## Features
* Perform actions, such as edit, delete, and upload (using chunked uploads).
* Perform queries, such as getting category members, getting links on a page, and getting template transclusions.
* Support for popular MediaWiki extensions, including [CentralAuth](https://www.mediawiki.org/wiki/Extension:CentralAuth) and [GlobalUsage](https://www.mediawiki.org/wiki/Extension:GlobalUsage).

##Getting Started
## Getting Started
* Main class: [Wiki.java](https://github.com/fastily/jwiki/blob/master/src/main/java/fastily/jwiki/core/Wiki.java)
* [Recipe Book/Cheatsheet](https://github.com/fastily/jwiki/wiki/Recipe-Book)
* [Javadocs](https://fastily.github.io/jwiki/docs/jwiki/)

###Example Code
### Example Code
```java
import fastily.jwiki.core.Wiki;

Expand All @@ -28,7 +28,7 @@ public class JwikiExample
}
```

###Download
### Download
jwiki is available via [bintray/jcenter](https://bintray.com/fastily/maven/jwiki)

Maven:
Expand All @@ -46,11 +46,11 @@ Gradle:
compile 'fastily:jwiki:1.2.1'
```

###Minimum Requirements
### Minimum Requirements
* [JDK](https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html): **1.8.0_40+**
* [MediaWiki](https://www.mediawiki.org/wiki/MediaWiki): **1.27+**

##Project Objectives
## Project Objectives
jwiki is intended to be a simple, reliable, and low-overhead framework for anybody seeking to make use of the MediaWiki API. Emphasis is placed on:

* **Simplicity** - Complex objects and functions are abstracted into the background so that _anybody_, regardless of Java experience, will be able to use jwiki.
Expand Down
61 changes: 35 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
apply plugin: 'java-library'
apply plugin: 'eclipse'
apply plugin: 'maven'
// apply plugin: 'maven-publish'

version="1.2.2"
description="jwiki build script"
group="fastily"

sourceSets {
main {
resources {
srcDirs = ['.']
includes=['*.md']
compileJava {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}

/*publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
model {
tasks.generatePomFileForMavenCustomPublication {
destination = file("$buildDir/generated-pom.xml")
}
}
}
*/

compileJava {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
repositories {
jcenter()
}

dependencies {
api "com.google.code.gson:gson:2.8.0"
api "com.squareup.okhttp3:okhttp:3.6.0"

testImplementation 'junit:junit:4.12'
testImplementation 'com.squareup.okhttp3:mockwebserver:3.6.0'
}

task writeNewPom {
Expand All @@ -42,28 +61,18 @@ task genJavadoc(type: Javadoc) {

options
{
links "https://square.github.io/okhttp/3.x/okhttp/"
links "https://square.github.io/okio/1.x/okio/"
links "https://www.javadoc.io/doc/com.google.code.gson/gson/2.8.0"
links "https://docs.oracle.com/javase/8/docs/api/"

setMemberLevel JavadocMemberLevel.PUBLIC
setAuthor true
}

classpath = configurations.compile
}

repositories {
jcenter()
}
links "https://docs.oracle.com/javase/8/docs/api/"
links "https://square.github.io/okio/1.x/okio/"
links "https://square.github.io/okhttp/3.x/okhttp/"
links "https://fastily.github.io/jwiki/docs/gson/"

dependencies {
api "com.google.code.gson:gson:2.8.0"
api "com.squareup.okhttp3:okhttp:3.6.0"

testImplementation 'junit:junit:4.12'
testImplementation 'com.squareup.okhttp3:mockwebserver:3.6.0'
// setOutputLevel JavadocOutputLevel.VERBOSE
}

classpath = configurations.compileClasspath
}

task wrapper(type: Wrapper) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/fastily/jwiki/core/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private Request.Builder startReq(HashMap<String, String> params)
HttpUrl.Builder hb = wiki.conf.baseURL.newBuilder();
params.forEach(hb::addQueryParameter);

return new Request.Builder().addHeader("User-Agent", wiki.conf.userAgent).url(hb.build());
return new Request.Builder().url(hb.build()).header("User-Agent", wiki.conf.userAgent);
}

/**
Expand All @@ -98,7 +98,7 @@ private Request.Builder startReq(HashMap<String, String> params)
*/
protected Response basicGET(HashMap<String, String> params) throws IOException
{
return client.newCall(startReq(params).build()).execute();
return client.newCall(startReq(params).get().build()).execute();
}

/**
Expand Down Expand Up @@ -130,7 +130,7 @@ protected Response multiPartFilePOST(HashMap<String, String> params, HashMap<Str
throws IOException
{
MultipartBody.Builder mpb = new MultipartBody.Builder().setType(MultipartBody.FORM);
form.entrySet().stream().forEach(e -> mpb.addFormDataPart(e.getKey(), e.getValue()));
form.forEach(mpb::addFormDataPart);

mpb.addFormDataPart("chunk", fn, RequestBody.create(octetstream, chunk));

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fastily/jwiki/core/MQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import fastily.jwiki.util.Tuple;

/**
* Perform multi-title queries. Use of these methods is intended for <ins>advanced</ins> users who wish to make queries
* Perform multi-title queries. Use of these methods is intended for <span style="text-decoration:underline;">advanced</span> users who wish to make queries
* to the server over a large data set. These methods are optimized for performance, and will consolidate titles into
* single queries to fetch the most data possible per query. If you're looking to make simple, single-item queries,
* (which is suitable for most users) please use the methods in Wiki.java.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/fastily/jwiki/core/package-info.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/**
* Contains the main classes for jwiki. Most of the classes here contain protected/private members which abstract the
* nasty/complicated details which do not, and should not concern the typical programmer. These classes all tie into
* <code>Wiki.java</code>, and for most users, this is the only class you're going to need.
* {@code Wiki.java} , and for most users, this is the only class you're going to need.
* <br><br>
* <a href="https://github.com/fastily/jwiki">jwiki</a> is licensed under the terms of the <a href="https://www.gnu.org/licenses/gpl-3.0.en.html">GPLv3</a>.
*
* @author Fastily
*/
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/fastily/jwiki/dwrap/Revision.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public class Revision extends DataEntry
/**
* Constructor, creates a revision object.
*
* @param title The title of the page we're using. NB: This isn't explicitly included in the JSONObject from the
* server
* @param r The ServerReply containing the revision to parse.
*/
public Revision(JsonObject r)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/fastily/jwiki/dwrap/package-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Contains data storage formats for jwiki. These are simple objects with public final, immutable fields.
*
* <br><br>
* <a href="https://github.com/fastily/jwiki">jwiki</a> is licensed under the terms of the <a href="https://www.gnu.org/licenses/gpl-3.0.en.html">GPLv3</a>.
* @author Fastily
*/
package fastily.jwiki.dwrap;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/fastily/jwiki/util/package-info.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* Classes with static methods that support the jwiki core framework. These are very general, and may be helpful in
* applications that build on jwiki.
*
* <br><br>
* <a href="https://github.com/fastily/jwiki">jwiki</a> is licensed under the terms of the <a href="https://www.gnu.org/licenses/gpl-3.0.en.html">GPLv3</a>.
* @author Fastily
*/

Expand Down
15 changes: 13 additions & 2 deletions src/test/java/fastily/jwiki/test/ActionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -70,10 +71,20 @@ public void testInitializationForSanity()
{
assertEquals("File:Test.jpg", wiki.convertIfNotInNS("Test.jpg", NS.FILE));

try
{
assertTrue(server.takeRequest(2, TimeUnit.SECONDS).getHeader("User-Agent").contains("jwiki"));
}
catch (Throwable e)
{
e.printStackTrace();
fail();
}

assertEquals(NS.FILE.v, wiki.whichNS("File:Test.jpg").v);
assertEquals(NS.MAIN.v, wiki.whichNS("hello").v);
}

/**
* Test editing
*/
Expand All @@ -95,7 +106,7 @@ public void testAddText()
assertTrue(wiki.addText("Wikipedia:Sandbox", "Appending text!", "test", true));
assertTrue(wiki.addText("Wikipedia:Sandbox", "Appending text!", "test", false));
}

/**
* Loads a MockResponse into the {@code server}'s queue.
*
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/fastily/jwiki/test/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* This is a collection of public-facing <a href="https://github.com/junit-team/junit">junit</a> tests for
* <a href="https://github.com/fastily/jwiki">jwiki</a>. Pre-condition: The test suite is backed by
* <a href="https://test.wikipedia.org/wiki/Main_Page">test.wikipedia.org</a>.
*
* <br><br>
* <a href="https://github.com/fastily/jwiki">jwiki</a> is licensed under the terms of the <a href="https://www.gnu.org/licenses/gpl-3.0.en.html">GPLv3</a>.
* @author Fastily
*/
package fastily.jwiki.test;

0 comments on commit 53be2eb

Please sign in to comment.