gilt / urbanairship4s

Urban Airship API for Scala

GitHub

urbanairship4s

Urban Airship API for Scala

Installation

For the core library:

libraryDependencies += "com.gilt.urbanairship4s" %% "core" % "0.1.0"

For the http4s client implementation:

libraryDependencies += "com.gilt.urbanairship4s" %% "http4s-client" % "0.1.0"

Usage

Create a client with

import com.gilt.urbanairship._
import com.gilt.urbanairship.http4s.PushClient

// http4sClient is a `org.http4s.client.Client[F]`
val uaClient = PushClient.withClient(http4sClient, "applicationKey", "masterSecret")

To create a push object:

  1. Create a selector. Selectors select who to send the message to. See com.gilt.urbanairship.AudienceSelector for available options.
  2. Create a message or notification. If you send a message, the notification is optional.
  3. Select the device types to which the message should be sent. See com.gilt.urbanairship.DeviceTypes for available options.
  4. Optionally, select push options (e.g. expiry time).
import com.gilt.urbanairship._

// Select a single device
val selector =
  AudienceSelector.DeviceSelector(
    DeviceType.IOS,
    UUID.fromString("00000000-0000-0000-0000-000000000000"))

val content =
  MessageContent(
    title = "Hello",
    body = "Hello world",
    expiry = Expiry.ExpireAfter(3600.seconds)
  )

val notification =
  Notification(
    "Hello",
    actions = Actions(
      open = Some(Action.Open(OpenType.OpenUrl("https://www.example.com/"))))
  )

PushObject(
      selector,
      Message(content, Some(notification)),
      DeviceTypes.withDevices(DeviceType.IOS)
    )

To send a push object, use:

val resultsOrErrors = uaClient.send(List(testPushObject))