จัดการแบรนด์

ตัวแทนทั้งหมดเป็นของแบรนด์ (ธุรกิจ องค์กร หรือกลุ่ม) ก่อนที่จะสร้างตัวแทนได้ คุณต้องสร้างแบรนด์ของตัวเอง แบรนด์เป็นการจัดระเบียบ เพื่อช่วยให้คุณจัดกลุ่มตัวแทนที่เกี่ยวข้องเข้าด้วยกัน

ข้อมูลโค้ดในหน้านี้มาจากตัวอย่าง Java และตัวอย่าง Node.js

สร้างแบรนด์

แบรนด์มี displayName และตัวระบุที่ไม่ซ้ำกัน name

Node.js

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);
});

Java.js

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

โดยโค้ดนี้จะแสดงข้อมูลแบรนด์ใหม่และตัวระบุที่ไม่ซ้ำกันที่กำหนดให้กับแบรนด์

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

ดึงข้อมูลแบรนด์

ดึงข้อมูลแบรนด์ได้โดยใช้ตัวระบุที่ไม่ซ้ำกัน (name)

Node.js

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);
});

Java

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

โค้ดนี้จะแสดงข้อมูลแบรนด์

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

แสดงรายการแบรนด์

คุณเรียกข้อมูลรายการแบรนด์ทั้งหมดที่สร้างไว้จนถึงตอนนี้ได้

Node.js

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);
});

Java

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'
    }
  ]
}

เปลี่ยนชื่อแบรนด์

คุณเปลี่ยนชื่อที่แสดงของแบรนด์ได้โดยใช้การดำเนินการ patch ดังนี้

Node.js

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'
}