getTargetUrl static method

String getTargetUrl({
  1. required String bridgeIpAddr,
  2. ResourceType? resourceType,
  3. String? pathToResource,
  4. bool isRemote = false,
})

Returns a properly formatted target URL.

bridgeIpAddr is the IP address of the target bridge.

The resourceType is used to let the bridge know what type of resource is being queried.

If a specific resource is being queried, include pathToResource. This is most likely the resource's ID.

If isRemote is true, the URL will be formatted for remote access.

Implementation

static String getTargetUrl({
  required String bridgeIpAddr,
  ResourceType? resourceType,
  String? pathToResource,
  bool isRemote = false,
}) {
  String domain = isRemote ? "api.meethue.com/route" : bridgeIpAddr;

  String resourceTypeStr = resourceType?.value ?? "";

  if (resourceTypeStr.isNotEmpty) {
    resourceTypeStr = "/$resourceTypeStr";
  }

  String subPath = pathToResource ?? "";

  if (subPath.isNotEmpty && !subPath.startsWith("/")) {
    subPath = "/$subPath";
  }

  return "https://$domain/clip/v2/resource$resourceTypeStr$subPath";
}