github.com/prebid/prebid-server/v2@v2.18.0/adapters/silverpush/devicetype.go (about)

     1  package silverpush
     2  
     3  import (
     4  	"regexp"
     5  	"strings"
     6  
     7  	"github.com/prebid/openrtb/v20/openrtb2"
     8  )
     9  
    10  var isValidMobile = regexp.MustCompile(`(ios|ipod|ipad|iphone|android)`)
    11  var isCtv = regexp.MustCompile(`(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)`)
    12  var isIos = regexp.MustCompile(`(iPhone|iPod|iPad)`)
    13  
    14  func isMobile(ua string) bool {
    15  	return isValidMobile.MatchString(strings.ToLower(ua))
    16  }
    17  
    18  func isCTV(ua string) bool {
    19  	return isCtv.MatchString(strings.ToLower(ua))
    20  }
    21  
    22  // isValidEids checks for valid eids.
    23  func isValidEids(eids []openrtb2.EID) bool {
    24  	for i := 0; i < len(eids); i++ {
    25  		if len(eids[i].UIDs) > 0 && eids[i].UIDs[0].ID != "" {
    26  			return true
    27  		}
    28  	}
    29  	return false
    30  }
    31  
    32  func getOS(ua string) string {
    33  	if strings.Contains(ua, "Windows") {
    34  		return "Windows"
    35  	} else if isIos.MatchString(ua) {
    36  		return "iOS"
    37  	} else if strings.Contains(ua, "Mac OS X") {
    38  		return "macOS"
    39  	} else if strings.Contains(ua, "Android") {
    40  		return "Android"
    41  	} else if strings.Contains(ua, "Linux") {
    42  		return "Linux"
    43  	} else {
    44  		return "Unknown"
    45  	}
    46  }