Git Product home page Git Product logo

wykop.pl-java-sdk's Introduction

Unofficial SDK for Wykop.pl API

SDK consists of a set of classes that hide a low-level architecture of the Wykop.pl API, and provides object-oriented, type-safe interface to access the API. These classes could be divided into three main packages:

  • com.crozin.wykop.sdk.domain — read-only domain objects, that represent a single entity, e.g. Link, Profile or Comment,
  • com.crozin.wykop.sdk.repository — repositories are divided into two types. The first one contains methods to retrieve domain objects of a given type, e.g. LinksRepository.getPromoted() returns a List of Links, and the other one associated with a certain entity, contains methods to return domain objects associated with that entity, e.g. ProfileRepository.getFollowers() returns a List of Profiles that given account follows.
  • com.crozin.wykop.sdk.service — services provide interfaces to execute a certain operations on a given entity, e.g. CommentService.delete() deletes a comment, if the account is allowed to do that.

Services are available only if the SDK session is associated with some account. The only exception is SearchService, which is available for annonymous (read-only) session.


SDK is available through its own Maven repository. In order to use it, add following declaration to your pom.xml file:

<repositories>
	<repository>
		<id>wykop.pl-java-sdk-mvn-repository</id>
		<url>https://raw.github.com/Crozin/Wykop.pl-Java-SDK/mvn-repo/</url>
		<snapshots>
			<enabled>true</enabled>
			<updatePolicy>always</updatePolicy>
		</snapshots>
	</repository>
</repositories>

Now you can simply add the dependency:

<dependencies>
    ...

	<dependency>
		<groupId>com.crozin</groupId>
		<artifactId>com.crozin.wykop.sdk</artifactId>
		<version>1.0.0</version>
	</dependency>
</dependencies>

Setting up a new session (connection)

The first step is to create an Application object, that represents your application. Application is a factory class for Session objects.

Application app = new Application("public-key", "private-key");

The next step is opening the actual session. There are two types of session: annonymous one, which provides read-only access to the API, and authenticated one, which is associated with a certain account and is capable of performing some operations on its behalf.

// Annonymous session
Session session = app.openSession();

// Authenticated session
AuthenticatedSession session = app.openSession("account-key");
AuthenticatedSession session = app.openSession("username", "password");

Note: To open an authenticated session using username and password the application has to have a special premission granted by Wykop.pl administration.

Examples

Get a link and all of its buries

Link link = session.find(1147383, Link.class);
List<Bury> buries = session.getLinkRepository(link).getBuries();

System.out.format("Link: %s, by: %s%n", link.getTitle(), link.getAuthor().getUsername());
for (Bury bury : buries) {
    System.out.println("\t- " + bury.getAuthor().getUsername());
}

// Link: Co wolno księdzu?, by: feniks79
//     - wilkpiski
//     - jacek-banaszkiewicz
// ...
//     - Wierzejski

List promoted links:

List<Link> links = session.getLinksRepository().getPromoted();

for (Link link : links) {
    System.out.format("%s - %d%n", link.getUrl(), link.getVotesCount());
}

// http://www.wykop.pl/link/1147057/kapiel-relaks-dla-noworodka/ - 122
// http://www.wykop.pl/link/1147165/pija-wodke-za-pieniadze-z-opieki-spolecznej/ - 116
// ...
// http://www.wykop.pl/link/1146403/rosyjska-incepcja/ - 445
// http://www.wykop.pl/link/1146509/wypadek-ciezarowki/ - 445

Open a new authenticated session and add a new link:

AuthenticatedSession session = app.openSession("account-key");
    
LinkCandidate link = new LinkCandidate();
link.setUrl(new URL("http://example.org/"));
link.setTitle("Foobar");
link.setDescription("Lorem ipsum dolor");
link.setGroup("foo");
link.addTag("foo");
link.addTag("bar");
link.addTag("foobar");

session.getClientService().addLink(link);

Custom commands

Although SDK supports all features of Wykop.pl API it is possible to execute a custom command using Command and Session objects.

// Fetch first chunk (page) of hits of May 2011
// see: http://www.wykop.pl/developers/docs/#info6_8_2

Command cmd = new Command("top", "date");
cmd.addArgument(2011);
cmd.addArgument(5);
cmd.addPostParameter("page", 0);

List<Link> hitsOfMay2011 = session.getResultList(cmd, Link.class);

wykop.pl-java-sdk's People

Contributors

mafoski avatar handmade0octopus avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.