/// <summary> /// Registers a new device. /// </summary> /// <param name="applicationId"></param> /// <param name="uuid"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <RegisterDeviceResult> RegisterDeviceAsync(int applicationId, string uuid, CancellationToken cancellationToken = new CancellationToken()) { //Get the application ResinApplication application = await GetApplicationAsync(applicationId, cancellationToken); if (application == null) { throw new ObjectNotFoundException($"Application with id {applicationId} was not found."); } //Get the user ResinUser user = await GetUserAsync(cancellationToken); //Create the data for the request var data = new { user = user.Id, application = application.Id, device_type = application.DeviceType, uuid }; //Get the api key string apiKey = await GetProvisioningKeyAsync(applicationId, cancellationToken); //Do it //var token = await PostAsync($"device/register?apikey={apiKey}", data, cancellationToken); Uri uri = new Uri($"https://api.resin.io/device/register?apikey={apiKey}"); ////Do it var token = await PostAsync(uri, data, cancellationToken); //Woot - we're done return(token.ToDataObjectDirect <RegisterDeviceResult>(this)); }
public ApplicationViewModel(ResinApplication model, ITextEditService textEditService, ResinApiClient client, IViewService viewService) { if (model == null) { throw new ArgumentNullException(nameof(model)); } _textEditService = textEditService ?? throw new ArgumentNullException(nameof(model)); _client = client ?? throw new ArgumentNullException(nameof(client)); _viewService = viewService ?? throw new ArgumentNullException(nameof(viewService)); _model = model; EditVariablesCommand = new RelayCommand(EditVariables); }