همه نمایندگان به یک برند (کسب و کار، سازمان یا گروه) تعلق دارند. قبل از ایجاد یک نماینده، لازم است یک برند مالک ایجاد کنید. برندها صرفاً سازمانی هستند تا به شما در گروه بندی عوامل مرتبط با یکدیگر کمک کنند.
قطعه کد موجود در این صفحه از نمونه های جاوا و نمونه های Node.js گرفته شده است.
یک برند ایجاد کنید
شما می توانید یک برند جدید ایجاد کنید. برای جزئیات بیشتر، brands
و brands.create
ببینید. ایجاد کنید.
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());
این کد نام تجاری جدید ( displayName
) و یک شناسه منحصر به فرد ( name
) اختصاص داده شده به برند را برمی گرداند:
{
name: 'brands/17456b6b-65dc-4e35-b128-fd3047664ddf',
displayName: 'My new brand'
}
یک برند را بازیابی کنید
شما می توانید اطلاعات مربوط به یک نام تجاری را با استفاده از شناسه منحصر به فرد آن ( name
) بازیابی کنید. برای جزئیات بیشتر، به brands.get
مراجعه کنید.
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); });
جاوا
Brand brand = api.getBrand(brandId); logger.info("Brand: " + brand);
این کد اطلاعات برند را برمی گرداند:
{
name: 'brands/17456b6b-65dc-4e35-b128-fd3047664ddf',
displayName: 'My new brand'
}
مارک ها را فهرست کنید
می توانید لیستی از تمام برندهایی که ایجاد کرده اید را بازیابی کنید. برای جزئیات بیشتر، به brands.list
مراجعه کنید.
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); });
جاوا
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
تغییر داد:
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'
}