{"id":13694776,"url":"https://github.com/Gitteroid/GitterJavaSDK","last_synced_at":"2025-05-03T04:30:54.496Z","repository":{"id":92711130,"uuid":"43413025","full_name":"Gitteroid/GitterJavaSDK","owner":"Gitteroid","description":"Gitter.im Java SDK that facilitates communication with Gitter API.","archived":false,"fork":false,"pushed_at":"2019-06-24T07:10:01.000Z","size":357,"stargazers_count":40,"open_issues_count":1,"forks_count":12,"subscribers_count":6,"default_branch":"dev","last_synced_at":"2024-11-12T21:39:14.779Z","etag":null,"topics":["async","gitter","gitter-api","java","rxjava","sync"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Gitteroid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-09-30T05:05:39.000Z","updated_at":"2022-06-23T01:34:16.000Z","dependencies_parsed_at":"2023-03-07T20:45:12.577Z","dependency_job_id":null,"html_url":"https://github.com/Gitteroid/GitterJavaSDK","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gitteroid%2FGitterJavaSDK","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gitteroid%2FGitterJavaSDK/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gitteroid%2FGitterJavaSDK/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gitteroid%2FGitterJavaSDK/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gitteroid","download_url":"https://codeload.github.com/Gitteroid/GitterJavaSDK/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252144478,"owners_count":21701420,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","gitter","gitter-api","java","rxjava","sync"],"created_at":"2024-08-02T17:01:41.820Z","updated_at":"2025-05-03T04:30:53.442Z","avatar_url":"https://github.com/Gitteroid.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/Gitteroid/GitterJavaSDK.svg?branch=dev)](https://travis-ci.org/Gitteroid/GitterJavaSDK) \n# Gitter.im Java SDK\n\n:+1: **_Fully compatible with Android_**\n\nAsync : [ ![Download](https://api.bintray.com/packages/amatkivskiy/maven/gitter.sdk.async/images/download.svg) ](https://bintray.com/amatkivskiy/maven/gitter.sdk.async/_latestVersion)\n\nSync : [ ![Download](https://api.bintray.com/packages/amatkivskiy/maven/gitter.sdk.async/images/download.svg) ](https://bintray.com/amatkivskiy/maven/gitter.sdk.sync/_latestVersion)\n\nRx : [ ![Download](https://api.bintray.com/packages/amatkivskiy/maven/gitter.sdk.async/images/download.svg) ](https://bintray.com/amatkivskiy/maven/gitter.sdk.rx/_latestVersion) [![Coverage Status](https://coveralls.io/repos/github/Gitteroid/GitterJavaSDK/badge.svg?branch=feature%2Ftesting_plus_ci)](https://coveralls.io/github/Gitteroid/GitterJavaSDK?branch=feature%2Ftesting_plus_ci)\n\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-GitterJavaSDK-green.svg?style=flat)](http://android-arsenal.com/details/1/2599)\n\n[![Join the chat at https://gitter.im/Gitteroid/GitterRxJavaSDK](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Gitteroid/GitterJavaSDK?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nGitter.im Java SDK that facilitates communication with Gitter API, Gitter Streaming API, Gitter Faye API.\n\nIt provides three approaches to work with API:\n- RxJava approach;\n- Async (callback) approach.\n- Sync approach.\n\n## Table of content\n- [Features](#Features)\n- [Release Notes](#ReleaseNotes)\n- [Setup](#Setup)\n- [Description](#Description)\n- [Streaming](#Streaming)\n- [Faye](#Faye)\n- [Samples](#Samples)\n\n### \u003ca name=\"Setup\"\u003e**Setup**\nAdd gradle dependency:\n\nFor RxJava:\n```groovy\nrepositories {\n      jcenter()\n}\n\ndependencies {\n      compile 'com.github.amatkivskiy:gitter.sdk.rx:1.6.1'\n}\n```\n\nFor async:\n```groovy\nrepositories {\n      jcenter()\n}\n\ndependencies {\n      compile 'com.github.amatkivskiy:gitter.sdk.async:1.6.1'\n}\n```\n\nFor sync:\n```groovy\nrepositories {\n      jcenter()\n}\n\ndependencies {\n      compile 'com.github.amatkivskiy:gitter.sdk.sync:1.6.1'\n}\n```\n\n### \u003ca name=\"ReleaseNotes\"\u003e**Release notes**\n- **1.6.1** (04.01.2018)\n    - *Rx,Async,Sync:*\n        - Add `getRoomIdByUri` to room API\n\t- Update dependencies used in the SDK\n\t\n- **1.6.0** (12.01.2017)\n    - *RoomResponse:*\n        - Remove `favouriteOrder`\n        - Add `avatarUrl`\n        - Add `groupId`\n        - Add `public`\n        - Add `activity`\n        - Add `premium`\n\n    - *UserResponse:*\n        - Add `avatarUrl`\n        - Add `role`\n        - Add `staff`\n\n    - *Rx,Async,Sync:*\n        - Add `delete` room API\n        - Remove channels API\n        - Fix `joinRoom` API\n        - Add `getRoomById` API\n        - Add `getBannedusers` API\n        - Add `banUser` API\n        - Add `unBanUser` API\n        - Add Welcome API support\n\n    - *Faye*\n        - Update OkHttp to version 3.5.0\n- **1.5.1** (07.05.2016)\n    - Updated `RoomRepsonse` data structure.\n    - Added `aroundId` and `q` params for chat messages request.\n    - Added `Update room` request.\n    - Fixed `Issue` data structure type.\n    - Faye: added ability to set custom OkHttpClient.\n    - Faye: changed `onSubscribed()` params, no it passes messages snapshots.\n- **1.5** (14.01.2016)\n    - Added faye api support.\n    - Added room events streaming api support.\n- **1.4**\n    - Refactored library structure\n    - Added async api support.\n    - Added async api samples.\n    - Added sync api support.\n    - Added sync api samples.\n- **1.2.1**\n    - Added ability to retrieve unread messages.\n- **1.2.0**\n    - Added ability to search users\n    - Added ability to search rooms\n    - Added ability to leave room\n- **1.1.0**\n    - Added room messages streaming API.\n\n### \u003ca name=\"Features\"\u003e**Features**\n\n- Authentication\n\n*Rooms resource*\n- List rooms\n- Room users\n- Channels\n- Join a room\n- Remove user from the room\n- Leave room\n- Search rooms\n\n*User resource*\n- Current user\n- User rooms\n- User orgs\n- User repos\n- User channels\n- Search users\n\n*Messages resource*\n- Unread items\n- List messages\n- Send a message\n- Update a message\n\n*:heavy_exclamation_mark: Streaming (Avalible only in Rx part.*)\n- Room messages stream\n- Room events stream\n\n*:heavy_exclamation_mark: Faye API (Avalible only in Async part.*)\n- Room messages events\n- Room user presence events\n- Room user managment events\n\n### \u003ca name=\"Description\"\u003e**Description**\n\n**Authentication**\nPlease read [Authentication](https://developer.gitter.im/docs/authentication) article on **Gitter Developer**  before.\n\n## How to authenticate user with SDK\n\n1) Setup **GitterDeveloperCredentials** with info from [here](https://developer.gitter.im/apps):\n```java\nGitterDeveloperCredentials.init(new SimpleGitterCredentialsProvider(your_oauth_key, your_oauth_secret, your_redirect_url));\n```\n2) Get Gitter request access URL:\n```java\nString gitterAccessUrl = GitterOauthUtils.buildOauthUrl();\n```\n3) Open this url in something like embedded browser and listen for redirects.\n4) When user grants access gitter redirects back with url like:\n```\nhttp://some.redirect.url?code=deadbeef\n```\nextract ```code``` parameter value.\n\n5)  Exchange code for access token:\n - Rx:\n```java\nRxGitterAuthenticationClient authenticationClient = new RxGitterAuthenticationClient.Builder().build();\n\nauthenticationClient.getAccessToken(code).subscribe(new Action1\u003cAccessTokenResponse\u003e() {\n      @Override\n      public void call(AccessTokenResponse accessTokenResponse) {\n        System.out.println(\"Access token = \" + accessTokenResponse.accessToken);\n      }\n    });\n```\n\n- Async:\n```java\nAsyncGitterAuthenticationClient authenticationClient = new AsyncGitterAuthenticationClient.Builder()\n        .build();\n\nauthenticationClient.getAccessToken(code, new Callback\u003cAccessTokenResponse\u003e() {\n\t\n\t\t@Override\n        public void success(AccessTokenResponse tokenResponse, Response response) {\n\t\tSystem.out.println(\"Access token = \" + accessTokenResponse.accessToken);\n        }\n\n        @Override\n        public void failure(RetrofitError error) {}\n});\n```\n\n- Sync:\n```java\nSyncGitterAuthenticationClient authenticationClient = new SyncGitterAuthenticationClient.Builder()\n        .build();\n\nAccessTokenResponse accessTokenResponse = authenticationClient.getAccessToken(code);\nSystem.out.println(\"Access token = \" + accessTokenResponse.accessToken);\n\n```\n6) Save and use this ```accessToken``` to make requests to the REST API.\n\n## How to get data from Gitter REST API\n1)  Create ```GitterApiClient``` with help of ```GitterApiClient.Builder```:\n- Rx:\n```java\nRxGitterApiClient client = new RxGitterApiClient.Builder()\n        .withAccountToken(\"user_access_token\")\n        .build();\n```\n- Async:\n```\nAsyncGitterApiClient client = new AsyncGitterApiClient.Builder()\n        .withAccountToken(\"user_access_token\")\n        .build();\n```\n\n- Sync:\n```\nSyncGitterApiClient client = new SyncGitterApiClient.Builder()\n        .withAccountToken(\"user_access_token\")\n        .build();\n```\n\nalso you can provide some Retrofit config for requests (same for Rx and Async):\n```java\nRxGitterApiClient client = new RxGitterApiClient.Builder()\n        .withAccountToken(\"user_access_token\")\n        .withClient(new OkClient())\n        .withExecutors(httpExecutor, callbackExecutor)\n        .withLogLevel(RestAdapter.LogLevel.BASIC)\n        .build();\n```\n2) Execute any request that you need:\n- Rx:\n```java\nclient.getCurrentUser().subscribe(new Action1\u003cUserResponse\u003e() {\n      @Override\n      public void call(UserResponse user) {\n        System.out.println(\"user.displayName = \" + user.displayName);\n      }\n    });\n```\n- Async:\n```java\nclient.getCurrentUser(new Callback\u003cUserResponse\u003e() {\n      @Override\n      public void success(UserResponse userResponse, Response response) {\n        System.out.println(\"userResponse.displayName = \" + userResponse.displayName);\n      }\n\n      @Override\n      public void failure(RetrofitError error) {\n        System.err.println(\"error = \" + error);\n      }\n    });\n```\n\n- Sync:\n```java\nUserResponse userResponse = client.getCurrentUser();\nSystem.out.println(\"userResponse.displayName = \" + userResponse.displayName);\n```\n\nor\n- Rx:\n```java\nChatMessagesRequestParams params = new ChatMessagesRequestParamsBuilder().limit(20).build();\nString roomId = \"room_id\";\n\nclient.getRoomMessages(roomId, params).subscribe(new Action1\u003cList\u003cMessageResponse\u003e\u003e() {\n      @Override\n      public void call(List\u003cMessageResponse\u003e messages) {\n        System.out.println(\"Received \" + messages.size() + \" messages\");\n      }\n    });\n```\n- Async:\n```java\nChatMessagesRequestParams params = new ChatMessagesRequestParamsBuilder().limit(20).build();\nString roomId = \"room_id\";\n\nclient.getRoomMessages(roomId, params, new Callback\u003cList\u003cMessageResponse\u003e\u003e() {\n      @Override\n      public void success(List\u003cMessageResponse\u003e messages, Response response) {\n        System.out.println(\"Received \" + messages.size() + \" messages\");\n      }\n\n      @Override\n      public void failure(RetrofitError error) {}\n    });\n```\n\n- Sync:\n```java\nChatMessagesRequestParams params = new ChatMessagesRequestParamsBuilder().limit(20).build();\nString roomId = \"room_id\";\n\nList\u003cMessageResponse\u003e messages = client.getRoomMessages(roomId, params);\nSystem.out.println(\"Received \" + messages.size() + \" messages\");\n```\n\nor\n- Rx:\n```java\nclient.getUserChannels(\"user_id\").subscribe(new Action1\u003cList\u003cRoomResponse\u003e\u003e() {\n      @Override\n      public void call(List\u003cRoomResponse\u003e rooms) {\n        System.out.println(\"Received \" + rooms.size() + \" rooms\");\n      }\n    });\n```\n- Async:\n```java\nclient.getUserChannels(\"user_id\", new Callback\u003cList\u003cRoomResponse\u003e\u003e() {\n      @Override\n      public void success(List\u003cRoomResponse\u003e rooms, Response response) {\n        System.out.println(\"Received \" + rooms.size() + \" rooms\");\n      }\n\n      @Override\n      public void failure(RetrofitError error) {}\n    });\n```\n- Sync:\n```java\nList\u003cRoomResponse\u003e rooms = client.getUserChannels(\"user_id\");\nSystem.out.println(\"Received \" + rooms.size() + \" rooms\");\n```\n\n### \u003ca name=\"Streaming\"\u003e**How to get streaming data from Gitter Streaming API**\n\n### :heavy_exclamation_mark: Please don't set any log level for *RxGitterStreamingApiClient* as it blocks the stream.\n:heavy_exclamation_mark: If you get `java.net.SocketTimeoutException: Read timed out` try to encrease `ReadTimeout` in your `retrofit.client.Client` and spicify this client for `GutterApiClient` (`withClient()`).\n\n```java\nRxGitterStreamingApiClient client = new RxGitterStreamingApiClient.Builder()\n        .withAccountToken(\"user_access_token\")\n        .build();\n\nString roomId = \"room_id\";\n\nclient.getRoomMessagesStream(roomId).subscribe(new Action1\u003cMessageResponse\u003e() {\n\t@Override\n\tpublic void call(MessageResponse messageResponse) {\n\t\tSystem.out.println(\"messageResponse = \" + messageResponse);\n\t}\n});\n```\n\nor \n\n```java\nRxGitterStreamingApiClient client = new RxGitterStreamingApiClient.Builder()\n        .withAccountToken(\"user_access_token\")\n        .build();\n\nString roomId = \"room_id\";\n\nclient.getRoomEventsStream(roomId).subscribe(new Action1\u003cRoomEvent\u003e() {\n\t@Override\n\tpublic void call(RoomEvent event) {\n\t\tSystem.out.println(event.sent);\n\t        System.out.println(event.meta);\n\t}\n});\n```\n\n### \u003ca name=\"Faye\"\u003e**How to work with Gitter Faye API**\n\n1 Setup ```AsyncGitterFayeClient```:\n\n```java\nAsyncGitterFayeClient client = new AsyncGitterFayeClientBuilder()\n        .withAccountToken(\"account_token\")\n        .withOnDisconnected(new DisconnectionListener() {\n          @Override\n          public void onDisconnected() {\n            // Client has disconnected. You can reconnect it here.\n          }\n        })\n        .withOkHttpClient(new OkHttpClient())\n        .build();\n```\n\n2 Connect it to the server:\n\n```java\nclient.connect(new ConnectionListener() {\n      @Override\n      public void onConnected() {\n        // Client is ready. Subscribe to channels you are intereseted in.\n      }\n    });\n```\n\n3 Subscribe to desighed channel:\n\n```java\nclient.subscribe(new RoomMessagesChannel(\"room_id\") {\n          @Override\n          public void onMessage(String channel, MessageEvent message) {\n            // Yeah, you've got message here.\n          }\n});\n```\n\nor \n\n```java\nclient.subscribe(new RoomUserPresenceChannel(\"room_id\") {\n          @Override\n          public void onMessage(String channel, UserPresenceEvent message) {\n            // User is active or not.\n          }\n});\n```\n\nor \n\n```java\nclient.subscribe(new RoomUsersChannel(\"room_id\") {\n          @Override\n          public void onMessage(String channel, UserEvent message) {\n            // User left ot joined the room.\n          }\n});\n```\n\nor define your custom channel: \n\n```java\nclient.subscribe(\"channel_name\",new ChannelListener(){\n@Override\npublic void onMessage(String channel,JsonObject message){\n//        Handle message here.\n    }\n\n@Override\npublic void onFailed(String channel,Exception ex){\n    }\n\n@Override\npublic void onSubscribed(String channel, List\u003cMessageResponse\u003e messagesSnapshot){\n    }\n\n@Override\npublic void onUnSubscribed(String channel){\n    }\n    });\n```\n\nYou can unsubscribe from channel: \n\n\n```java\nclient.unSubscribe(\"channel_name\");\n```\n\nor \n\n```java\nRoomMessagesChannel channel = new RoomMessagesChannel(\"room_id\") {\n        @Override\n        public void onMessage(String channel, MessageEvent message) {\n        }\n};\nclient.subscribe(channel);\n\nclient.unSubscribe(channel);\n```\n\nFinally when your are finished with client, you need to call:\n\n```java\nclient.disconnect();\n```\n\nThats all =).\n\n### \u003ca name=\"Samples\"\u003e**Samples**\n\nYou can see some code samples [here](https://github.com/Gitteroid/GitterJavaSDK/tree/master/samples/src/main/java/com/amatkivskiy/gitter/sdk/samples)\n\n### Feel free to ask any questions.\n\n## LICENSE\n\n```\nThe MIT License (MIT)\n\nCopyright (c) 2017 \n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGitteroid%2FGitterJavaSDK","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGitteroid%2FGitterJavaSDK","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGitteroid%2FGitterJavaSDK/lists"}