public SmartThingsClient(string accessToken) { var configuration = new Configuration(); configuration.AccessToken = accessToken ?? throw new ArgumentNullException(accessToken); _accessToken = accessToken; _devicesApi = new DevicesApi(configuration); _locationsApi = new LocationsApi(configuration); _roomsApi = new RoomsApi(configuration); _scenesApi = new ScenesApi(configuration); _rulesApi = new RulesApi(configuration); _schedulesApi = new SchedulesApi(configuration); _appsApi = new AppsApi(configuration); _subscriptionsApi = new SubscriptionsApi(configuration); _installedAppsApi = new InstalledappsApi(configuration); _deviceProfilesApi = new ProfilesApi(configuration); _capabilitiesApi = new CapabilitiesApi(configuration); _presentationApi = new PresentationsApi(configuration); //_accessToken = accessToken; //_devicesApi = new DevicesApi(); //_locationsApi = new LocationsApi(); //_roomsApi = new RoomsApi(); //_scenesApi = new ScenesApi(); //_rulesApi = new RulesApi(); //_schedulesApi = new SchedulesApi(); //_appsApi = new AppsApi(); //_subscriptionsApi = new SubscriptionsApi(); //_installedAppsApi = new InstalledappsApi(); //_deviceProfilesApi = new ProfilesApi(); //_capabilitiesApi = new CapabilitiesApi(); //_presentationApi = new PresentationsApi(); }
protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { _allDevices = null; _allLocations = null; _allRooms = null; _allScenes = null; _allRules = null; _allSchedules = null; _allApps = null; _allSubscriptions = null; _allInstalledApps = null; _allDeviceProfiles = null; _devicesApi = null; _locationsApi = null; _roomsApi = null; _scenesApi = null; _rulesApi = null; _schedulesApi = null; _appsApi = null; _subscriptionsApi = null; _installedAppsApi = null; _deviceProfilesApi = null; } _disposedValue = true; } }
/// <summary> /// List a device's resources with subscriptions /// </summary> /// <param name="deviceId">DeviceId</param> /// <returns>List of device subscriptions</returns> /// <example> /// <code> /// try /// { /// var subscriptions = connectApi.ListDeviceSubscriptions("015bb66a92a30000000000010010006d"); /// foreach (var resource in subscriptions) /// { /// Console.WriteLine(resource); /// } /// return subscriptions; /// } /// catch (CloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <exception cref="CloudApiException">CloudApiException</exception> public IEnumerable <string> ListDeviceSubscriptions(string deviceId) { string subscriptionsString; try { subscriptionsString = SubscriptionsApi.GetEndpointSubscriptions(deviceId); } catch (mds.Client.ApiException e) { if (e.ErrorCode == 404) { return(new string[] { }); } throw new CloudApiException(e.ErrorCode, e.Message, e.ErrorContent); } if (!string.IsNullOrEmpty(subscriptionsString)) { return(subscriptionsString.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries)); } return(new string[] { }); }
/// <summary> /// Get a list of pre-subscription data. /// </summary> /// <returns>List of <see cref="Presubscription"/></returns> /// <example> /// <code> /// try /// { /// var presubscriptions = connectApi.ListPresubscriptions(); /// foreach (var item in presubscriptions) /// { /// Console.WriteLine(item); /// } /// return presubscriptions; /// } /// catch (MbedCloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <exception cref="CloudApiException">CloudApiException</exception> public Presubscription[] ListPresubscriptions() { try { return(SubscriptionsApi.GetPreSubscriptions()?.Select(p => Presubscription.Map(p))?.ToArray()); } catch (mds.Client.ApiException ex) { throw new CloudApiException(ex.ErrorCode, ex.Message, ex.ErrorContent); } }
/// <summary> /// Delete the presubscriptions /// </summary> /// <example> /// <code> /// try /// { /// connectApi.DeletePresubscriptions(); /// } /// catch (MbedCloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <exception cref="CloudApiException">CloudApiException</exception> public void DeletePresubscriptions() { try { SubscriptionsApi.DeletePreSubscriptions(); } catch (mds.Client.ApiException ex) { throw new mds.Client.ApiException(ex.ErrorCode, ex.Message, ex.ErrorContent); } }
private void SetUpApi(Config config, statistics.Client.Configuration statsConfig = null, mds.Client.Configuration mdsConfig = null, Configuration deviceConfig = null) { const string dateFormat = "yyyy-MM-dd'T'HH:mm:ss.fffZ"; var auth = $"{config.AuthorizationPrefix} {config.ApiKey}"; if (statsConfig == null) { statsConfig = new statistics.Client.Configuration { BasePath = config.Host, DateTimeFormat = dateFormat, UserAgent = UserAgent, }; statsConfig.AddApiKey("Authorization", config.ApiKey); statsConfig.AddApiKeyPrefix("Authorization", config.AuthorizationPrefix); statsConfig.CreateApiClient(); } if (mdsConfig == null) { mdsConfig = new mds.Client.Configuration { BasePath = config.Host, DateTimeFormat = dateFormat, UserAgent = UserAgent, }; mdsConfig.AddApiKey("Authorization", config.ApiKey); mdsConfig.AddApiKeyPrefix("Authorization", config.AuthorizationPrefix); mdsConfig.CreateApiClient(); } if (deviceConfig == null) { deviceConfig = new device_directory.Client.Configuration { BasePath = config.Host, DateTimeFormat = dateFormat, UserAgent = UserAgent, }; deviceConfig.AddApiKey("Authorization", config.ApiKey); deviceConfig.AddApiKeyPrefix("Authorization", config.AuthorizationPrefix); deviceConfig.CreateApiClient(); } DeviceDirectoryApi = new device_directory.Api.DefaultApi(deviceConfig); StatisticsApi = new statistics.Api.StatisticsApi(statsConfig); SubscriptionsApi = new SubscriptionsApi(mdsConfig); ResourcesApi = new ResourcesApi(mdsConfig); EndpointsApi = new EndpointsApi(mdsConfig); AccountApi = new statistics.Api.AccountApi(statsConfig); NotificationsApi = new NotificationsApi(mdsConfig); DeviceRequestsApi = new DeviceRequestsApi(mdsConfig); }
/// <summary> /// Gets the status of a resource's subscription. True if ok, false if not. /// </summary> /// <param name="deviceId">Id of device.</param> /// <param name="resourcePath">Resource path.</param> /// <returns>True if subscribed, false if not.</returns> /// <example> /// <code> /// var status = connectApi.GetResourceSubscription("015bb66a92a30000000000010010006d", "3200/0/5500"); /// </code> /// </example> public bool GetResourceSubscription(string deviceId, string resourcePath) { try { var fixedPath = RemoveLeadingSlash(resourcePath); SubscriptionsApi.CheckResourceSubscription(deviceId, fixedPath); return(true); } catch (mds.Client.ApiException) { return(false); } }
/** * Constructor to take in API credentials and create the backend API client * Also initializes the specific API clients for each object that will be used * * user: The Zuora API username * pass: The Zuora API password */ public ApplicationManager(String user, String pass) { //Creating the API client with the new REST endpoint zApi = new ApiClient("https://rest.apisandbox.zuora.com/v1"); //Adding the username and password to the header for subsequent API calls zApi.AddDefaultHeader("apiAccessKeyId", user); zApi.AddDefaultHeader("apiSecretAccessKey", pass); //Initializing API clients for Product Catalog, Accounts, and Subscriptions catalogApi = new CatalogApi(zApi); accountsApi = new AccountsApi(zApi); subscriptionsApi = new SubscriptionsApi(zApi); }
/// <summary> /// Unsubscribe from device and/or resource_path updates. /// </summary> /// <param name="deviceId">device to unsubscribe events from.</param> /// <param name="resourcePath">resource_path to unsubscribe events from.</param> /// <example> /// <code> /// try /// { /// connectApi.DeleteResourceSubscription("015bb66a92a30000000000010010006d", "3200/0/5500"); /// } /// catch (CloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <exception cref="CloudApiException">CloudApiException</exception> public void DeleteResourceSubscription(string deviceId, string resourcePath) { try { var fixedPath = RemoveLeadingSlash(resourcePath); SubscriptionsApi.DeleteResourceSubscription(deviceId, fixedPath); var subscribePath = deviceId + resourcePath; ResourceSubscribtions.TryRemove(subscribePath, out var removedItem); } catch (mds.Client.ApiException ex) { throw new CloudApiException(ex.ErrorCode, ex.Message, ex.ErrorContent); } }
/// <summary> /// Removes a device's subscriptions /// </summary> /// <param name="deviceId">Device Id</param> /// <example> /// <code> /// try /// { /// connectApi.DeleteDeviceSubscriptions("015bb66a92a30000000000010010006d"); /// } /// catch (CloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <exception cref="CloudApiException">CloudApiException</exception> public void DeleteDeviceSubscriptions(string deviceId) { try { SubscriptionsApi.DeleteEndpointSubscriptions(deviceId); ResourceSubscribtions.Keys .Where(k => k.Contains(deviceId)) .ToList() .ForEach(d => ResourceSubscribtions.TryRemove(d, out var removedItem)); } catch (mds.Client.ApiException e) when(e.ErrorCode != 404) { throw new CloudApiException(e.ErrorCode, e.Message, e.ErrorContent); } }
public SmartThingsClient(string accessToken) { var configuration = new Configuration(); configuration.AccessToken = accessToken ?? throw new ArgumentNullException(accessToken); //configuration.BasePath = "https://graph-eu01-euwest1.api.smartthings.com/v1"; _devicesApi = new DevicesApi(configuration); _locationsApi = new LocationsApi(configuration); _roomsApi = new RoomsApi(configuration); _scenesApi = new ScenesApi(configuration); _rulesApi = new RulesApi(configuration); _schedulesApi = new SchedulesApi(configuration); _appsApi = new AppsApi(configuration); _subscriptionsApi = new SubscriptionsApi(configuration); _installedAppsApi = new InstalledAppsApi(configuration); _deviceProfilesApi = new DeviceProfilesApi(configuration); }
/// <summary> /// Update pre-subscription data. Pre-subscription data will be removed for empty list. /// </summary> /// <param name="presubscriptions">Array of <see cref="Presubscription"/></param> /// <example> /// <code> /// try /// { /// var presubscription = new Presubscription /// { /// DeviceId = "015bb66a92a30000000000010010006d", /// ResourcePaths = new List { "/5001/0/1" }, /// }; /// connectApi.UpdatePresubscriptions(new Presubscription[] { presubscription }); /// /// foreach (var item in api.ListPresubscriptions()) /// { /// Console.WriteLine(item); /// } /// } /// catch (MbedCloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <exception cref="CloudApiException">CloudApiException</exception> public void UpdatePresubscriptions(Presubscription[] presubscriptions) { var presubscriptionArray = new mds.Model.PresubscriptionArray(); foreach (var presubscription in presubscriptions) { var updatedPresubscription = new mds.Model.Presubscription(presubscription.DeviceId, presubscription.DeviceType, presubscription.ResourcePaths.ToList()); presubscriptionArray.Add(updatedPresubscription); } try { SubscriptionsApi.UpdatePreSubscriptions(presubscriptionArray); } catch (mds.Client.ApiException ex) { throw new mds.Client.ApiException(ex.ErrorCode, ex.Message, ex.ErrorContent); } }
/// <summary> /// Subscribe to resource updates. /// </summary> /// <param name="deviceId">Id of device.</param> /// <param name="resourcePath">Resource path.</param> /// <returns>Async Consumer with String</returns> /// <example> /// <code> /// var consumer = await api.AddResourceSubscriptionAsync("015bb66a92a30000000000010010006d", "3200/0/5500"); /// var counter = 0; /// while (true) /// { /// var t = consumer.GetValue(); /// Console.WriteLine(t.Result); /// counter++; /// if (counter >= 2) /// { /// break; /// } /// } /// </code> /// </example> /// <exception cref="CloudApiException">CloudApiException</exception> public async Task <Resource> AddResourceSubscriptionAsync(string deviceId, string resourcePath) { Log.Info($"adding subscription for {deviceId} at path {resourcePath}"); try { await StartNotificationsAsync(); var fixedPath = RemoveLeadingSlash(resourcePath); await SubscriptionsApi.AddResourceSubscriptionAsync(deviceId, fixedPath); var subscribePath = deviceId + resourcePath; var resource = new Resource(deviceId, this); ResourceSubscribtions.AddOrUpdate(subscribePath, resource, (key, _) => resource); return(resource); } catch (mds.Client.ApiException ex) { throw new CloudApiException(ex.ErrorCode, ex.Message, ex.ErrorContent); } }
public void Init() { instance = new SubscriptionsApi(); }