Giter Club home page Giter Club logo

stream-java's Introduction

stream-java

Build Status

stream-java is a Java client for Stream.

You can sign up for a Stream account at https://getstream.io/get_started.

The Stream's Java client come in two different flavours, you should decide which one to drag into your project. Those two implementations differ according to the underlying library used to handle HTTP connections:

  • stream-repo-apache uses Apache HttpClient and we recommend it for backend applications. Apache HttpClient is a mature, reliable and rock-solid HTTP library.
  • stream-repo-okhttp uses Square's OkHttp which is lightweight, powerful and mobile-oriented HTTP library. We recommend it for mobile application.

Installation

If you decide to go for the Apache HttpClient implementation, add the following dependency to your pom.xml:

<dependency>
    <groupId>io.getstream.client</groupId>
    <artifactId>stream-repo-apache</artifactId>
    <version>2.1.3</version>
</dependency>

or in your build.gradle:

compile 'io.getstream.client:stream-repo-apache:2.1.3'

Instead, if you opted for the OkHttp implementation please add it to your pom.xml

<dependency>
    <groupId>io.getstream.client</groupId>
    <artifactId>stream-repo-okhttp</artifactId>
    <version>2.1.3</version>
</dependency>

or in your build.gradle:

compile 'io.getstream.client:stream-repo-okhttp:2.1.3'

In case you want to download the artifact and put it manually into your project, you can download it from here.

Snapshots of the development version are available in Sonatype snapshots repository.

JDK / JVM version requirements

This API Client project requires Java SE 8.

See the Travis configuration for details of how it is built, tested and packaged.

Full documentation

Documentation for this Java client are available at the Stream website.

Usage

/**
 * Instantiate a new client to connect to us east API endpoint
 * Find your API keys here https://getstream.io/dashboard/
 **/

StreamClient streamClient = new StreamClientImpl(new ClientConfiguration(), "<API_KEY>", "<API_SECRET>");

Create a new Feed

/* Instantiate a feed object */
Feed feed = streamClient.newFeed("user", "1");

Working with Activities

/* Create an activity service */
FlatActivityServiceImpl<SimpleActivity> flatActivityService = feed.newFlatActivityService(SimpleActivity.class);

/* Get activities from 5 to 10 (using offset pagination) */
FeedFilter filter = new FeedFilter.Builder().withLimit(5).withOffset(5).build();
List<SimpleActivity> activities = flatActivityService.getActivities(filter).getResults();

/* Filter on an id less than the given UUID */
aid = "e561de8f-00f1-11e4-b400-0cc47a024be0";
FeedFilter filter = new FeedFilter.Builder().withIdLowerThan(aid).withLimit(5).build();
List<SimpleActivity> activities = flatActivityService.getActivities(filter).getResults();

/* Create a new activity */
SimpleActivity activity = new SimpleActivity();
activity.setActor("user:1");
activity.setObject("tweet:1");
activity.setVerb("tweet");
activity.setForeignId("tweet:1");
SimpleActivity response = flatActivityService.addActivity(activity);

/* Remove an activity by its id */
feed.deleteActivity("e561de8f-00f1-11e4-b400-0cc47a024be0");

/* Remove activities by their foreign_id */
feed.deleteActivityByForeignId("tweet:1");

In case you want to add a single activity to multiple feeds, you can use the batch feature addToMany:

/* Batch adding activities to many feeds */
flatActivityService.addActivityToMany(ImmutableList.<String>of("user:1", "user:2").asList(), myActivity);

The API client allows you to send activities with custom field as well, you can find a complete example here

Follow and Unfollow

/* Follow another feed */
feed.follow(flat", "42");

/* Stop following another feed */
feed.unfollow(flat", "42");

/* Retrieve first 10 followers of a feed */
FeedFilter filter = new FeedFilter.Builder().withLimit(10).build();
List<FeedFollow> followingPaged = feed.getFollowing(filter);

/* Retrieve the first 10 followed feeds */
FeedFilter filter = new FeedFilter.Builder().withLimit(10).build();
List<FeedFollow> followingPaged = feed.getFollowing(filter);

In case you want to send to Stream a long list of following relationships you can use the batch feature followMany:

/* Batch following many feeds */
FollowMany followMany = new FollowMany.Builder()
    .add("user:1", "user:2")
    .add("user:1", "user:3")
    .add("user:1", "user:4")
    .add("user:2", "user:3")
    .build();
feed.followMany(followMany);

Client token

In order to generate a token for client side usage (e.g. JS client), you can use the following code:

/* Generating tokens for client side usage */
String token = feed.getToken();

Further references

For more examples have a look here.

Docs are available on GetStream.io.

Javadocs are available here.

Credits & Contributors

This project was originally contributed by Alessandro Pieri, prior to him joining Stream as an employee.

We continue to welcome pull requests from community members.

Copyright and License Information

Copyright (c) 2016-2017 Stream.io Inc, and individual contributors. All rights reserved.

See the file "LICENSE" for information on the history of this software, terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.

stream-java's People

Contributors

dwightgunning avatar kevcodez avatar sirio7g avatar tbarbugli avatar tschellenbach avatar

Watchers

 avatar  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.