1package digitaltwins 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// Client is the a service for managing and querying digital twins and digital twin models. 19type Client struct { 20 BaseClient 21} 22 23// NewClient creates an instance of the Client client. 24func NewClient() Client { 25 return NewClientWithBaseURI(DefaultBaseURI) 26} 27 28// NewClientWithBaseURI creates an instance of the Client client using a custom endpoint. Use this when interacting 29// with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewClientWithBaseURI(baseURI string) Client { 31 return Client{NewWithBaseURI(baseURI)} 32} 33 34// Add adds or replaces a digital twin. 35// Status codes: 36// 200 (OK): Success. 37// 400 (Bad Request): The request is invalid. 38// 412 (Precondition Failed): The model is decommissioned or the digital twin already exists (when using If-None-Match: 39// *). 40// Parameters: 41// ID - the id of the digital twin. The id is unique within the service and case sensitive. 42// twin - the digital twin instance being added. If provided, the $dtId property is ignored. 43// ifNoneMatch - only perform the operation if the entity does not already exist. 44func (client Client) Add(ctx context.Context, ID string, twin interface{}, ifNoneMatch string) (result SetObject, err error) { 45 if tracing.IsEnabled() { 46 ctx = tracing.StartSpan(ctx, fqdn+"/Client.Add") 47 defer func() { 48 sc := -1 49 if result.Response.Response != nil { 50 sc = result.Response.Response.StatusCode 51 } 52 tracing.EndSpan(ctx, sc, err) 53 }() 54 } 55 req, err := client.AddPreparer(ctx, ID, twin, ifNoneMatch) 56 if err != nil { 57 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Add", nil, "Failure preparing request") 58 return 59 } 60 61 resp, err := client.AddSender(req) 62 if err != nil { 63 result.Response = autorest.Response{Response: resp} 64 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Add", resp, "Failure sending request") 65 return 66 } 67 68 result, err = client.AddResponder(resp) 69 if err != nil { 70 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Add", resp, "Failure responding to request") 71 return 72 } 73 74 return 75} 76 77// AddPreparer prepares the Add request. 78func (client Client) AddPreparer(ctx context.Context, ID string, twin interface{}, ifNoneMatch string) (*http.Request, error) { 79 pathParameters := map[string]interface{}{ 80 "id": autorest.Encode("path", ID), 81 } 82 83 const APIVersion = "2020-05-31-preview" 84 queryParameters := map[string]interface{}{ 85 "api-version": APIVersion, 86 } 87 88 preparer := autorest.CreatePreparer( 89 autorest.AsContentType("application/json; charset=utf-8"), 90 autorest.AsPut(), 91 autorest.WithBaseURL(client.BaseURI), 92 autorest.WithPathParameters("/digitaltwins/{id}", pathParameters), 93 autorest.WithJSON(twin), 94 autorest.WithQueryParameters(queryParameters)) 95 if len(string(ifNoneMatch)) > 0 { 96 preparer = autorest.DecoratePreparer(preparer, 97 autorest.WithHeader("If-None-Match", autorest.String(ifNoneMatch))) 98 } 99 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 100} 101 102// AddSender sends the Add request. The method will close the 103// http.Response Body if it receives an error. 104func (client Client) AddSender(req *http.Request) (*http.Response, error) { 105 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 106} 107 108// AddResponder handles the response to the Add request. The method always 109// closes the http.Response Body. 110func (client Client) AddResponder(resp *http.Response) (result SetObject, err error) { 111 err = autorest.Respond( 112 resp, 113 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 114 autorest.ByUnmarshallingJSON(&result.Value), 115 autorest.ByClosing()) 116 result.Response = autorest.Response{Response: resp} 117 return 118} 119 120// AddRelationship adds a relationship between two digital twins. 121// Status codes: 122// 200 (OK): Success. 123// 400 (Bad Request): The request is invalid. 124// 404 (Not Found): There is either no digital twin, target digital twin, or relationship with the provided id. 125// 409 (Conflict): A relationship with the provided id already exists. 126// Parameters: 127// ID - the id of the digital twin. The id is unique within the service and case sensitive. 128// relationshipID - the id of the relationship. The id is unique within the digital twin and case sensitive. 129// relationship - the data for the relationship. 130// ifNoneMatch - only perform the operation if the entity does not already exist. 131func (client Client) AddRelationship(ctx context.Context, ID string, relationshipID string, relationship *interface{}, ifNoneMatch string) (result SetObject, err error) { 132 if tracing.IsEnabled() { 133 ctx = tracing.StartSpan(ctx, fqdn+"/Client.AddRelationship") 134 defer func() { 135 sc := -1 136 if result.Response.Response != nil { 137 sc = result.Response.Response.StatusCode 138 } 139 tracing.EndSpan(ctx, sc, err) 140 }() 141 } 142 req, err := client.AddRelationshipPreparer(ctx, ID, relationshipID, relationship, ifNoneMatch) 143 if err != nil { 144 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "AddRelationship", nil, "Failure preparing request") 145 return 146 } 147 148 resp, err := client.AddRelationshipSender(req) 149 if err != nil { 150 result.Response = autorest.Response{Response: resp} 151 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "AddRelationship", resp, "Failure sending request") 152 return 153 } 154 155 result, err = client.AddRelationshipResponder(resp) 156 if err != nil { 157 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "AddRelationship", resp, "Failure responding to request") 158 return 159 } 160 161 return 162} 163 164// AddRelationshipPreparer prepares the AddRelationship request. 165func (client Client) AddRelationshipPreparer(ctx context.Context, ID string, relationshipID string, relationship *interface{}, ifNoneMatch string) (*http.Request, error) { 166 pathParameters := map[string]interface{}{ 167 "id": autorest.Encode("path", ID), 168 "relationshipId": autorest.Encode("path", relationshipID), 169 } 170 171 const APIVersion = "2020-05-31-preview" 172 queryParameters := map[string]interface{}{ 173 "api-version": APIVersion, 174 } 175 176 preparer := autorest.CreatePreparer( 177 autorest.AsContentType("application/json; charset=utf-8"), 178 autorest.AsPut(), 179 autorest.WithBaseURL(client.BaseURI), 180 autorest.WithPathParameters("/digitaltwins/{id}/relationships/{relationshipId}", pathParameters), 181 autorest.WithQueryParameters(queryParameters)) 182 if relationship != nil { 183 preparer = autorest.DecoratePreparer(preparer, 184 autorest.WithJSON(relationship)) 185 } 186 if len(string(ifNoneMatch)) > 0 { 187 preparer = autorest.DecoratePreparer(preparer, 188 autorest.WithHeader("If-None-Match", autorest.String(ifNoneMatch))) 189 } 190 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 191} 192 193// AddRelationshipSender sends the AddRelationship request. The method will close the 194// http.Response Body if it receives an error. 195func (client Client) AddRelationshipSender(req *http.Request) (*http.Response, error) { 196 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 197} 198 199// AddRelationshipResponder handles the response to the AddRelationship request. The method always 200// closes the http.Response Body. 201func (client Client) AddRelationshipResponder(resp *http.Response) (result SetObject, err error) { 202 err = autorest.Respond( 203 resp, 204 azure.WithErrorUnlessStatusCode(http.StatusOK), 205 autorest.ByUnmarshallingJSON(&result.Value), 206 autorest.ByClosing()) 207 result.Response = autorest.Response{Response: resp} 208 return 209} 210 211// Delete deletes a digital twin. All relationships referencing the digital twin must already be deleted. 212// Status codes: 213// 200 (OK): Success. 214// 400 (Bad Request): The request is invalid. 215// 404 (Not Found): There is no digital twin with the provided id. 216// Parameters: 217// ID - the id of the digital twin. The id is unique within the service and case sensitive. 218// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is 219// provided. 220func (client Client) Delete(ctx context.Context, ID string, ifMatch string) (result autorest.Response, err error) { 221 if tracing.IsEnabled() { 222 ctx = tracing.StartSpan(ctx, fqdn+"/Client.Delete") 223 defer func() { 224 sc := -1 225 if result.Response != nil { 226 sc = result.Response.StatusCode 227 } 228 tracing.EndSpan(ctx, sc, err) 229 }() 230 } 231 req, err := client.DeletePreparer(ctx, ID, ifMatch) 232 if err != nil { 233 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Delete", nil, "Failure preparing request") 234 return 235 } 236 237 resp, err := client.DeleteSender(req) 238 if err != nil { 239 result.Response = resp 240 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Delete", resp, "Failure sending request") 241 return 242 } 243 244 result, err = client.DeleteResponder(resp) 245 if err != nil { 246 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Delete", resp, "Failure responding to request") 247 return 248 } 249 250 return 251} 252 253// DeletePreparer prepares the Delete request. 254func (client Client) DeletePreparer(ctx context.Context, ID string, ifMatch string) (*http.Request, error) { 255 pathParameters := map[string]interface{}{ 256 "id": autorest.Encode("path", ID), 257 } 258 259 const APIVersion = "2020-05-31-preview" 260 queryParameters := map[string]interface{}{ 261 "api-version": APIVersion, 262 } 263 264 preparer := autorest.CreatePreparer( 265 autorest.AsDelete(), 266 autorest.WithBaseURL(client.BaseURI), 267 autorest.WithPathParameters("/digitaltwins/{id}", pathParameters), 268 autorest.WithQueryParameters(queryParameters)) 269 if len(ifMatch) > 0 { 270 preparer = autorest.DecoratePreparer(preparer, 271 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 272 } 273 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 274} 275 276// DeleteSender sends the Delete request. The method will close the 277// http.Response Body if it receives an error. 278func (client Client) DeleteSender(req *http.Request) (*http.Response, error) { 279 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 280} 281 282// DeleteResponder handles the response to the Delete request. The method always 283// closes the http.Response Body. 284func (client Client) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 285 err = autorest.Respond( 286 resp, 287 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 288 autorest.ByClosing()) 289 result.Response = resp 290 return 291} 292 293// DeleteRelationship deletes a relationship between two digital twins. 294// Status codes: 295// 200 (OK): Success. 296// 404 (Not Found): There is either no digital twin or relationship with the provided id. 297// Parameters: 298// ID - the id of the digital twin. The id is unique within the service and case sensitive. 299// relationshipID - the id of the relationship. The id is unique within the digital twin and case sensitive. 300// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is 301// provided. 302func (client Client) DeleteRelationship(ctx context.Context, ID string, relationshipID string, ifMatch string) (result autorest.Response, err error) { 303 if tracing.IsEnabled() { 304 ctx = tracing.StartSpan(ctx, fqdn+"/Client.DeleteRelationship") 305 defer func() { 306 sc := -1 307 if result.Response != nil { 308 sc = result.Response.StatusCode 309 } 310 tracing.EndSpan(ctx, sc, err) 311 }() 312 } 313 req, err := client.DeleteRelationshipPreparer(ctx, ID, relationshipID, ifMatch) 314 if err != nil { 315 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "DeleteRelationship", nil, "Failure preparing request") 316 return 317 } 318 319 resp, err := client.DeleteRelationshipSender(req) 320 if err != nil { 321 result.Response = resp 322 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "DeleteRelationship", resp, "Failure sending request") 323 return 324 } 325 326 result, err = client.DeleteRelationshipResponder(resp) 327 if err != nil { 328 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "DeleteRelationship", resp, "Failure responding to request") 329 return 330 } 331 332 return 333} 334 335// DeleteRelationshipPreparer prepares the DeleteRelationship request. 336func (client Client) DeleteRelationshipPreparer(ctx context.Context, ID string, relationshipID string, ifMatch string) (*http.Request, error) { 337 pathParameters := map[string]interface{}{ 338 "id": autorest.Encode("path", ID), 339 "relationshipId": autorest.Encode("path", relationshipID), 340 } 341 342 const APIVersion = "2020-05-31-preview" 343 queryParameters := map[string]interface{}{ 344 "api-version": APIVersion, 345 } 346 347 preparer := autorest.CreatePreparer( 348 autorest.AsDelete(), 349 autorest.WithBaseURL(client.BaseURI), 350 autorest.WithPathParameters("/digitaltwins/{id}/relationships/{relationshipId}", pathParameters), 351 autorest.WithQueryParameters(queryParameters)) 352 if len(ifMatch) > 0 { 353 preparer = autorest.DecoratePreparer(preparer, 354 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 355 } 356 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 357} 358 359// DeleteRelationshipSender sends the DeleteRelationship request. The method will close the 360// http.Response Body if it receives an error. 361func (client Client) DeleteRelationshipSender(req *http.Request) (*http.Response, error) { 362 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 363} 364 365// DeleteRelationshipResponder handles the response to the DeleteRelationship request. The method always 366// closes the http.Response Body. 367func (client Client) DeleteRelationshipResponder(resp *http.Response) (result autorest.Response, err error) { 368 err = autorest.Respond( 369 resp, 370 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 371 autorest.ByClosing()) 372 result.Response = resp 373 return 374} 375 376// GetByID retrieves a digital twin. 377// Status codes: 378// 200 (OK): Success. 379// 404 (Not Found): There is no digital twin with the provided id. 380// Parameters: 381// ID - the id of the digital twin. The id is unique within the service and case sensitive. 382func (client Client) GetByID(ctx context.Context, ID string) (result SetObject, err error) { 383 if tracing.IsEnabled() { 384 ctx = tracing.StartSpan(ctx, fqdn+"/Client.GetByID") 385 defer func() { 386 sc := -1 387 if result.Response.Response != nil { 388 sc = result.Response.Response.StatusCode 389 } 390 tracing.EndSpan(ctx, sc, err) 391 }() 392 } 393 req, err := client.GetByIDPreparer(ctx, ID) 394 if err != nil { 395 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "GetByID", nil, "Failure preparing request") 396 return 397 } 398 399 resp, err := client.GetByIDSender(req) 400 if err != nil { 401 result.Response = autorest.Response{Response: resp} 402 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "GetByID", resp, "Failure sending request") 403 return 404 } 405 406 result, err = client.GetByIDResponder(resp) 407 if err != nil { 408 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "GetByID", resp, "Failure responding to request") 409 return 410 } 411 412 return 413} 414 415// GetByIDPreparer prepares the GetByID request. 416func (client Client) GetByIDPreparer(ctx context.Context, ID string) (*http.Request, error) { 417 pathParameters := map[string]interface{}{ 418 "id": autorest.Encode("path", ID), 419 } 420 421 const APIVersion = "2020-05-31-preview" 422 queryParameters := map[string]interface{}{ 423 "api-version": APIVersion, 424 } 425 426 preparer := autorest.CreatePreparer( 427 autorest.AsGet(), 428 autorest.WithBaseURL(client.BaseURI), 429 autorest.WithPathParameters("/digitaltwins/{id}", pathParameters), 430 autorest.WithQueryParameters(queryParameters)) 431 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 432} 433 434// GetByIDSender sends the GetByID request. The method will close the 435// http.Response Body if it receives an error. 436func (client Client) GetByIDSender(req *http.Request) (*http.Response, error) { 437 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 438} 439 440// GetByIDResponder handles the response to the GetByID request. The method always 441// closes the http.Response Body. 442func (client Client) GetByIDResponder(resp *http.Response) (result SetObject, err error) { 443 err = autorest.Respond( 444 resp, 445 azure.WithErrorUnlessStatusCode(http.StatusOK), 446 autorest.ByUnmarshallingJSON(&result.Value), 447 autorest.ByClosing()) 448 result.Response = autorest.Response{Response: resp} 449 return 450} 451 452// GetComponent retrieves a component from a digital twin. 453// Status codes: 454// 200 (OK): Success. 455// 404 (Not Found): There is either no digital twin with the provided id or the component path is invalid. 456// Parameters: 457// ID - the id of the digital twin. The id is unique within the service and case sensitive. 458// componentPath - the name of the DTDL component. 459func (client Client) GetComponent(ctx context.Context, ID string, componentPath string) (result SetObject, err error) { 460 if tracing.IsEnabled() { 461 ctx = tracing.StartSpan(ctx, fqdn+"/Client.GetComponent") 462 defer func() { 463 sc := -1 464 if result.Response.Response != nil { 465 sc = result.Response.Response.StatusCode 466 } 467 tracing.EndSpan(ctx, sc, err) 468 }() 469 } 470 req, err := client.GetComponentPreparer(ctx, ID, componentPath) 471 if err != nil { 472 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "GetComponent", nil, "Failure preparing request") 473 return 474 } 475 476 resp, err := client.GetComponentSender(req) 477 if err != nil { 478 result.Response = autorest.Response{Response: resp} 479 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "GetComponent", resp, "Failure sending request") 480 return 481 } 482 483 result, err = client.GetComponentResponder(resp) 484 if err != nil { 485 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "GetComponent", resp, "Failure responding to request") 486 return 487 } 488 489 return 490} 491 492// GetComponentPreparer prepares the GetComponent request. 493func (client Client) GetComponentPreparer(ctx context.Context, ID string, componentPath string) (*http.Request, error) { 494 pathParameters := map[string]interface{}{ 495 "componentPath": autorest.Encode("path", componentPath), 496 "id": autorest.Encode("path", ID), 497 } 498 499 const APIVersion = "2020-05-31-preview" 500 queryParameters := map[string]interface{}{ 501 "api-version": APIVersion, 502 } 503 504 preparer := autorest.CreatePreparer( 505 autorest.AsGet(), 506 autorest.WithBaseURL(client.BaseURI), 507 autorest.WithPathParameters("/digitaltwins/{id}/components/{componentPath}", pathParameters), 508 autorest.WithQueryParameters(queryParameters)) 509 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 510} 511 512// GetComponentSender sends the GetComponent request. The method will close the 513// http.Response Body if it receives an error. 514func (client Client) GetComponentSender(req *http.Request) (*http.Response, error) { 515 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 516} 517 518// GetComponentResponder handles the response to the GetComponent request. The method always 519// closes the http.Response Body. 520func (client Client) GetComponentResponder(resp *http.Response) (result SetObject, err error) { 521 err = autorest.Respond( 522 resp, 523 azure.WithErrorUnlessStatusCode(http.StatusOK), 524 autorest.ByUnmarshallingJSON(&result.Value), 525 autorest.ByClosing()) 526 result.Response = autorest.Response{Response: resp} 527 return 528} 529 530// GetRelationshipByID retrieves a relationship between two digital twins. 531// Status codes: 532// 200 (OK): Success. 533// 404 (Not Found): There is either no digital twin or relationship with the provided id. 534// Parameters: 535// ID - the id of the digital twin. The id is unique within the service and case sensitive. 536// relationshipID - the id of the relationship. The id is unique within the digital twin and case sensitive. 537func (client Client) GetRelationshipByID(ctx context.Context, ID string, relationshipID string) (result SetObject, err error) { 538 if tracing.IsEnabled() { 539 ctx = tracing.StartSpan(ctx, fqdn+"/Client.GetRelationshipByID") 540 defer func() { 541 sc := -1 542 if result.Response.Response != nil { 543 sc = result.Response.Response.StatusCode 544 } 545 tracing.EndSpan(ctx, sc, err) 546 }() 547 } 548 req, err := client.GetRelationshipByIDPreparer(ctx, ID, relationshipID) 549 if err != nil { 550 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "GetRelationshipByID", nil, "Failure preparing request") 551 return 552 } 553 554 resp, err := client.GetRelationshipByIDSender(req) 555 if err != nil { 556 result.Response = autorest.Response{Response: resp} 557 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "GetRelationshipByID", resp, "Failure sending request") 558 return 559 } 560 561 result, err = client.GetRelationshipByIDResponder(resp) 562 if err != nil { 563 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "GetRelationshipByID", resp, "Failure responding to request") 564 return 565 } 566 567 return 568} 569 570// GetRelationshipByIDPreparer prepares the GetRelationshipByID request. 571func (client Client) GetRelationshipByIDPreparer(ctx context.Context, ID string, relationshipID string) (*http.Request, error) { 572 pathParameters := map[string]interface{}{ 573 "id": autorest.Encode("path", ID), 574 "relationshipId": autorest.Encode("path", relationshipID), 575 } 576 577 const APIVersion = "2020-05-31-preview" 578 queryParameters := map[string]interface{}{ 579 "api-version": APIVersion, 580 } 581 582 preparer := autorest.CreatePreparer( 583 autorest.AsGet(), 584 autorest.WithBaseURL(client.BaseURI), 585 autorest.WithPathParameters("/digitaltwins/{id}/relationships/{relationshipId}", pathParameters), 586 autorest.WithQueryParameters(queryParameters)) 587 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 588} 589 590// GetRelationshipByIDSender sends the GetRelationshipByID request. The method will close the 591// http.Response Body if it receives an error. 592func (client Client) GetRelationshipByIDSender(req *http.Request) (*http.Response, error) { 593 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 594} 595 596// GetRelationshipByIDResponder handles the response to the GetRelationshipByID request. The method always 597// closes the http.Response Body. 598func (client Client) GetRelationshipByIDResponder(resp *http.Response) (result SetObject, err error) { 599 err = autorest.Respond( 600 resp, 601 azure.WithErrorUnlessStatusCode(http.StatusOK), 602 autorest.ByUnmarshallingJSON(&result.Value), 603 autorest.ByClosing()) 604 result.Response = autorest.Response{Response: resp} 605 return 606} 607 608// ListIncomingRelationships retrieves all incoming relationship for a digital twin. 609// Status codes: 610// 200 (OK): Success. 611// 400 (Bad Request): The request is invalid. 612// 404 (Not Found): There is no digital twin with the provided id. 613// Parameters: 614// ID - the id of the digital twin. The id is unique within the service and case sensitive. 615func (client Client) ListIncomingRelationships(ctx context.Context, ID string) (result IncomingRelationshipCollectionPage, err error) { 616 if tracing.IsEnabled() { 617 ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListIncomingRelationships") 618 defer func() { 619 sc := -1 620 if result.irc.Response.Response != nil { 621 sc = result.irc.Response.Response.StatusCode 622 } 623 tracing.EndSpan(ctx, sc, err) 624 }() 625 } 626 result.fn = client.listIncomingRelationshipsNextResults 627 req, err := client.ListIncomingRelationshipsPreparer(ctx, ID) 628 if err != nil { 629 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "ListIncomingRelationships", nil, "Failure preparing request") 630 return 631 } 632 633 resp, err := client.ListIncomingRelationshipsSender(req) 634 if err != nil { 635 result.irc.Response = autorest.Response{Response: resp} 636 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "ListIncomingRelationships", resp, "Failure sending request") 637 return 638 } 639 640 result.irc, err = client.ListIncomingRelationshipsResponder(resp) 641 if err != nil { 642 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "ListIncomingRelationships", resp, "Failure responding to request") 643 return 644 } 645 if result.irc.hasNextLink() && result.irc.IsEmpty() { 646 err = result.NextWithContext(ctx) 647 return 648 } 649 650 return 651} 652 653// ListIncomingRelationshipsPreparer prepares the ListIncomingRelationships request. 654func (client Client) ListIncomingRelationshipsPreparer(ctx context.Context, ID string) (*http.Request, error) { 655 pathParameters := map[string]interface{}{ 656 "id": autorest.Encode("path", ID), 657 } 658 659 const APIVersion = "2020-05-31-preview" 660 queryParameters := map[string]interface{}{ 661 "api-version": APIVersion, 662 } 663 664 preparer := autorest.CreatePreparer( 665 autorest.AsGet(), 666 autorest.WithBaseURL(client.BaseURI), 667 autorest.WithPathParameters("/digitaltwins/{id}/incomingrelationships", pathParameters), 668 autorest.WithQueryParameters(queryParameters)) 669 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 670} 671 672// ListIncomingRelationshipsSender sends the ListIncomingRelationships request. The method will close the 673// http.Response Body if it receives an error. 674func (client Client) ListIncomingRelationshipsSender(req *http.Request) (*http.Response, error) { 675 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 676} 677 678// ListIncomingRelationshipsResponder handles the response to the ListIncomingRelationships request. The method always 679// closes the http.Response Body. 680func (client Client) ListIncomingRelationshipsResponder(resp *http.Response) (result IncomingRelationshipCollection, err error) { 681 err = autorest.Respond( 682 resp, 683 azure.WithErrorUnlessStatusCode(http.StatusOK), 684 autorest.ByUnmarshallingJSON(&result), 685 autorest.ByClosing()) 686 result.Response = autorest.Response{Response: resp} 687 return 688} 689 690// listIncomingRelationshipsNextResults retrieves the next set of results, if any. 691func (client Client) listIncomingRelationshipsNextResults(ctx context.Context, lastResults IncomingRelationshipCollection) (result IncomingRelationshipCollection, err error) { 692 req, err := lastResults.incomingRelationshipCollectionPreparer(ctx) 693 if err != nil { 694 return result, autorest.NewErrorWithError(err, "digitaltwins.Client", "listIncomingRelationshipsNextResults", nil, "Failure preparing next results request") 695 } 696 if req == nil { 697 return 698 } 699 resp, err := client.ListIncomingRelationshipsSender(req) 700 if err != nil { 701 result.Response = autorest.Response{Response: resp} 702 return result, autorest.NewErrorWithError(err, "digitaltwins.Client", "listIncomingRelationshipsNextResults", resp, "Failure sending next results request") 703 } 704 result, err = client.ListIncomingRelationshipsResponder(resp) 705 if err != nil { 706 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "listIncomingRelationshipsNextResults", resp, "Failure responding to next results request") 707 } 708 return 709} 710 711// ListIncomingRelationshipsComplete enumerates all values, automatically crossing page boundaries as required. 712func (client Client) ListIncomingRelationshipsComplete(ctx context.Context, ID string) (result IncomingRelationshipCollectionIterator, err error) { 713 if tracing.IsEnabled() { 714 ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListIncomingRelationships") 715 defer func() { 716 sc := -1 717 if result.Response().Response.Response != nil { 718 sc = result.page.Response().Response.Response.StatusCode 719 } 720 tracing.EndSpan(ctx, sc, err) 721 }() 722 } 723 result.page, err = client.ListIncomingRelationships(ctx, ID) 724 return 725} 726 727// ListRelationships retrieves the relationships from a digital twin. 728// Status codes: 729// 200 (OK): Success. 730// 400 (Bad Request): The request is invalid. 731// 404 (Not Found): There is no digital twin with the provided id. 732// Parameters: 733// ID - the id of the digital twin. The id is unique within the service and case sensitive. 734// relationshipName - the name of the relationship. 735func (client Client) ListRelationships(ctx context.Context, ID string, relationshipName string) (result RelationshipCollectionPage, err error) { 736 if tracing.IsEnabled() { 737 ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListRelationships") 738 defer func() { 739 sc := -1 740 if result.rc.Response.Response != nil { 741 sc = result.rc.Response.Response.StatusCode 742 } 743 tracing.EndSpan(ctx, sc, err) 744 }() 745 } 746 result.fn = client.listRelationshipsNextResults 747 req, err := client.ListRelationshipsPreparer(ctx, ID, relationshipName) 748 if err != nil { 749 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "ListRelationships", nil, "Failure preparing request") 750 return 751 } 752 753 resp, err := client.ListRelationshipsSender(req) 754 if err != nil { 755 result.rc.Response = autorest.Response{Response: resp} 756 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "ListRelationships", resp, "Failure sending request") 757 return 758 } 759 760 result.rc, err = client.ListRelationshipsResponder(resp) 761 if err != nil { 762 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "ListRelationships", resp, "Failure responding to request") 763 return 764 } 765 if result.rc.hasNextLink() && result.rc.IsEmpty() { 766 err = result.NextWithContext(ctx) 767 return 768 } 769 770 return 771} 772 773// ListRelationshipsPreparer prepares the ListRelationships request. 774func (client Client) ListRelationshipsPreparer(ctx context.Context, ID string, relationshipName string) (*http.Request, error) { 775 pathParameters := map[string]interface{}{ 776 "id": autorest.Encode("path", ID), 777 } 778 779 const APIVersion = "2020-05-31-preview" 780 queryParameters := map[string]interface{}{ 781 "api-version": APIVersion, 782 } 783 if len(relationshipName) > 0 { 784 queryParameters["relationshipName"] = autorest.Encode("query", relationshipName) 785 } 786 787 preparer := autorest.CreatePreparer( 788 autorest.AsGet(), 789 autorest.WithBaseURL(client.BaseURI), 790 autorest.WithPathParameters("/digitaltwins/{id}/relationships", pathParameters), 791 autorest.WithQueryParameters(queryParameters)) 792 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 793} 794 795// ListRelationshipsSender sends the ListRelationships request. The method will close the 796// http.Response Body if it receives an error. 797func (client Client) ListRelationshipsSender(req *http.Request) (*http.Response, error) { 798 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 799} 800 801// ListRelationshipsResponder handles the response to the ListRelationships request. The method always 802// closes the http.Response Body. 803func (client Client) ListRelationshipsResponder(resp *http.Response) (result RelationshipCollection, err error) { 804 err = autorest.Respond( 805 resp, 806 azure.WithErrorUnlessStatusCode(http.StatusOK), 807 autorest.ByUnmarshallingJSON(&result), 808 autorest.ByClosing()) 809 result.Response = autorest.Response{Response: resp} 810 return 811} 812 813// listRelationshipsNextResults retrieves the next set of results, if any. 814func (client Client) listRelationshipsNextResults(ctx context.Context, lastResults RelationshipCollection) (result RelationshipCollection, err error) { 815 req, err := lastResults.relationshipCollectionPreparer(ctx) 816 if err != nil { 817 return result, autorest.NewErrorWithError(err, "digitaltwins.Client", "listRelationshipsNextResults", nil, "Failure preparing next results request") 818 } 819 if req == nil { 820 return 821 } 822 resp, err := client.ListRelationshipsSender(req) 823 if err != nil { 824 result.Response = autorest.Response{Response: resp} 825 return result, autorest.NewErrorWithError(err, "digitaltwins.Client", "listRelationshipsNextResults", resp, "Failure sending next results request") 826 } 827 result, err = client.ListRelationshipsResponder(resp) 828 if err != nil { 829 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "listRelationshipsNextResults", resp, "Failure responding to next results request") 830 } 831 return 832} 833 834// ListRelationshipsComplete enumerates all values, automatically crossing page boundaries as required. 835func (client Client) ListRelationshipsComplete(ctx context.Context, ID string, relationshipName string) (result RelationshipCollectionIterator, err error) { 836 if tracing.IsEnabled() { 837 ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListRelationships") 838 defer func() { 839 sc := -1 840 if result.Response().Response.Response != nil { 841 sc = result.page.Response().Response.Response.StatusCode 842 } 843 tracing.EndSpan(ctx, sc, err) 844 }() 845 } 846 result.page, err = client.ListRelationships(ctx, ID, relationshipName) 847 return 848} 849 850// SendComponentTelemetry sends telemetry on behalf of a component in a digital twin. 851// Status codes: 852// 200 (OK): Success. 853// 400 (Bad Request): The request is invalid. 854// 404 (Not Found): There is either no digital twin with the provided id or the component path is invalid. 855// Parameters: 856// ID - the id of the digital twin. The id is unique within the service and case sensitive. 857// componentPath - the name of the DTDL component. 858// telemetry - the telemetry measurements to send from the digital twin's component. 859// dtID - a unique message identifier (in the scope of the digital twin id) that is commonly used for 860// de-duplicating messages. 861// dtTimestamp - an RFC 3339 timestamp that identifies the time the telemetry was measured. 862func (client Client) SendComponentTelemetry(ctx context.Context, ID string, componentPath string, telemetry interface{}, dtID string, dtTimestamp string) (result autorest.Response, err error) { 863 if tracing.IsEnabled() { 864 ctx = tracing.StartSpan(ctx, fqdn+"/Client.SendComponentTelemetry") 865 defer func() { 866 sc := -1 867 if result.Response != nil { 868 sc = result.Response.StatusCode 869 } 870 tracing.EndSpan(ctx, sc, err) 871 }() 872 } 873 req, err := client.SendComponentTelemetryPreparer(ctx, ID, componentPath, telemetry, dtID, dtTimestamp) 874 if err != nil { 875 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "SendComponentTelemetry", nil, "Failure preparing request") 876 return 877 } 878 879 resp, err := client.SendComponentTelemetrySender(req) 880 if err != nil { 881 result.Response = resp 882 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "SendComponentTelemetry", resp, "Failure sending request") 883 return 884 } 885 886 result, err = client.SendComponentTelemetryResponder(resp) 887 if err != nil { 888 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "SendComponentTelemetry", resp, "Failure responding to request") 889 return 890 } 891 892 return 893} 894 895// SendComponentTelemetryPreparer prepares the SendComponentTelemetry request. 896func (client Client) SendComponentTelemetryPreparer(ctx context.Context, ID string, componentPath string, telemetry interface{}, dtID string, dtTimestamp string) (*http.Request, error) { 897 pathParameters := map[string]interface{}{ 898 "componentPath": autorest.Encode("path", componentPath), 899 "id": autorest.Encode("path", ID), 900 } 901 902 const APIVersion = "2020-05-31-preview" 903 queryParameters := map[string]interface{}{ 904 "api-version": APIVersion, 905 } 906 907 preparer := autorest.CreatePreparer( 908 autorest.AsContentType("application/json; charset=utf-8"), 909 autorest.AsPost(), 910 autorest.WithBaseURL(client.BaseURI), 911 autorest.WithPathParameters("/digitaltwins/{id}/components/{componentPath}/telemetry", pathParameters), 912 autorest.WithJSON(telemetry), 913 autorest.WithQueryParameters(queryParameters), 914 autorest.WithHeader("dt-id", autorest.String(dtID))) 915 if len(dtTimestamp) > 0 { 916 preparer = autorest.DecoratePreparer(preparer, 917 autorest.WithHeader("dt-timestamp", autorest.String(dtTimestamp))) 918 } 919 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 920} 921 922// SendComponentTelemetrySender sends the SendComponentTelemetry request. The method will close the 923// http.Response Body if it receives an error. 924func (client Client) SendComponentTelemetrySender(req *http.Request) (*http.Response, error) { 925 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 926} 927 928// SendComponentTelemetryResponder handles the response to the SendComponentTelemetry request. The method always 929// closes the http.Response Body. 930func (client Client) SendComponentTelemetryResponder(resp *http.Response) (result autorest.Response, err error) { 931 err = autorest.Respond( 932 resp, 933 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 934 autorest.ByClosing()) 935 result.Response = resp 936 return 937} 938 939// SendTelemetry sends telemetry on behalf of a digital twin. 940// Status codes: 941// 200 (OK): Success. 942// 400 (Bad Request): The request is invalid. 943// 404 (Not Found): There is no digital twin with the provided id. 944// Parameters: 945// ID - the id of the digital twin. The id is unique within the service and case sensitive. 946// telemetry - the telemetry measurements to send from the digital twin. 947// dtID - a unique message identifier (in the scope of the digital twin id) that is commonly used for 948// de-duplicating messages. 949// dtTimestamp - an RFC 3339 timestamp that identifies the time the telemetry was measured. 950func (client Client) SendTelemetry(ctx context.Context, ID string, telemetry interface{}, dtID string, dtTimestamp string) (result autorest.Response, err error) { 951 if tracing.IsEnabled() { 952 ctx = tracing.StartSpan(ctx, fqdn+"/Client.SendTelemetry") 953 defer func() { 954 sc := -1 955 if result.Response != nil { 956 sc = result.Response.StatusCode 957 } 958 tracing.EndSpan(ctx, sc, err) 959 }() 960 } 961 req, err := client.SendTelemetryPreparer(ctx, ID, telemetry, dtID, dtTimestamp) 962 if err != nil { 963 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "SendTelemetry", nil, "Failure preparing request") 964 return 965 } 966 967 resp, err := client.SendTelemetrySender(req) 968 if err != nil { 969 result.Response = resp 970 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "SendTelemetry", resp, "Failure sending request") 971 return 972 } 973 974 result, err = client.SendTelemetryResponder(resp) 975 if err != nil { 976 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "SendTelemetry", resp, "Failure responding to request") 977 return 978 } 979 980 return 981} 982 983// SendTelemetryPreparer prepares the SendTelemetry request. 984func (client Client) SendTelemetryPreparer(ctx context.Context, ID string, telemetry interface{}, dtID string, dtTimestamp string) (*http.Request, error) { 985 pathParameters := map[string]interface{}{ 986 "id": autorest.Encode("path", ID), 987 } 988 989 const APIVersion = "2020-05-31-preview" 990 queryParameters := map[string]interface{}{ 991 "api-version": APIVersion, 992 } 993 994 preparer := autorest.CreatePreparer( 995 autorest.AsContentType("application/json; charset=utf-8"), 996 autorest.AsPost(), 997 autorest.WithBaseURL(client.BaseURI), 998 autorest.WithPathParameters("/digitaltwins/{id}/telemetry", pathParameters), 999 autorest.WithJSON(telemetry), 1000 autorest.WithQueryParameters(queryParameters), 1001 autorest.WithHeader("dt-id", autorest.String(dtID))) 1002 if len(dtTimestamp) > 0 { 1003 preparer = autorest.DecoratePreparer(preparer, 1004 autorest.WithHeader("dt-timestamp", autorest.String(dtTimestamp))) 1005 } 1006 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 1007} 1008 1009// SendTelemetrySender sends the SendTelemetry request. The method will close the 1010// http.Response Body if it receives an error. 1011func (client Client) SendTelemetrySender(req *http.Request) (*http.Response, error) { 1012 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 1013} 1014 1015// SendTelemetryResponder handles the response to the SendTelemetry request. The method always 1016// closes the http.Response Body. 1017func (client Client) SendTelemetryResponder(resp *http.Response) (result autorest.Response, err error) { 1018 err = autorest.Respond( 1019 resp, 1020 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 1021 autorest.ByClosing()) 1022 result.Response = resp 1023 return 1024} 1025 1026// Update updates a digital twin. 1027// Status codes: 1028// 200 (OK): Success. 1029// 400 (Bad Request): The request is invalid. 1030// 404 (Not Found): There is no digital twin with the provided id. 1031// Parameters: 1032// ID - the id of the digital twin. The id is unique within the service and case sensitive. 1033// patchDocument - an update specification described by JSON Patch. Updates to property values and $model 1034// elements may happen in the same request. Operations are limited to add, replace and remove. 1035// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is 1036// provided. 1037func (client Client) Update(ctx context.Context, ID string, patchDocument []interface{}, ifMatch string) (result autorest.Response, err error) { 1038 if tracing.IsEnabled() { 1039 ctx = tracing.StartSpan(ctx, fqdn+"/Client.Update") 1040 defer func() { 1041 sc := -1 1042 if result.Response != nil { 1043 sc = result.Response.StatusCode 1044 } 1045 tracing.EndSpan(ctx, sc, err) 1046 }() 1047 } 1048 if err := validation.Validate([]validation.Validation{ 1049 {TargetValue: patchDocument, 1050 Constraints: []validation.Constraint{{Target: "patchDocument", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 1051 return result, validation.NewError("digitaltwins.Client", "Update", err.Error()) 1052 } 1053 1054 req, err := client.UpdatePreparer(ctx, ID, patchDocument, ifMatch) 1055 if err != nil { 1056 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Update", nil, "Failure preparing request") 1057 return 1058 } 1059 1060 resp, err := client.UpdateSender(req) 1061 if err != nil { 1062 result.Response = resp 1063 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Update", resp, "Failure sending request") 1064 return 1065 } 1066 1067 result, err = client.UpdateResponder(resp) 1068 if err != nil { 1069 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "Update", resp, "Failure responding to request") 1070 return 1071 } 1072 1073 return 1074} 1075 1076// UpdatePreparer prepares the Update request. 1077func (client Client) UpdatePreparer(ctx context.Context, ID string, patchDocument []interface{}, ifMatch string) (*http.Request, error) { 1078 pathParameters := map[string]interface{}{ 1079 "id": autorest.Encode("path", ID), 1080 } 1081 1082 const APIVersion = "2020-05-31-preview" 1083 queryParameters := map[string]interface{}{ 1084 "api-version": APIVersion, 1085 } 1086 1087 preparer := autorest.CreatePreparer( 1088 autorest.AsContentType("application/json-patch+json; charset=utf-8"), 1089 autorest.AsPatch(), 1090 autorest.WithBaseURL(client.BaseURI), 1091 autorest.WithPathParameters("/digitaltwins/{id}", pathParameters), 1092 autorest.WithJSON(patchDocument), 1093 autorest.WithQueryParameters(queryParameters)) 1094 if len(ifMatch) > 0 { 1095 preparer = autorest.DecoratePreparer(preparer, 1096 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 1097 } 1098 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 1099} 1100 1101// UpdateSender sends the Update request. The method will close the 1102// http.Response Body if it receives an error. 1103func (client Client) UpdateSender(req *http.Request) (*http.Response, error) { 1104 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 1105} 1106 1107// UpdateResponder handles the response to the Update request. The method always 1108// closes the http.Response Body. 1109func (client Client) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { 1110 err = autorest.Respond( 1111 resp, 1112 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 1113 autorest.ByClosing()) 1114 result.Response = resp 1115 return 1116} 1117 1118// UpdateComponent updates a component on a digital twin. 1119// Status codes: 1120// 200 (OK): Success. 1121// 400 (Bad Request): The request is invalid. 1122// 404 (Not Found): There is either no digital twin with the provided id or the component path is invalid. 1123// Parameters: 1124// ID - the id of the digital twin. The id is unique within the service and case sensitive. 1125// componentPath - the name of the DTDL component. 1126// patchDocument - an update specification described by JSON Patch. Updates to property values and $model 1127// elements may happen in the same request. Operations are limited to add, replace and remove. 1128// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is 1129// provided. 1130func (client Client) UpdateComponent(ctx context.Context, ID string, componentPath string, patchDocument []interface{}, ifMatch string) (result autorest.Response, err error) { 1131 if tracing.IsEnabled() { 1132 ctx = tracing.StartSpan(ctx, fqdn+"/Client.UpdateComponent") 1133 defer func() { 1134 sc := -1 1135 if result.Response != nil { 1136 sc = result.Response.StatusCode 1137 } 1138 tracing.EndSpan(ctx, sc, err) 1139 }() 1140 } 1141 req, err := client.UpdateComponentPreparer(ctx, ID, componentPath, patchDocument, ifMatch) 1142 if err != nil { 1143 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "UpdateComponent", nil, "Failure preparing request") 1144 return 1145 } 1146 1147 resp, err := client.UpdateComponentSender(req) 1148 if err != nil { 1149 result.Response = resp 1150 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "UpdateComponent", resp, "Failure sending request") 1151 return 1152 } 1153 1154 result, err = client.UpdateComponentResponder(resp) 1155 if err != nil { 1156 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "UpdateComponent", resp, "Failure responding to request") 1157 return 1158 } 1159 1160 return 1161} 1162 1163// UpdateComponentPreparer prepares the UpdateComponent request. 1164func (client Client) UpdateComponentPreparer(ctx context.Context, ID string, componentPath string, patchDocument []interface{}, ifMatch string) (*http.Request, error) { 1165 pathParameters := map[string]interface{}{ 1166 "componentPath": autorest.Encode("path", componentPath), 1167 "id": autorest.Encode("path", ID), 1168 } 1169 1170 const APIVersion = "2020-05-31-preview" 1171 queryParameters := map[string]interface{}{ 1172 "api-version": APIVersion, 1173 } 1174 1175 preparer := autorest.CreatePreparer( 1176 autorest.AsContentType("application/json-patch+json; charset=utf-8"), 1177 autorest.AsPatch(), 1178 autorest.WithBaseURL(client.BaseURI), 1179 autorest.WithPathParameters("/digitaltwins/{id}/components/{componentPath}", pathParameters), 1180 autorest.WithQueryParameters(queryParameters)) 1181 if patchDocument != nil && len(patchDocument) > 0 { 1182 preparer = autorest.DecoratePreparer(preparer, 1183 autorest.WithJSON(patchDocument)) 1184 } 1185 if len(ifMatch) > 0 { 1186 preparer = autorest.DecoratePreparer(preparer, 1187 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 1188 } 1189 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 1190} 1191 1192// UpdateComponentSender sends the UpdateComponent request. The method will close the 1193// http.Response Body if it receives an error. 1194func (client Client) UpdateComponentSender(req *http.Request) (*http.Response, error) { 1195 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 1196} 1197 1198// UpdateComponentResponder handles the response to the UpdateComponent request. The method always 1199// closes the http.Response Body. 1200func (client Client) UpdateComponentResponder(resp *http.Response) (result autorest.Response, err error) { 1201 err = autorest.Respond( 1202 resp, 1203 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 1204 autorest.ByClosing()) 1205 result.Response = resp 1206 return 1207} 1208 1209// UpdateRelationship updates the properties on a relationship between two digital twins. 1210// Status codes: 1211// 200 (OK): Success. 1212// 400 (Bad Request): The request is invalid. 1213// 404 (Not Found): There is either no digital twin or relationship with the provided id. 1214// Parameters: 1215// ID - the id of the digital twin. The id is unique within the service and case sensitive. 1216// relationshipID - the id of the relationship. The id is unique within the digital twin and case sensitive. 1217// patchDocument - JSON Patch description of the update to the relationship properties. 1218// ifMatch - only perform the operation if the entity's etag matches one of the etags provided or * is 1219// provided. 1220func (client Client) UpdateRelationship(ctx context.Context, ID string, relationshipID string, patchDocument []interface{}, ifMatch string) (result autorest.Response, err error) { 1221 if tracing.IsEnabled() { 1222 ctx = tracing.StartSpan(ctx, fqdn+"/Client.UpdateRelationship") 1223 defer func() { 1224 sc := -1 1225 if result.Response != nil { 1226 sc = result.Response.StatusCode 1227 } 1228 tracing.EndSpan(ctx, sc, err) 1229 }() 1230 } 1231 req, err := client.UpdateRelationshipPreparer(ctx, ID, relationshipID, patchDocument, ifMatch) 1232 if err != nil { 1233 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "UpdateRelationship", nil, "Failure preparing request") 1234 return 1235 } 1236 1237 resp, err := client.UpdateRelationshipSender(req) 1238 if err != nil { 1239 result.Response = resp 1240 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "UpdateRelationship", resp, "Failure sending request") 1241 return 1242 } 1243 1244 result, err = client.UpdateRelationshipResponder(resp) 1245 if err != nil { 1246 err = autorest.NewErrorWithError(err, "digitaltwins.Client", "UpdateRelationship", resp, "Failure responding to request") 1247 return 1248 } 1249 1250 return 1251} 1252 1253// UpdateRelationshipPreparer prepares the UpdateRelationship request. 1254func (client Client) UpdateRelationshipPreparer(ctx context.Context, ID string, relationshipID string, patchDocument []interface{}, ifMatch string) (*http.Request, error) { 1255 pathParameters := map[string]interface{}{ 1256 "id": autorest.Encode("path", ID), 1257 "relationshipId": autorest.Encode("path", relationshipID), 1258 } 1259 1260 const APIVersion = "2020-05-31-preview" 1261 queryParameters := map[string]interface{}{ 1262 "api-version": APIVersion, 1263 } 1264 1265 preparer := autorest.CreatePreparer( 1266 autorest.AsContentType("application/json-patch+json; charset=utf-8"), 1267 autorest.AsPatch(), 1268 autorest.WithBaseURL(client.BaseURI), 1269 autorest.WithPathParameters("/digitaltwins/{id}/relationships/{relationshipId}", pathParameters), 1270 autorest.WithQueryParameters(queryParameters)) 1271 if patchDocument != nil && len(patchDocument) > 0 { 1272 preparer = autorest.DecoratePreparer(preparer, 1273 autorest.WithJSON(patchDocument)) 1274 } 1275 if len(ifMatch) > 0 { 1276 preparer = autorest.DecoratePreparer(preparer, 1277 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 1278 } 1279 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 1280} 1281 1282// UpdateRelationshipSender sends the UpdateRelationship request. The method will close the 1283// http.Response Body if it receives an error. 1284func (client Client) UpdateRelationshipSender(req *http.Request) (*http.Response, error) { 1285 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 1286} 1287 1288// UpdateRelationshipResponder handles the response to the UpdateRelationship request. The method always 1289// closes the http.Response Body. 1290func (client Client) UpdateRelationshipResponder(resp *http.Response) (result autorest.Response, err error) { 1291 err = autorest.Respond( 1292 resp, 1293 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 1294 autorest.ByClosing()) 1295 result.Response = resp 1296 return 1297} 1298