ducky/devices

Paddy 2015-11-12

1:600326d50e74 Go to Latest

ducky/devices/device_type.go

Move DeviceType to its own file, add helper and constants. Make a device_type.go file, to avoid a mess in the devices.go file. Move the DeviceType definition over to the new file. Also, while we're here, set up a few of the contstants we know we'll need. These are the DeviceTypes we intend to support, such as Android phones, Android tablets, and Chrome extensions. Also, set up a helper method that will determine whether a DeviceType is "valid", i.e. if we have a constant defined for it. DeviceTypes, in general, are mostly intended to be used (at the moment, at least) to customise how we display devices to users. Basically, they allow us to display an at least semi-accurate depiction of the device.

History
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/device_type.go	Thu Nov 12 22:17:15 2015 -0800
     1.3 @@ -0,0 +1,32 @@
     1.4 +package devices
     1.5 +
     1.6 +const (
     1.7 +	// TypeAndroidTablet is used to designate a Device as an
     1.8 +	// Android tablet, usually for display purposes.
     1.9 +	TypeAndroidTablet = DeviceType("android_tablet")
    1.10 +	// TypeAndroidPhone is used to designate a Device as an
    1.11 +	// Android phone, usually for display purposes.
    1.12 +	TypeAndroidPhone = DeviceType("android_phone")
    1.13 +	// TypeChromeExtension is used to designate a device as a
    1.14 +	// Chrome extension, usually for display purposes.
    1.15 +	TypeChromeExtension = DeviceType("chrome_extension")
    1.16 +)
    1.17 +
    1.18 +// DeviceType is an enum specifying which type of Device it is. Usually,
    1.19 +// this is something like `android_phone` or `android_tablet`.
    1.20 +type DeviceType string
    1.21 +
    1.22 +// IsValidDeviceType validates the DeviceType against a list of
    1.23 +// DeviceTypes that have been whitelisted as "valid".
    1.24 +func IsValidDeviceType(d DeviceType) bool {
    1.25 +	switch d {
    1.26 +	case TypeAndroidTablet:
    1.27 +		return true
    1.28 +	case TypeAndroidPhone:
    1.29 +		return true
    1.30 +	case TypeChromeExtension:
    1.31 +		return true
    1.32 +	default:
    1.33 +		return false
    1.34 +	}
    1.35 +}