Skip to content

Commit

Permalink
feat: Add get-full-pricing endpoint (#481)
Browse files Browse the repository at this point in the history
* Update changelog

* Bump version: v7.8.0 → v7.9.0

* Add full-pricing endpoint

* Master API key default for secrets
  • Loading branch information
SMadani authored Sep 28, 2023
1 parent aa56274 commit 52f8059
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[bumpversion]
commit = True
tag = False
current_version = v7.8.0
current_version = v7.9.0
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
serialize =
{major}.{minor}.{patch}-{release}{build}
Expand Down
39 changes: 38 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

# [7.9.0] - 2023-??-??
- Added `get-full-pricing` implementation of Pricing API in `AccountClient`
- Added master API key default overloads for secret management in Account API
- Deprecated public internal request classes in Account API
- Internal refactoring of Verify v1 and Account API implementations

# [7.8.0] - 2023-09-07
- Added capability to configure request timeouts (default is 60 seconds)
- Deprecated custom HTTP client implementation setting
- Internal refactoring of Numbers, Conversion and Number Insight implementations
- Internal refactoring of Numbers, Conversion and Number Insight API implementations

# [7.7.0] - 2023-08-10
- Added Users API implementation
Expand Down Expand Up @@ -68,9 +74,40 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Deprecated WAPPush SMS (removed in 8.x)
- Bumped dependency versions

## [8.0.0-beta4] - 2023-02-24
- Removed Payments over the Phone NCCO
- Added SIP functionality to video API
- Added Broadcast functionality to video API
- Refactored Archives for consistency with Broadcast
- Use UUID as return type for IDs where applicable

## [8.0.0-beta3] - 2023-01-11
- Removed `WAPPush` SMS message type
- Fixed token generation (added missing claim & role as string)
- Fixed incorrect responses for `muteSession` and `muteStream` (they don't return anything)
- Improved handling of 200 / 204 responses for video endpoints which don't return anything

## [8.0.0-beta2] - 2022-12-15
- Added token generation capability to `VideoClient`
- Added varargs for `SetStreamLayoutRequest`
- `listArchives` endpoint takes as input `ListArchivesRequest` using builder pattern
- Simplified `muteSession` and `muteStream` invocation

# [7.1.1] - 2022-11-16
- Bumped Jackson version to 2.14

## [8.0.0-beta1] - 2022-11-15
- Maven artifact moved to `com.vonage:server-sdk`
- Initial implementation of [Vonage Video API](https://developer.vonage.com/api/video), with following functionality:
- Create sessions
- Retrieve or update stream layouts in a session
- Create, retrieve, delete archives
- Add / remove streams from archive
- Change archive layout
- Mute streams or individual participants in a session
- Disconnect participants from a session
- Send signal to participants in a session

## [7.1.0] - 2022-08-25
- Fixed parsing `MessageResponseException` when entity body is empty
- Added toggle for using Messages API Sandbox to `MessagesClient`
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ See all of our SDKs and integrations on the [Vonage Developer portal](https://de

## Installation

Releases are published to [Maven Central](https://central.sonatype.com/artifact/com.vonage/client/7.8.0/snippets).
Releases are published to [Maven Central](https://central.sonatype.com/artifact/com.vonage/client/7.9.0/snippets).
Instructions for your build system can be found in the snippets section.
They're also available from [here](https://mvnrepository.com/artifact/com.vonage/client/7.8.0).
They're also available from [here](https://mvnrepository.com/artifact/com.vonage/client/7.9.0).
Release notes can be found in the [changelog](CHANGELOG.md).

### Build It Yourself
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {

group = "com.vonage"
archivesBaseName = "client"
version = "7.8.0"
version = "7.9.0"
sourceCompatibility = "1.8"
targetCompatibility = "1.8"

Expand Down
4 changes: 2 additions & 2 deletions bumpversion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ then
exit 1
fi

python -m pip install --upgrade pip
pip install bump2version
python3 -m pip install --upgrade pip
pip3 install bump2version
bump2version --new-version "$1" patch
2 changes: 1 addition & 1 deletion src/main/java/com/vonage/client/HttpWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public class HttpWrapper {
private static final String CLIENT_NAME = "vonage-java-sdk";
private static final String CLIENT_VERSION = "7.8.0";
private static final String CLIENT_VERSION = "7.9.0";
private static final String JAVA_VERSION = System.getProperty("java.version");
private static final String USER_AGENT = String.format("%s/%s java/%s", CLIENT_NAME, CLIENT_VERSION, JAVA_VERSION);

Expand Down
71 changes: 69 additions & 2 deletions src/main/java/com/vonage/client/account/AccountClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@
import com.vonage.client.auth.SignatureAuthMethod;
import com.vonage.client.auth.TokenAuthMethod;
import com.vonage.client.common.HttpMethod;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;

/**
* A client for talking to the Vonage Account API. The standard way to obtain an instance of this class is to use {@link
* VonageClient#getAccountClient()}.
*/
public class AccountClient {
final Supplier<String> apiKeyGetter;

final RestEndpoint<Void, BalanceResponse> balance;
final RestEndpoint<PricingRequest, PricingResponse> pricing;
//final RestEndpoint<FullPricingRequest, PricingResponse> fullPricing;
final RestEndpoint<FullPricingRequest, FullPricingResponse> fullPricing;
final RestEndpoint<PrefixPricingRequest, PrefixPricingResponse> prefixPricing;
final RestEndpoint<TopUpRequest, Void> topUp;
final RestEndpoint<SettingsRequest, SettingsResponse> settings;
Expand All @@ -45,6 +49,8 @@ public class AccountClient {
*/
@SuppressWarnings("unchecked")
public AccountClient(HttpWrapper wrapper) {
apiKeyGetter = () -> wrapper.getAuthCollection().getAuth(TokenAuthMethod.class).getApiKey();

class Endpoint<T, R> extends DynamicEndpoint<T, R> {
static final String SECRETS_PATH = "s/%s/secrets";

Expand Down Expand Up @@ -87,7 +93,7 @@ class SecretRequestEndpoint<R> extends Endpoint<SecretRequest, R> {

balance = new Endpoint<>(req -> "/get-balance");
pricing = new Endpoint<>(req -> "/get-pricing/outbound/" + req.getServiceType());
//fullPricing = new Endpoint<>(req -> "/get-full-pricing/outbound/" + req.getServiceType());
fullPricing = new Endpoint<>(req -> "/get-full-pricing/outbound/" + req.getServiceType());
prefixPricing = new Endpoint<>(req -> "/get-prefix-pricing/outbound/" + req.getServiceType());
topUp = new Endpoint<>(req -> "/top-up", HttpMethod.POST);
settings = new Endpoint<>(req -> "/settings", HttpMethod.POST);
Expand All @@ -108,6 +114,17 @@ public BalanceResponse getBalance() throws AccountResponseException {
return balance.execute(null);
}

/**
*
* @param service The service type to retrieve pricing and network information for.
*
* @return The
*/
public List<PricingResponse> listPriceAllCountries(ServiceType service) {
Objects.requireNonNull(service, "Service type is required.");
return fullPricing.execute(new FullPricingRequest(service)).getCountries();
}

/**
* Retrieve the voice pricing for a specified country.
*
Expand Down Expand Up @@ -165,6 +182,19 @@ public void topUp(String transaction) throws AccountResponseException {
topUp.execute(new TopUpRequest(transaction));
}

/**
* List the ID of each secret associated with this account's main API key.
*
* @return ListSecretsResponse object which contains the results from the API.
*
* @throws AccountResponseException If there was an error making the request or retrieving the response.
*
* @since 7.9.0
*/
public ListSecretsResponse listSecrets() throws AccountResponseException {
return listSecrets(apiKeyGetter.get());
}

/**
* List the ID of each secret associated to the given API key.
*
Expand All @@ -183,6 +213,19 @@ public ListSecretsResponse listSecrets(String apiKey) throws AccountResponseExce
return listSecrets.execute(apiKey);
}

/**
* Get information for a specific secret id associated with this account's main API key.
*
* @param secretId The id of the secret to get information on.
*
* @return SecretResponse object which contains the results from the API.
*
* @throws AccountResponseException If there was an error making the request or retrieving the response.
*/
public SecretResponse getSecret(String secretId) throws AccountResponseException {
return getSecret(apiKeyGetter.get(), secretId);
}

/**
* Get information for a specific secret id associated to a given API key.
*
Expand All @@ -199,6 +242,19 @@ public SecretResponse getSecret(String apiKey, String secretId) throws AccountRe
return getSecret.execute(new SecretRequest(apiKey, secretId));
}

/**
* Create a secret to be used with this account's main API key.
*
* @param secret The contents of the secret.
*
* @return SecretResponse object which contains the created secret from the API.
*
* @throws AccountResponseException If there was an error making the request or retrieving the response.
*/
public SecretResponse createSecret(String secret) throws AccountResponseException {
return createSecret(apiKeyGetter.get(), secret);
}

/**
* Create a secret to be used with a specific API key.
*
Expand All @@ -215,6 +271,17 @@ public SecretResponse createSecret(String apiKey, String secret) throws AccountR
return createSecret.execute(new CreateSecretRequest(apiKey, secret));
}

/**
* Revoke a secret associated with this account's main API key.
*
* @param secretId The id of the secret to revoke.
*
* @throws AccountResponseException If there was an error making the request or retrieving the response.
*/
public void revokeSecret(String secretId) throws AccountResponseException {
revokeSecret(apiKeyGetter.get(), secretId);
}

/**
* Revoke a secret associated with a specific API key.
*
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/vonage/client/account/FullPricingResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2023 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vonage.client.account;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
import java.util.List;

/**
* Pricing data for all countries.
*
* @since 7.9.0
*/
@JsonIgnoreProperties(ignoreUnknown = true)
class FullPricingResponse implements Jsonable {
private Integer count;
private List<PricingResponse> countries;

@JsonProperty("countries")
public List<PricingResponse> getCountries() {
return countries;
}
}
Loading

0 comments on commit 52f8059

Please sign in to comment.