<commit_before>package lila.push

import lila.user.User

import play.api.libs.json._
import play.api.libs.ws.{ WS, WSAuthScheme }
import play.api.Play.current

// https://aerogear.org/docs/specs/aerogear-unifiedpush-rest/index.html#397083935
private final class Aerogear(config: Aerogear.Config) {

  import Aerogear._

  def push(p: Push): Funit = WS.url(s"${config.url}/rest/sender")
    .withAuth(config.applicationId, config.masterSecret, WSAuthScheme.BASIC)
    .post(Json.obj(
      "message" -> p
    )).flatMap {
      case res if res.status == 200 => funit
      case res                      => fufail(s"[push] $p ${res.status} ${res.body}")
    }
}

private object Aerogear {

  case class Push(
    userId: String,
    alert: String,
    sound: String, // ???
    userData: JsObject)

  private implicit val pushWrites: OWrites[Push] = OWrites { p =>
    Json.obj(
      "alert" -> p.alert,
      "sound" -> p.sound,
      "user-data" -> p.userData
    )
  }

  case class Config(
    url: String,
    variantId: String,
    secret: String,
    applicationId: String,
    masterSecret: String)
}<commit_msg>push notification: set criteria and category<commit_after>package lila.push

import lila.user.User

import play.api.libs.json._
import play.api.libs.ws.{ WS, WSAuthScheme }
import play.api.Play.current

// https://aerogear.org/docs/specs/aerogear-unifiedpush-rest/index.html#397083935
private final class Aerogear(config: Aerogear.Config) {

  import Aerogear._

  def push(p: Push): Funit = WS.url(s"${config.url}/rest/sender")
    .withAuth(config.applicationId, config.masterSecret, WSAuthScheme.BASIC)
    .post(Json.obj(
      "message" -> p
    )).flatMap {
      case res if res.status == 200 => funit
      case res                      => fufail(s"[push] $p ${res.status} ${res.body}")
    }
}

private object Aerogear {

  case class Push(
    userId: String,
    alert: String,
    sound: String, // ???
    userData: JsObject)

  private implicit val pushWrites: OWrites[Push] = OWrites { p =>
    Json.obj(
      "alert" -> p.alert,
      "sound" -> p.sound,
      "criteria" -> Json.obj(
        "alias" -> List(p.userId),
        "categories" -> List("move")),
      "user-data" -> p.userData
    )
  }

  case class Config(
    url: String,
    variantId: String,
    secret: String,
    applicationId: String,
    masterSecret: String)
}
{'fraction_non_alphanumeric': 0.14201432785503582, 'fraction_numerical': 0.010113780025284451, 'mean_word_length': 2.7210031347962382, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4106792', 'n_tokens_mistral': 871, 'n_tokens_neox': 820, 'n_words': 181}