Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions device/device_detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ type Device struct {
}

type deviceInfo struct {
UserAgent struct {
Name string `json:"name"`
Major string `json:"major"`
Minor string `json:"minor"`
Patch string `json:"patch"`
BotName string `json:"bot_name"`
IsBot bool `json:"is_bot"`
IsDownloader bool `json:"is_downloader"`
IsFeedreader bool `json:"is_feedreader"`
Identified bool `json:"identified"`
} `json:"user_agent"`

Device struct {
Name string `json:"name"`
Brand string `json:"brand"`
Expand Down Expand Up @@ -140,3 +152,48 @@ func (d *Device) IsDesktop() bool {
func (d *Device) IsTouchscreen() bool {
return d.info.Device.IsTouchscreen
}

// UserAgentName returns the name of the user agent
func (d *Device) UserAgentName() string {
return d.info.UserAgent.Name
}

// UserAgentMajor returns the major version of the user agent
func (d *Device) UserAgentMajor() string {
return d.info.UserAgent.Major
}

// UserAgentMinor returns the minor version of the user agent
func (d *Device) UserAgentMinor() string {
return d.info.UserAgent.Minor
}

// UserAgentPatch returns the patch level version of the user agent
func (d *Device) UserAgentPatch() string {
return d.info.UserAgent.Patch
}

// UserAgentBotName returns the bot name (if the user agent is a bot)
func (d *Device) UserAgentBotName() string {
return d.info.UserAgent.BotName
}

// UserAgentIsBot returns true if the client device is a bot
func (d *Device) UserAgentIsBot() bool {
return d.info.UserAgent.IsBot
}

// UserAgentIsDownloader returns true if the client device is a downloader
func (d *Device) IsDownloader() bool {
return d.info.UserAgent.IsDownloader
}

// UserAgentIsFeedreader returns true if the client device is a feed reader
func (d *Device) IsFeedreader() bool {
return d.info.UserAgent.IsFeedreader
}

// UserAgentIdentified returns true if the client device was successfully identified
func (d *Device) Identified() bool {
return d.info.UserAgent.Identified
}