github.com/grokify/go-ringcentral-client@v0.3.31/office/v1/examples/e911_address/e911_address.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"os"
     7  
     8  	"github.com/grokify/goauth"
     9  	"github.com/grokify/mogo/config"
    10  	"github.com/grokify/mogo/fmt/fmtutil"
    11  
    12  	rc "github.com/grokify/go-ringcentral-client/office/v1/client"
    13  	ru "github.com/grokify/go-ringcentral-client/office/v1/util"
    14  )
    15  
    16  func getAccountDeviceList(apiClient *rc.APIClient, accountId string) (rc.GetAccountDevicesResponse, error) {
    17  	info, resp, err := apiClient.AccountProvisioningApi.ListAccountDevices(context.Background(), accountId)
    18  	if err != nil {
    19  		return info, err
    20  	}
    21  	if resp.StatusCode >= 300 {
    22  		return info, fmt.Errorf("API Status Code %v", resp.StatusCode)
    23  	}
    24  	return info, err
    25  }
    26  
    27  func getPrintDeviceE911Address(apiClient *rc.APIClient, deviceId string) {
    28  	device, resp, err := apiClient.AccountProvisioningApi.LoadAccountDevice(
    29  		context.Background(), "~", deviceId)
    30  	if err != nil {
    31  		panic(err)
    32  	} else if resp.StatusCode >= 300 {
    33  		panic("BAD_STATUS")
    34  	}
    35  	fmtutil.PrintJSON(device)
    36  }
    37  
    38  func main() {
    39  	_, err := config.LoadDotEnv([]string{os.Getenv("ENV_PATH"), "./.env"}, 1)
    40  	if err != nil {
    41  		panic(err)
    42  	}
    43  
    44  	apiClient, err := ru.NewApiClientPassword(
    45  		goauth.NewCredentialsOAuth2Env("RINGCENTRAL_"))
    46  	if err != nil {
    47  		panic(err)
    48  	}
    49  
    50  	deviceList, err := getAccountDeviceList(apiClient, "~")
    51  	if err != nil {
    52  		panic(err)
    53  	}
    54  	fmtutil.PrintJSON(deviceList)
    55  
    56  	// UpdateDevice
    57  	if 1 == 0 {
    58  		deviceId := "12345678"
    59  		getPrintDeviceE911Address(apiClient, deviceId)
    60  
    61  		body := rc.AccountDeviceUpdate{
    62  			EmergencyServiceAddress: rc.EmergencyAddressInfoRequest{
    63  				CustomerName: "RingForce",
    64  				Street:       "20 DAVIS DR",
    65  				Street2:      "",
    66  				City:         "BELMONT",
    67  				State:        "CA",
    68  				Zip:          "94402-3002",
    69  				Country:      "US",
    70  			},
    71  		}
    72  		fmtutil.PrintJSON(body)
    73  
    74  		info, resp, err := apiClient.AccountProvisioningApi.UpdateDevice(
    75  			context.Background(), "~", deviceId, body,
    76  		)
    77  		if err != nil {
    78  			panic(err)
    79  		} else if resp.StatusCode >= 300 {
    80  			panic(fmt.Sprintf("Status %v", resp.StatusCode))
    81  		}
    82  		fmtutil.PrintJSON(info)
    83  
    84  		getPrintDeviceE911Address(apiClient, deviceId)
    85  	}
    86  
    87  	fmt.Println("DONE")
    88  }