برندها را مدیریت کنید، برندها را مدیریت کنید

همه نمایندگان متعلق به یک برند (کسب و کار، سازمان یا گروه) هستند. قبل از اینکه یک نماینده ایجاد شود، لازم است یک برند مالک ایجاد شود. برندها صرفاً سازمانی هستند تا به شما در گروه بندی نمایندگان مرتبط کمک کنند.

قطعه کدهای این صفحه از نمونه‌های جاوا و نمونه‌های Node.js گرفته شده‌اند.

ایجاد یک برند

شما می‌توانید یک برند جدید ایجاد کنید. برای جزئیات بیشتر، به brands و brands.create مراجعه کنید.

نود جی اس

const businessCommunicationsApiHelper =
  require('@google/rbm-businesscommunications');

const privateKey =
  require('../../resources/businesscommunications-service-account-credentials.json');

businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey);

businessCommunicationsApiHelper.createBrand('My new brand').then((response) => {
	console.log('The new brand is:');
	console.log(response.data);
}).catch((err) => {
	console.log(err);
});

جاوا

String displayName = flags.getOrDefault("brand_name", "Test brand: " + now.getSecond());
Brand brand = api.createBrand(displayName);
logger.info("New brand id: " + brand.getName());

این کد نام تجاری جدید ( displayName ) و یک شناسه منحصر به فرد ( name ) که به برند اختصاص داده شده است را برمی‌گرداند:

{
  name: 'brands/17456b6b-65dc-4e35-b128-fd3047664ddf',
  displayName: 'My new brand'
}

بازیابی یک برند

شما می‌توانید با استفاده از شناسه منحصر به فرد یک برند ( name ) اطلاعات مربوط به آن را بازیابی کنید. برای جزئیات بیشتر، به brands.get مراجعه کنید.

نود جی اس

const businessCommunicationsApiHelper =
  require('@google/rbm-businesscommunications');

const privateKey =
  require('../../resources/businesscommunications-service-account-credentials.json');

businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey);

businessCommunicationsApiHelper.getBrand(brandId).then((response) => {
  console.log('Brand details are:');
  console.log(response.data);
}).catch((err) => {
  console.log(err);
});

جاوا

Brand brand = api.getBrand(brandId);
logger.info("Brand: " + brand);

این کد اطلاعات برند را برمی‌گرداند:

{
  name: 'brands/17456b6b-65dc-4e35-b128-fd3047664ddf',
  displayName: 'My new brand'
}

فهرست برندها

می‌توانید فهرستی از تمام برندهایی که ایجاد کرده‌اید را بازیابی کنید. برای جزئیات بیشتر، به brands.list مراجعه کنید.

نود جی اس

const businessCommunicationsApiHelper =
  require('@google/rbm-businesscommunications');

const privateKey =
  require('../../resources/businesscommunications-service-account-credentials.json');

businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey);

businessCommunicationsApiHelper.listBrands().then((response) => {
  console.log('Current brands available are:');
  console.log(response.data);
}).catch((err) => {
  console.log(err);
});

جاوا

List<Brand> brands = api.listBrands().stream().sorted(Comparator.comparing(Brand::getName))
  .collect(Collectors.toList());
logger.info(String.format("Found %d brands", brands.size()));
for (Brand brand : brands) {
  logger.info(String.format("Brand [%s]: '%s'", brand.getName(), brand.getDisplayName()));
}

این کد لیستی از تمام برندهای شما را برمی‌گرداند:

{
  brands: [
    {
      name: 'brands/1deb6297-8a57-474a-a02c-48529a3de0a0',
      displayName: 'My brand'
    },
    {
      name: 'brands/3b607982-8c06-467a-96b8-020ddc26ac83',
      displayName: 'My second brand'
    },
    {
      name: 'brands/40bd963f-ff92-425c-b273-8f0892d2d017',
      displayName: 'My thrd brand'
    }
  ]
}

تغییر نام یک برند

شما می‌توانید نام نمایشی برند را تغییر دهید. برای جزئیات بیشتر، به brands.patch مراجعه کنید.

نام نمایشی برند را می‌توان با استفاده از عملیات patch تغییر داد:

نود جی اس

const businessCommunicationsApiHelper =
  require('@google/rbm-businesscommunications');

const privateKey =
  require('../../resources/businesscommunications-service-account-credentials.json');

businessCommunicationsApiHelper.initBusinessCommunucationsApi(privateKey);

businessCommunicationsApiHelper
  .patchBrand(brand.name, 'My brand new name').then((response) => {
    console.log(response.data);
});

این کد اطلاعات برند به‌روزرسانی‌شده را برمی‌گرداند:

{
  name: 'brands/40bd963f-ff92-425c-b273-8f0892d2d017',
  displayName: 'My brands new name'
}