c8y_client 0.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 54

A library for Dart developers.

Created from templates made available by Stagehand under a Apache License Version 2.0 license.

Usage #

import 'package:c8yClient/src/core/model/id.dart';

A simple usage example: Get all devices with Position as Streaming

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';
import 'package:c8y_client/src/core/model/device_capabilities/c8y_position.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
    var inventoryApi = client.inventory();
    var iterator = await inventoryApi.stream({'fragmentType': 'c8y_Position'});
      while (await iterator.moveNext()) {
        var position = C8YPosition.fromJson(
            iterator.current.fragments['c8y_Position'] as Map<String, Object>);
        print(position.lat);
      }
  }
  catch (error) {
    print("error : " + error.toString());
  }
}

Get list of all devices with Position:

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
    var inventoryApi = client.inventory();
    var devices = await inventoryApi.listAll({'fragmentType': 'c8y_Position'});
    print('total devices : ' + devices.length.toString());
  }
  catch (error) {
    print("error : " + error.toString());
  }

}

Get list of devices with limit (40):

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
    var inventoryApi = client.inventory();
    var devices = await inventoryApi.listByLimit({'fragmentType': 'c8y_Position'}, 40);
    print('total devices : ' + devices.length.toString());
  }
  catch (error) {
    print("error : " + error.toString());
  }
}

A simple usage example: Get device by ID and a get dynamic property

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
     var inventoryApi = client.inventory();
     var mo = await inventoryApi.get(ID('10407719'));
    print(mo.name);
    print(mo.fragment['Numero_de_Satelites']);
  }
  catch (error) {
    print("error : " + error.toString());
  }
}

A simple usage example: Get all alarms as Streaming

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
      var alarmApi = client.alarm();
      var alarmsIterator = await alarmApi.stream({});
      while (await alarmsIterator.moveNext()) {
        print(alarmsIterator.current.text);
      }
  }
  catch (error) {
    print("error : " + error.toString());
  }
}

Get list of all alarms:

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
      var alarms = await alarmApi.listAll({});
      print('total alarms listall : ' + alarms.length.toString());
  }
  catch (error) {
    print("error : " + error.toString());
  }

}

Get list of alarms with limit (40):

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
      var alarmApi = client.alarm();
     var alarmsByLimit = await alarmApi.listByLimit({}, 40);
     print('total alarms list with limit : ' + alarmsByLimit.length.toString());
  }
  catch (error) {
    print("error : " + error.toString());
  }
}

A simple usage example: Get current user

import 'package:c8yClient/c8y_client.dart';
import 'package:c8yClient/src/sdk/client/client.dart';
import 'package:c8yClient/src/core/authentication/cumulocity_credentials.dart';

main() async {
  var client = Client.withPageSize('https://tenant.serviceProvider.com',
      CumulocityCredentials('user', 'password'), 100);
  try {
    var currentUser = await client.user().currentUser();
    print(currentUser.userName);
  }
  catch (error) {
    print("error : " + error.toString());
  }
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.0.1 #

  • Initial version support for user currentuser and inventory get all/one device.
  • Examples of use in the Readme file.

##0.0.2

-Added support for stream query devices -Added support for stream query alarms -Added support for current user

##0.0.3

-Expose models for developers use

##0.0.4

-Expose models for developers use

example/c8y_client_example.dart

import 'package:c8y_client/c8y_client.dart';
import 'package:c8y_client/src/core/authentication/cumulocity_credentials.dart';
import 'package:c8y_client/src/core/model/device_capabilities/c8y_position.dart';
import 'package:c8y_client/src/sdk/client/client.dart';

void main() async {

  var client = Client.withPageSize('https://tenant.service-provider.com',
      CumulocityCredentials('usrname', 'password'), 2000);


  var currentUser = await client.user().currentUser();
  print(currentUser.userName);

  var inventoryApi = client.inventory();
  var mo = await inventoryApi.get(ID('10407719'));
  print(mo.name);
  print(mo.fragments['Numero_de_Satelites']);


  var iterator = await inventoryApi.stream({'fragmentType': 'c8y_Position'});
  var counter = 0;
  while (await iterator.moveNext()) {
    var position = C8YPosition.fromJson(
        iterator.current.fragments['c8y_Position'] as Map<String, Object>);
    print(position.lat);
    counter++;
  }
  print('total devices stream : ' + counter.toString());

  var devices = await inventoryApi.listAll({'fragmentType': 'c8y_Position'});
  print('total devices listAll : ' + devices.length.toString());

  var devicesByLimit =
      await inventoryApi.listByLimit({'fragmentType': 'c8y_Position'}, 40);
  print('total devices list with limit : ' + devicesByLimit.length.toString());

  var alarmApi = client.alarm();
  counter = 0;
  var alarmsIterator = await alarmApi.stream({});
  while (await alarmsIterator.moveNext()) {
  print(alarmsIterator.current.text);
    counter++;
  }
  print('total alarms stream : ' + counter.toString());


  var alarms = await alarmApi.listAll({});
  print('total alarms listall : ' + alarms.length.toString());

  var alarmsByLimit = await alarmApi.listByLimit({}, 40);
  print('total alarms list with limit : ' + alarmsByLimit.length.toString());
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  c8y_client: ^0.0.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:c8y_client/c8y_client.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
20
Health:
Code health derived from static analysis. [more]
90
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
85
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Jul 10, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Health issues and suggestions

Document public APIs. (-0.53 points)

123 out of 125 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/inventory/model/mi_managed_object.dart. (-5.36 points)

Analysis of lib/src/inventory/model/mi_managed_object.dart reported 11 hints, including:

line 31 col 10: The value of the field '_childDevices' isn't used.

line 32 col 10: The value of the field '_childAssets' isn't used.

line 33 col 10: The value of the field '_childAdditions' isn't used.

line 34 col 7: The value of the field '_additionParents' isn't used.

line 35 col 7: The value of the field '_assetParents' isn't used.

Fix lib/src/alarms/model/alarm_representation.dart. (-1 points)

Analysis of lib/src/alarms/model/alarm_representation.dart reported 2 hints:

line 12 col 12: The value of the field '_creationTime' isn't used.

line 13 col 12: The value of the field '_firstOccurrenceTime' isn't used.

Fix lib/src/core/model/source.dart. (-1 points)

Analysis of lib/src/core/model/source.dart reported 2 hints:

line 6 col 10: The value of the field '_self' isn't used.

line 7 col 10: The value of the field '_name' isn't used.

Fix additional 32 files with analysis or formatting issues. (-2 points)

Additional issues in the following files:

  • lib/src/sdk/client/plataform_parameters.dart (2 hints)
  • lib/src/sdk/client/client.dart (1 hint)
  • lib/src/sdk/client/httpclient.dart (1 hint)
  • lib/c8y_client.dart (Run dartfmt to format lib/c8y_client.dart.)
  • lib/src/alarms/implementations/alarm.dart (Run dartfmt to format lib/src/alarms/implementations/alarm.dart.)
  • lib/src/alarms/model/alarm_api.dart (Run dartfmt to format lib/src/alarms/model/alarm_api.dart.)
  • lib/src/alarms/model/alarm_collection.dart (Run dartfmt to format lib/src/alarms/model/alarm_collection.dart.)
  • lib/src/alarms/model/alarm_collection_represenation.dart (Run dartfmt to format lib/src/alarms/model/alarm_collection_represenation.dart.)
  • lib/src/alarms/model/alarm_media_type.dart (Run dartfmt to format lib/src/alarms/model/alarm_media_type.dart.)
  • lib/src/core/authentication/cumulocity_credentials.dart (Run dartfmt to format lib/src/core/authentication/cumulocity_credentials.dart.)
  • lib/src/core/authentication/cumulocity_login.dart (Run dartfmt to format lib/src/core/authentication/cumulocity_login.dart.)
  • lib/src/core/implementations/paged_collection_iterable.dart (Run dartfmt to format lib/src/core/implementations/paged_collection_iterable.dart.)
  • lib/src/core/model/base_resource_representation.dart (Run dartfmt to format lib/src/core/model/base_resource_representation.dart.)
  • lib/src/core/model/document.dart (Run dartfmt to format lib/src/core/model/document.dart.)
  • lib/src/core/model/paged_collection_representation.dart (Run dartfmt to format lib/src/core/model/paged_collection_representation.dart.)
  • lib/src/core/model/paged_collection_resource.dart (Run dartfmt to format lib/src/core/model/paged_collection_resource.dart.)
  • lib/src/core/model/resource_representation.dart (Run dartfmt to format lib/src/core/model/resource_representation.dart.)
  • lib/src/core/util/date.dart (Run dartfmt to format lib/src/core/util/date.dart.)
  • lib/src/core/util/url_processor.dart (Run dartfmt to format lib/src/core/util/url_processor.dart.)
  • lib/src/inventory/implementations/managed_object_collection_impl.dart (Run dartfmt to format lib/src/inventory/implementations/managed_object_collection_impl.dart.)
  • lib/src/inventory/implementations/managed_object_reference_collection_representation.dart (Run dartfmt to format lib/src/inventory/implementations/managed_object_reference_collection_representation.dart.)
  • lib/src/inventory/implementations/paged_managed_object_collection_representation.dart (Run dartfmt to format lib/src/inventory/implementations/paged_managed_object_collection_representation.dart.)
  • lib/src/inventory/model/inventory_api.dart (Run dartfmt to format lib/src/inventory/model/inventory_api.dart.)
  • lib/src/inventory/model/managed_object_collection_representation.dart (Run dartfmt to format lib/src/inventory/model/managed_object_collection_representation.dart.)
  • lib/src/inventory/model/managed_object_reference_representation.dart (Run dartfmt to format lib/src/inventory/model/managed_object_reference_representation.dart.)
  • lib/src/inventory/model/managed_object_representation.dart (Run dartfmt to format lib/src/inventory/model/managed_object_representation.dart.)
  • lib/src/sdk/client/platform.dart (Run dartfmt to format lib/src/sdk/client/platform.dart.)
  • lib/src/sdk/client/sdk_exception.dart (Run dartfmt to format lib/src/sdk/client/sdk_exception.dart.)
  • lib/src/user/implementation/user.dart (Run dartfmt to format lib/src/user/implementation/user.dart.)
  • lib/src/user/model/current_user_representation.dart (Run dartfmt to format lib/src/user/model/current_user_representation.dart.)
  • lib/src/user/model/user_api_representation.dart (Run dartfmt to format lib/src/user/model/user_api_representation.dart.)
  • lib/src/user/model/user_representation.dart (Run dartfmt to format lib/src/user/model/user_representation.dart.)

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Homepage URL is insecure. (-5 points)

Update the homepage field and use a secure (https) URL.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
http ^0.12.0+4 0.12.1
http_parser ^3.1.4 3.1.4
json_annotation ^3.0.1 3.0.1
logger ^0.9.1 0.9.1
Transitive dependencies
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
meta 1.2.2 1.3.0-nullsafety
path 1.7.0
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0 1.3.0-nullsafety
Dev dependencies
build_runner ^1.8.1
json_serializable ^3.3.0
pedantic ^1.8.0 1.9.2
test ^1.6.0