Skip to content

Commit 0220a31

Browse files
authored
Prototype (#20)
Created an SDK for searching and ordering telephone numbers.
1 parent b6af2ee commit 0220a31

36 files changed

+1782
-38
lines changed

README.md

Lines changed: 98 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Bandwidth Numbers Java SDK
22

3-
Java SDK for Bandwidth's number and application management
3+
Java SDK for Bandwidth's number management API.
44

55
## Dependency
66

@@ -20,18 +20,110 @@ compile 'com.bandwidth.sdk:numbers:(put desired version here)'
2020

2121

2222
## Quick Start
23+
24+
All objects in the SDK follow the Builder pattern for easy construction. To search for and order numbers, construct the
25+
relevant request and pass it to the appropriate client method.
26+
27+
### Construct the client
28+
Instances of the NumbersClient must be closed, typically on application shutdown to avoid resource leaks. Use the
29+
provided close method. The client also implements the AutoClosable interface for convenient use in try-with-resources
30+
blocks.
31+
32+
The client builder exposes a configuration method that allows access to the underlying AsyncHttpClient configuration
33+
should you want to configure it. See the [documentation](https://github.com/AsyncHttpClient/async-http-client) for that
34+
project to see what can be configured.
35+
```java
36+
NumbersClientImpl numbersClient = NumbersClientImpl.builder()
37+
.account("1")
38+
.username("username")
39+
.password("password")
40+
.build();
41+
42+
// Optionally an AsyncHttpClientConfig may be provided to fine tune settings
43+
NumbersClientImpl numbersClient = NumbersClientImpl.builder()
44+
.account("1")
45+
.username("username")
46+
.password("password")
47+
.config(
48+
new DefaultAsyncHttpClientConfig.Builder()
49+
.setRequestTimeout(60_000)
50+
.build())
51+
.build();
52+
```
53+
54+
### Search for available telephone numbers
55+
```java
56+
AvailableNumberSearchRequest availableNumberSearchRequest = AvailableNumberSearchRequest.builder()
57+
.state("NC")
58+
.city("CARY")
59+
.enableTNDetail(false)
60+
.quantity(10)
61+
.build();
62+
63+
SearchResult searchResult = numbersClient.getAvailableTelephoneNumbers(availableNumberSearchRequest);
64+
```
65+
66+
### Place an order for telephone numbers
67+
Placing an order is a synchronous operation that will submit an order request to bandwidth and poll until the order has
68+
completed behind the scenes. One invocation may result in several API calls in the background before control returns to
69+
the calling thread.
70+
```java
71+
// Each order type has a separate implementation
72+
ExistingTelephoneNumberOrderType existingTelephoneNumberOrderType = ExistingTelephoneNumberOrderType.builder()
73+
.addTelephoneNumberList("8042994451")
74+
.build();
75+
76+
// Wrap the order type in an Order wrapper and choose site id and peer for numbers to be associated with
77+
Order order = Order.builder()
78+
.siteId("1")
79+
.peerId("500539")
80+
.existingTelephoneNumberOrderType(existingTelephoneNumberOrderType)
81+
.build();
82+
83+
OrderResponse orderResponse = numbersClient.orderTelephoneNumbers(order);
84+
```
85+
2386
### Important Links
2487
* [Bandwidth Dashboard](https://dashboard.bandwidth.com/portal/report/#login:)
2588
* [Bandwidth Application](https://app.bandwidth.com/login)
2689
* [Bandwidth Developer Homepage](https://dev.bandwidth.com/)
2790

91+
92+
2893
```java
29-
public class MyAwesomeBandwidthNumbersApp{
94+
public class MyAwesomeBandwidthNumbersApp {
3095

31-
public static void main(String[] args){
32-
33-
}
96+
public static void main(String[] args) {
97+
98+
try (NumbersClientImpl numbersClient = NumbersClientImpl.builder()
99+
.account("1")
100+
.username("username")
101+
.password("password")
102+
.build()) {
34103

104+
AvailableNumberSearchRequest availableNumberSearchRequest = AvailableNumberSearchRequest.builder()
105+
.state("NC")
106+
.city("CARY")
107+
.enableTNDetail(false)
108+
.quantity(10)
109+
.build();
110+
111+
SearchResult searchResult = numbersClient.getAvailableTelephoneNumbers(availableNumberSearchRequest);
112+
113+
// putting it all together, place an order for numbers returned from a number search
114+
ExistingTelephoneNumberOrderType existingTelephoneNumberOrderType =
115+
ExistingTelephoneNumberOrderType.builder()
116+
.addAllTelephoneNumberList(searchResult.getTelephoneNumberList())
117+
.build();
118+
119+
Order order = Order.builder()
120+
.siteId("1")
121+
.peerId("500539")
122+
.existingTelephoneNumberOrderType(existingTelephoneNumberOrderType)
123+
.build();
124+
125+
OrderResponse orderResponse = numbersClient.orderTelephoneNumbers(order);
126+
}
127+
}
35128
}
36-
37129
```

build.gradle

Lines changed: 115 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
/*
2-
* This build file was generated by the Gradle 'init' task.
3-
*
4-
* This generated file contains a sample Java project to get you started.
5-
* For more details take a look at the Java Quickstart chapter in the Gradle
6-
* user guide available at https://docs.gradle.org/3.3/userguide/tutorial_java_projects.html
7-
*/
8-
91
buildscript {
102
repositories {
3+
mavenLocal()
114
mavenCentral()
125
}
136

@@ -23,6 +16,9 @@ buildscript {
2316
}
2417
}
2518

19+
plugins {
20+
id 'maven-publish'
21+
}
2622

2723
// Apply the java plugin to add support for Java
2824
apply plugin: 'java'
@@ -40,11 +36,115 @@ targetCompatibility = 1.8
4036
dependencies {
4137
apt 'org.immutables:value:2.5.6'
4238
compileOnly 'org.immutables:value:2.5.6:annotations'
43-
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.8.6'
44-
compile 'org.asynchttpclient:async-http-client:2.6.0'
45-
compile 'com.google.guava:guava:27.0-jre'
46-
compile 'com.fasterxml.jackson.datatype:jackson-datatype-guava:2.9.5'
47-
testCompile('org.assertj:assertj-core:3.6.2')
48-
testCompile('org.mockito:mockito-core:2.7.9')
49-
testCompile('junit:junit:4.4')
39+
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.8.6'
40+
implementation 'org.asynchttpclient:async-http-client:2.6.0'
41+
implementation 'com.google.guava:guava:27.0-jre'
42+
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-guava:2.9.5'
43+
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.4'
44+
testImplementation("org.assertj:assertj-core:3.11.1")
45+
testImplementation('org.mockito:mockito-core:2.23.0')
46+
testImplementation group: 'junit', name: 'junit', version: '4.12'
47+
}
48+
49+
publishing {
50+
publications {
51+
maven(MavenPublication) {
52+
groupId = 'com.bandwidth.sdk'
53+
artifactId = 'numbers'
54+
version = '0.1-SNAPSHOT'
55+
from components.java
56+
}
57+
}
58+
}
59+
60+
//Taken and changed from http://weibeld.net/java/publish-to-maven-central.html#deploy-to-ossrh
61+
62+
//To deploy, you need to define the following in your local ~/.gradle/gradle.properties file
63+
//signing.keyId
64+
//signing.password
65+
//signing.secretKeyRingFile
66+
//ossrhUsername
67+
//ossrhPassword
68+
69+
//To deploy, run
70+
//gradle uploadArchives
71+
72+
//If you don't remove the -SNAPSHOT, the deploy will only go to the staging repo
73+
74+
if (project.hasProperty("signing.keyId")) {
75+
// Signing
76+
apply plugin: 'signing'
77+
signing {
78+
sign configurations.archives
79+
}
80+
81+
82+
// Deploying
83+
apply plugin: 'maven'
84+
85+
// Add Javadoc JAR and sources JAR to artifact
86+
task javadocJar(type: Jar) {
87+
classifier = 'javadoc'
88+
from javadoc
89+
}
90+
task sourcesJar(type: Jar) {
91+
classifier = 'sources'
92+
from sourceSets.main.allSource
93+
}
94+
artifacts {
95+
archives javadocJar, sourcesJar
96+
}
97+
98+
// Configure group ID, artifact ID, and version
99+
group = "com.bandwidth.sdk"
100+
archivesBaseName = "numbers"
101+
version = "0.1-SNAPSHOT"
102+
103+
// Build, sign, and upload
104+
uploadArchives {
105+
repositories {
106+
mavenDeployer {
107+
108+
// Sign POM
109+
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
110+
111+
// Destination
112+
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
113+
authentication(userName: ossrhUsername, password: ossrhPassword )
114+
}
115+
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
116+
authentication(userName: ossrhUsername, password: ossrhPassword )
117+
}
118+
pom.project {
119+
name 'Bandwidth Java Numbers'
120+
packaging 'jar'
121+
description 'Java SDK for Bandwidth Numbers'
122+
url 'https://github.com/Bandwidth/numbers-java-sdk'
123+
124+
scm {
125+
connection 'scm:git:git://github.com/Bandwidth/numbers-java-sdk.git'
126+
developerConnection 'scm:git:ssh://github.com/Bandwidth/numbers-java-sdk.git'
127+
url 'https://github.com/Bandwidth/numbers-java-sdk/tree/master'
128+
}
129+
130+
licenses {
131+
license {
132+
name 'The Apache License, Version 2.0'
133+
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
134+
}
135+
}
136+
137+
developers {
138+
developer {
139+
id 'dx-bandwidth'
140+
name 'DX-Bandwidth'
141+
142+
organization 'bandwidth'
143+
organizationUrl 'http://bandwidth.com'
144+
}
145+
}
146+
}
147+
}
148+
}
149+
}
50150
}

gradlew.bat

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings.gradle

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1 @@
1-
/*
2-
* This settings file was generated by the Gradle 'init' task.
3-
*
4-
* The settings file is used to specify which projects to include in your build.
5-
* In a single project build this file can be empty or even removed.
6-
*
7-
* Detailed information about configuring a multi-project build in Gradle can be found
8-
* in the user guide at https://docs.gradle.org/3.3/userguide/multi_project_builds.html
9-
*/
10-
11-
/*
12-
// To declare projects as part of a multi-project build use the 'include' method
13-
include 'shared'
14-
include 'api'
15-
include 'services:webservice'
16-
*/
17-
181
rootProject.name = 'numbers-java-sdk'

0 commit comments

Comments
 (0)