SocialHub is a multi social network service's API library written in Java, and can be complied to Objective-C by J2ObjC. and we can also use it with Kotlin and Swift too.
List of Social Media (SNS)
- Twitter ( use library based on twitter4j )
- Slack ( use library based on jslack )
- Mastodon ( use library based on mastodon4j )
- Tumblr ( use library based on jumblr )
- Misskey ( use library )
Most of all libraries are modified (remove complex dependency and unused functions) for compilation to Objective-C with J2ObjC.
Work in Progress
Difficult to Handle
- Discord API does not provide the way to write message api as user to channel.
Code sample to authorize account and get account information.
/* JAVA */ // 1. Make Authorized Account Object // For Twitter TwitterAuth auth = SocialHub.getTwitterAuth(CONSUMER_KEY, CONSUMER_SECRET); Account account = auth.getAccountWithAccessToken(ACCESS_TOKEN, ACCESS_SECRET); // For Mastodon MastodonAuth auth = SocialHub.getMastodonAuth(HOST); Account account = auth.getAccountWithAccessToken(ACCESS_TOKEN); // 2. Request To SNS (all sns same interface) User user = account.action().getUserMe(); System.out.println(user.getName());
Code sample to get unified timeline comments from account group (two or more accounts).
/* JAVA */ // 1. Make Account Group AccountGroup accounts = new AccountGroup(); accounts.addAccount((Account)twitterAccount); accounts.addAccount((Account)mastodonAccount); // 2. Get Home New Timeline CommentGroup comments = accounts.action().getHomeTimeLine(); // 3. Get Past Timeline CommentGroup pasts = comments.action().getPastComments();
if you want more samples, please see detail documents and test code.
J2ObjC is project aim to compile Java code to Objective-C code. SocialHub is adapted with J2ObjC compilation So, you can use SocialHub as an Objective-C library (also use in Swift) in MacOS or iOS application development. Travis CI compiles SocialHub and make SocialHub CocoaPods Repository. It's an easy way to use this repository rather than compiling yourself.
Compile to Objective-C
To compile SocialHub to Objective-C framework, do next instructions. It's only executable on MacOS environment (This file is script of followings.)
Download latest J2ObjC builds and unzip
Set J2ObjC path in
Build Objective-C libraries
Build commands is written in
j2objc.shfile. so execute it or do next instructions.
j2objc.gradleis gradle settings to make Objective-C library.
./gradlew -b j2objc.gradle clean :j2objcAssemble -x test
Add dependency in your project
After J2ObjC compile,
cocoapod.specwill be created in
./build/j2objcOutputsfolder, so you write SocialHub dependency in your CocoaPods project's
def j2objc_socialhub pod 'j2objc-SocialHub-debug', :configuration => ['Debug'], :path => '../shared/build/j2objcOutputs' pod 'j2objc-SocialHub-release', :configuration => ['Release'], :path => '../shared/build/j2objcOutputs' end ... NOTE: this line must be added manually for the relevant targets: j2objc_socialhub ...
Use SocialHub in Swift
Make bridging header, and write as following.
- iOS: SocialHub
- This library is converted to Objective-C and used in Swift.