这份文档还在翻译中,预期年底前完成。欢迎您提供宝贵的意见及建议。

Redact using an ID

In this code snippet you see how to redact a message using an ID

Example

Replace the following variables in the example code:

Key Description
VONAGE_REDACT_ID The ID of the data record that you'd like to redact
VONAGE_REDACT_TYPE The product that the ID belongs to e.g. sms

Prerequisites

npm install @vonage/server-sdk

Create a file named transaction.js and add the following code:

const Vonage = require('@vonage/server-sdk');

const vonage = new Vonage({
  apiKey: VONAGE_API_KEY,
  apiSecret: VONAGE_API_SECRET
});

View full source

Write the code

Add the following to transaction.js:

vonage.redact.transaction(NEXMO_REDACT_ID, NEXMO_REDACT_TYPE, (err) => {
  if(err) {
    console.error(err);
  }
  // On success the API returns a 204, so there is no response
});

View full source

Run your code

Save this file to your machine and run it:

node transaction.js

Prerequisites

Add the following to `build.gradle`:

compile 'com.vonage:client:6.2.0'

Create a class named RedactATransaction and add the following code to the main method:

VonageClient client = VonageClient.builder()
        .apiKey(VONAGE_API_KEY)
        .apiSecret(VONAGE_API_SECRET)
        .build();

View full source

Write the code

Add the following to the main method of the RedactATransaction class:

RedactClient redactClient = client.getRedactClient();

redactClient.redactTransaction(VONAGE_REDACT_ID, VONAGE_REDACT_PRODUCT);

View full source

Run your code

We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:

  apply plugin: 'application'
  mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Run the following gradle command to execute your application, replacing com.vonage.quickstart.redact with the package containing RedactATransaction:

gradle run -Pmain=com.vonage.quickstart.redact.RedactATransaction

Prerequisites

Install-Package Vonage

Create a file named RedactTransaction.cs and add the following code:

using Vonage;
using Vonage.Redaction;
using Vonage.Request;

View full source

Add the following to RedactTransaction.cs:

var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(credentials);

View full source

Write the code

Add the following to RedactTransaction.cs:

var request = new RedactRequest() { Id = VONAGE_REDACT_ID, Type = VONAGE_REDACT_TYPE, Product = VONAGE_REDACT_PRODUCT };
var response = client.RedactClient.Redact(request);

View full source

Prerequisites

composer require vonage/client

Create a file named redact.php and add the following code:

$basic  = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

View full source

Write the code

Add the following to redact.php:

// This request returns a 204 on success, and throws on error
$client->redact()->transaction(VONAGE_REDACT_ID, VONAGE_REDACT_TYPE);

View full source

Run your code

Save this file to your machine and run it:

php redact.php

Prerequisites

pip install vonage python-dotenv

Create a file named redact-a-transaction.py and add the following code:

import os
from os.path import join, dirname
import vonage
from dotenv import load_dotenv

View full source

Add the following to redact-a-transaction.py:

client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)

View full source

Write the code

Add the following to redact-a-transaction.py:

client.redact_transaction(id=VONAGE_REDACT_ID, product=VONAGE_REDACT_TYPE)
print("Successfully redacted ID " + VONAGE_REDACT_ID)

View full source

Run your code

Save this file to your machine and run it:

python redact-a-transaction.py

Prerequisites

gem install vonage

Create a file named redact.rb and add the following code:

client = Vonage::Client.new(
  api_key: VONAGE_API_KEY,
  api_secret: VONAGE_API_SECRET
)

View full source

Write the code

Add the following to redact.rb:

client.redact.transaction(
  id: VONAGE_REDACT_ID,
  product: VONAGE_REDACT_TYPE
)

View full source

Run your code

Save this file to your machine and run it:

ruby redact.rb