|
| 1 | +package openrtb |
| 2 | + |
| 3 | +// The "device" object provides information pertaining to the device including its hardware, |
| 4 | +// platform, location, and carrier. This device can refer to a mobile handset, a desktop computer, |
| 5 | +// set top box or other digital device. |
| 6 | +type Device struct { |
| 7 | + Dnt *int // "1": Do not track |
| 8 | + Ua *string // User agent |
| 9 | + Ip *string // IPv4 |
| 10 | + Geo *Geo |
| 11 | + Didsha1 *string // SHA1 hashed device ID |
| 12 | + Didmd5 *string // MD5 hashed device ID |
| 13 | + Dpidsha1 *string // SHA1 hashed platform device ID |
| 14 | + Dpidmd5 *string // MD5 hashed platform device ID |
| 15 | + Ipv6 *string // IPv6 |
| 16 | + Carrier *string // Carrier or ISP derived from the IP address |
| 17 | + Language *string // Browser language |
| 18 | + Make *string // Device make |
| 19 | + Model *string // Device model |
| 20 | + Os *string // Device OS |
| 21 | + Osv *string // Device OS version |
| 22 | + Js *int // Javascript status ("0": Disabled, "1": Enabled) |
| 23 | + Connectiontype *int |
| 24 | + Devicetype *int |
| 25 | + Flashver *string // Flash version |
| 26 | + Ext map[string]string |
| 27 | +} |
| 28 | + |
| 29 | +// Returns the DNT status, with default fallback |
| 30 | +func (d *Device) IsDnt() bool { |
| 31 | + if d.Dnt != nil { |
| 32 | + return *d.Dnt == 1 |
| 33 | + } |
| 34 | + return false |
| 35 | +} |
| 36 | + |
| 37 | +// Returns the JS status, with default fallback |
| 38 | +func (d *Device) IsJs() bool { |
| 39 | + if d.Js != nil { |
| 40 | + return *d.Js == 1 |
| 41 | + } |
| 42 | + return false |
| 43 | +} |
| 44 | + |
| 45 | +// Returns the connection type, with default fallback |
| 46 | +func (d *Device) ConnectionType() int { |
| 47 | + if d.Connectiontype != nil { |
| 48 | + return *d.Connectiontype |
| 49 | + } |
| 50 | + return CONN_TYPE_UNKNOWN |
| 51 | +} |
| 52 | + |
| 53 | +// Returns the connection type, with default fallback |
| 54 | +func (d *Device) DeviceType() int { |
| 55 | + if d.Devicetype != nil { |
| 56 | + return *d.Devicetype |
| 57 | + } |
| 58 | + return DEVICE_TYPE_UNKNOWN |
| 59 | +} |
| 60 | + |
| 61 | +// Applies defaults |
| 62 | +func (d *Device) WithDefaults() *Device { |
| 63 | + if d.Dnt == nil { |
| 64 | + d.Dnt = new(int) |
| 65 | + *d.Dnt = 0 |
| 66 | + } |
| 67 | + if d.Js == nil { |
| 68 | + d.Js = new(int) |
| 69 | + *d.Js = 0 |
| 70 | + } |
| 71 | + if d.Connectiontype == nil { |
| 72 | + d.Connectiontype = new(int) |
| 73 | + *d.Connectiontype = CONN_TYPE_UNKNOWN |
| 74 | + } |
| 75 | + if d.Devicetype == nil { |
| 76 | + d.Devicetype = new(int) |
| 77 | + *d.Devicetype = DEVICE_TYPE_UNKNOWN |
| 78 | + } |
| 79 | + return d |
| 80 | +} |
0 commit comments