All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gravity.gdk.reco.RecoContext.scala Maven / Gradle / Ivy

The newest version!
package com.gravity.gdk.reco

import javax.servlet.http.HttpServletRequest

import com.gravity.gdk.impression.PageViewGuid
import com.gravity.gdk.user.GravityUser
import com.gravity.gdk.util.http._

/*
              ___...---''
  ___...---'\'___
''       _.-''  _`'.______\\.
        /_.)  )..-  __..--'\\
       (    __..--''
        '-''\@


 Ⓐ Ⓐ Ⓐ Ⓐ Ⓐ Ⓐ Ⓐ Ⓐ Ⓐ Ⓐ Ⓐ
*/

/**
  * @param currentUrl URL being served by your server. This is used as the basis for "contextual" recommendations;
  *                   that is, recommendations may be weighted based on the contents of this URL for some contextual
  *                   relevance to what this URL topically represents.
  * @param imageWidth If provided, images provided in resultant [[RecoArticle]] image URLs will be sized accordingly.
  * @param imageHeight If provided, images provided in resultant [[RecoArticle]] image URLs will be sized accordingly.
  * @param pageViewGuid If you are rendering multiple distinct placements on a single Web page in the browser, you
  *                     should pass this param using a single memoized [[com.gravity.gdk.impression.PageViewGuid.random]];
  *                     this will allow the various placements' impressions for the given page view to be joined to
  *                     each other for deduping across placements in the same page, additional downstream analysis, etc.
  */
case class RecoContext(user: GravityUser, currentUrl: String, imageWidth: Int = 0, imageHeight: Int = 0,
  pageViewGuid: PageViewGuid = PageViewGuid.random)

object RecoContext {
  /** Make a RecoContext from the current request your server is handling. */
  def fromRequest(implicit request: HttpServletRequest): RecoContext = {
    RecoContext(
      GravityUser.fromRequest(request),
      request.getRequestURLWithQueryString
    )
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy