Advertisement
Guest User

Sample Class

a guest
Jun 6th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. package im.actor.server.sms
  2.  
  3. import java.net.URLEncoder
  4.  
  5. import akka.actor.ActorSystem
  6. import akka.http.scaladsl.Http
  7. import akka.http.scaladsl.model._
  8. import com.typesafe.config.Config
  9. import akka.stream.Materializer
  10.  
  11. import scala.concurrent.Future
  12.  
  13. final class MyOwnClient(config: Config)(implicit system: ActorSystem, materializer: Materializer) extends SmsEngine {
  14.  
  15. val defaultSmsTemplate: String = "Your MIM Activation code is : "
  16.  
  17. private val url = "http://xxx.com/magfaHttpService"
  18. private val service = config.getString("service")
  19. private val domain = config.getString("domain")
  20. private val username = config.getString("username")
  21. private val password = config.getString("password")
  22. private val from = config.getString("from")
  23.  
  24. override def send(phoneNumber: Long, message: String): Future[Unit] = {
  25.  
  26. val http = Http()
  27.  
  28. val req = url + "?service=" + service + "&domain=" + domain + "&username=" + username +
  29. "&password=" + password + "&from=" + from + "&to=" + phoneNumber.toString +
  30. "&message=" + URLEncoder.encode(defaultSmsTemplate + message, "ISO-8859-1")
  31.  
  32. val f = http.singleRequest(HttpRequest(uri = req)) map {
  33. case HttpResponse(StatusCodes.OK, _, _, _) ⇒ ()
  34. case resp ⇒
  35. throw new Exception(s"Wrong response: $resp")
  36. }
  37.  
  38. f onFailure {
  39. case e ⇒
  40. system.log.error(e, "Failed to send sms through Magfa")
  41. }
  42. f
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement