Kotlin quick start

Getting started with MySocialApp is very easy. However, if you have any questions get in touch.

Get your free app

To use your own application follow this startup guide , otherwise you can use our testing app made available to start very quickly.

Testing app

app id: u470584465854a728453
URL: https://u470584465854a728453-api.mysocialapp.io

❗️

Beware of using the testing app

Do not share sensitive information on this instance. In addition, the data is likely to be erased very regularly.

Install the library

Gradle / Maven repository

In your build.gradle or pom.xml script for your application module, add the library repository:

repositories {
    ...
  maven { url 'https://jitpack.io' }
}
<dependency>
  <groupId>com.github.MySocialApp</groupId>
    <artifactId>mysocialapp-java-client</artifactId>
  <version>v0.9.0</version>
</dependency>

Gradle / Maven library

The mysocialapp-java-client library (working with Kotlin) is also available in JitPack repository. Add a dependency element as a child of dependencies with the following in build.gradle or pom.xml:

dependencies {
  implementation 'com.github.MySocialApp:mysocialapp-java-client:v0.17.0'
}
<dependency>
  <groupId>com.github.MySocialApp</groupId>
    <artifactId>mysocialapp-java-client</artifactId>
  <version>v0.17.0</version>
</dependency>

Code examples

Create an account

// Your app or testing app ID
val myAppId = "u470584465854a728453"
val msa = MySocialApp.Builder().setAppId(myAppId).build()

// create user and get session
val session = msa.blockingCreateAccount("[email protected]", "mySecretPassw0rd", "John")

// get account info
val account = session.account.blockingGet()

println("My Account ID is " + account.id);
println("And it was created at " + account.createdDate);
// Your app or testing app ID
val myAppId = "u470584465854a728453"
val msa = MySocialApp.Builder().setAppId(myAppId).build()

// or the reactive way using RxKotlin
msa.createAccount("[email protected]", "mySecretPassw0rd", "John") // create user and get session
        .flatMap(mSession -> mSession.account.get()) //  get account info
                .subscribe({ mAccount ->
            println("My Account ID is " + mAccount.id);
            println("And it was created at " + mAccount.createdDate);
        },{
          // on Failure
        })

See more about configuring the Kotlin library

👍

Gift for testing users

Use your real e-mail address to receive a gift when you register :) In addition, you will see that you can integrate your application with any online service (eg: Mailchimp, Amazon AWS, Google Cloud, Zapier .. ) to react to events (new user, new comment, new photo, new post..) on your app.

Listen for notification events

s.notification.addNotificationListener(object : NotificationCallback {

  override fun onNewsFeed(feed: Feed) {
    // called when my friends or someone that I matter published a new content
  }
  
  override fun onComment(comment: Comment) {
    // called when someone comments on a post that belongs to me or on which I have interacted
  }

  override fun onLike(like: Like) {
    // called when someone likes on a post that belongs to me or on which I have interacted
  }

  override fun onMention(feed: Feed) {
    // called when someone mention me on a post
  }

  override fun onMention(comment: Comment) {
    // called when someone mention me on a comment
  }

  override fun onConversationMessage(conversationMessage: ConversationMessage) {
    // called when someone chat with me in private
  }

  override fun onEvent(event: Event) {
    // called when a new event near to me has been created
  }
  
  // There is much more downstream notifications
})

See more about configuring notification events here

Create post (News Feed / Activity Stream)

A feed post can contain text, image, hashtags, web links, mentions of users. Web links are rewritten and tracked. Publications can be public or visible only from his contacts.

// message with user mention + hash tag
val message = "Hello, my name is [[user:${myAccount.id}]] this is a post with an image and #hashtag :)"

// build message
val post = FeedPost.Builder()
  .setMessage(message) // add text message
  .setImage(File("/tmp/my_image.jpg")) // add image
  .setVisibility(AccessControl.PUBLIC) // set post visible from all
  .build()

// publish post on public feed
val feed = session.newsFeed.blockingSendWallPost(post)
// message with user mention + hash tag
val message = "Hello, my name is [[user:${myAccount.id}]] this is a post with an image and #hashtag :)"

// build message
FeedPost post = FeedPost.Builder()
  .setMessage(message) // add text message
  .setImage(new File("/tmp/my_image.jpg")) // add image
  .setVisibility(AccessControl.PUBLIC) // set post visible from all
  .build()

// publish post on public feed
session.newsFeed.sendWallPost(post).subscribe({ feed ->
  // on Success
}, {
  // on Failure
})

Posts can be published on the public, user, group, event news feed. Dynamic type of feed can be added. (e.g: Product news feed)

Add comment to Post

Each post can receive comments (+ likes) and allow interactions between users. Notifications are sent to warn participants. As well as the feed post, comment can contain text, image, hashtags, web links, mentions of users.

// build comment
val comment = CommentPost.Builder()
  .setMessage("Here a comment") // add comment message
  .setImage(File("/tmp/my_image.jpg")) // add comment image
  .build()

// comment the post
feed.blockingAddComment(comment)
// build comment
val comment = CommentPost.Builder()
  .setMessage("Here a comment") // add comment message
  .setImage(File("/tmp/my_image.jpg")) // add comment image
  .build()

// comment the post
feed.addComment(comment).subscribe({ comment ->
  // on Success
}, {
  // on Failure
})

Create event

Invite users to participate in an event. E.g: notify the users of the final of the World Cup on Sunday, at 9:00pm. You can add a description as well as custom fields to fit your needs.

// Luzhniki Stadium / Moscow
val luzhnikiStadiumLocation = new SimpleLocation(55.709330496, 37.552164458)

// Match start date+time
val start = Calendar.instance
start.set(2018, Calendar.JULY, 15, 21, 0)

// Match end date+time
val end = Calendar.instance
end.set(2018, Calendar.JULY, 15, 22, 30)

// Build event
val event = Event.Builder()
  .setName("Soccer World Cup 2018")
  .setDescription("Last soccer world cup match. Go !")
  .setStartDate(start.time)
  .setEndDate(end.time)
  .setLocation(luzhnikiStadiumLocation)
  .setMaxSeats(10000)
  .setMemberAccessControl(EventMemberAccessControl.PUBLIC)
  .setCoverImage(File("/tmp/worldcup.jpg"))
  .setCustomFields(soccerCustomFields) // your custom fields
  .build()

// Create event
session.event.blockingCreate(event)
// Luzhniki Stadium / Moscow
val luzhnikiStadiumLocation = new SimpleLocation(55.709330496, 37.552164458)

// Match start date+time
val start = Calendar.instance
start.set(2018, Calendar.JULY, 15, 21, 0)

// Match end date+time
val end = Calendar.instance
end.set(2018, Calendar.JULY, 15, 22, 30)

// Build event
val event = Event.Builder()
  .setName("Soccer World Cup 2018")
  .setDescription("Last soccer world cup match. Go !")
  .setStartDate(start.time)
  .setEndDate(end.time)
  .setLocation(luzhnikiStadiumLocation)
  .setMaxSeats(10000)
  .setMemberAccessControl(EventMemberAccessControl.PUBLIC)
  .setCoverImage(File("/tmp/worldcup.jpg"))
  .setCustomFields(soccerCustomFields) // your custom fields
  .build()

// Create event
session.event.create(event).subscribe({ event ->
  // on Success
}, {
  // on Failure
})

Possibilities are endless. Check out our readme Kotlin github page for more examples.