Skip to content

Instantly share code, notes, and snippets.

@ttaylorr
Created March 4, 2015 01:45
Show Gist options
  • Save ttaylorr/6fe338c5fd8a235556da to your computer and use it in GitHub Desktop.
Save ttaylorr/6fe338c5fd8a235556da to your computer and use it in GitHub Desktop.
ChatConnectable API
package pro.beam.api;
import pro.beam.api.resource.BeamUser;
import pro.beam.api.resource.chat.BeamChat;
import pro.beam.api.resource.chat.BeamChatConnectable;
import pro.beam.api.resource.chat.events.EventHandler;
import pro.beam.api.resource.chat.events.IncomingMessageEvent;
import pro.beam.api.resource.chat.events.StatusEvent;
import pro.beam.api.resource.chat.methods.AuthenticateMessage;
import pro.beam.api.resource.chat.replies.AuthenticationReply;
import pro.beam.api.resource.chat.replies.ReplyHandler;
import pro.beam.api.services.impl.ChatService;
import pro.beam.api.services.impl.UsersService;
import java.util.concurrent.ExecutionException;
public class Application {
public static void main(String[] args) throws ExecutionException, InterruptedException {
BeamAPI beam = new BeamAPI();
BeamUser ttaylorr = beam.use(UsersService.class).login("<user>", "<password>").get();
BeamChat chat = beam.use(ChatService.class).findOne(ttaylorr.channel.id).get();
BeamChatConnectable connectable = chat.makeConnectable(beam);
boolean connected = connectable.connectBlocking();
if (connected) {
connectable.send(AuthenticateMessage.from(ttaylorr.channel, ttaylorr, chat.authkey), new ReplyHandler<AuthenticationReply>() {
@Override
public void onSuccess(AuthenticationReply reply) {
System.out.println("Authenticated!");
}
});
connectable.on(StatusEvent.class, new EventHandler<StatusEvent>() {
@Override
public void onEvent(StatusEvent event) {
// ...
}
});
connectable.on(IncomingMessageEvent.class, new EventHandler<IncomingMessageEvent>() {
@Override
public void onEvent(IncomingMessageEvent event) {
// ...
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment