Skip to content

Commit 10b891b

Browse files
committed
Merge pull request #13 from messagebird/lookup
Add support for the Lookup API
2 parents 3d4389d + 50cae36 commit 10b891b

File tree

11 files changed

+424
-10
lines changed

11 files changed

+424
-10
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ If you are using maven simply add the messagebird API to your dependencies like
2828
<dependency>
2929
<groupId>com.messagebird</groupId>
3030
<artifactId>messagebird-api</artifactId>
31-
<version>1.1.1</version>
31+
<version>1.2.0</version>
3232
</dependency>
3333
```
3434

3535
In case you are building without maven you still need maven to build the libraries but
3636
then simply copy the following jar's over to your project
3737

3838
```
39-
messagebird-api-1.1.1.jar
39+
messagebird-api-1.2.0.jar
4040
jackson-core-2.1.1.jar
4141
jackson-databind-2.1.1.jar
4242
jackson-mapper-asl-1.9.13.jar
@@ -106,7 +106,7 @@ To try out the command line examples follow the above build instructions.
106106
When everything did build successful you can try out the API like this:
107107
```shell
108108
cd examples/target
109-
java -cp examples-1.0.1-jar-with-dependencies.jar ExampleSendMessage test_gshuPaZoeEG6ovbc8M79w0QyM 31612345678 "This is a test message"
109+
java -cp examples-1.2.0-jar-with-dependencies.jar ExampleSendMessage test_gshuPaZoeEG6ovbc8M79w0QyM 31612345678 "This is a test message"
110110
```
111111

112112
Please see the other examples for a complete overview of all the available API calls.

api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.messagebird</groupId>
88
<artifactId>messagebird-api</artifactId>
9-
<version>1.1.1</version>
9+
<version>1.2.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>${project.groupId}:${project.artifactId}</name>

api/src/main/java/com/messagebird/MessageBirdClient.java

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class MessageBirdClient {
3232
private static final String MESSAGESPATH = "/messages";
3333
private static final String VOICEMESSAGESPATH = "/voicemessages";
3434
private static final String VERIFYPATH = "/verify";
35+
private static final String LOOKUPPATH = "/lookup";
36+
private static final String LOOKUPHLRPATH = "/lookup/%s/hlr";
3537
private MessageBirdService messageBirdService;
3638

3739
public MessageBirdClient(final MessageBirdService messageBirdService) {
@@ -385,4 +387,124 @@ public void deleteVerifyObject(String id) throws NotFoundException, GeneralExcep
385387
}
386388
messageBirdService.deleteByID(VERIFYPATH, id);
387389
}
390+
391+
/**
392+
* Send a Lookup request
393+
*
394+
* @param Lookup
395+
* @return Lookup
396+
* @throws UnauthorizedException
397+
* @throws GeneralException
398+
* @throws NotFoundException
399+
*/
400+
public Lookup viewLookup(final Lookup lookup) throws UnauthorizedException, GeneralException, NotFoundException {
401+
if (lookup.getPhoneNumber() == null) {
402+
throw new IllegalArgumentException("Phonenumber must be specified.");
403+
}
404+
final Map<String, Object> params = new LinkedHashMap<String, Object>();
405+
if (lookup.getCountryCode() != null) {
406+
params.put("countryCode", lookup.getCountryCode());
407+
}
408+
return messageBirdService.requestByID(LOOKUPPATH, String.valueOf(lookup.getPhoneNumber()), params, Lookup.class);
409+
}
410+
411+
/**
412+
* Send a Lookup request
413+
*
414+
* @param phonenumber
415+
* @return Lookup
416+
* @throws UnauthorizedException
417+
* @throws GeneralException
418+
*/
419+
public Lookup viewLookup(final BigInteger phonenumber) throws UnauthorizedException, GeneralException, NotFoundException {
420+
if (phonenumber == null) {
421+
throw new IllegalArgumentException("Phonenumber must be specified.");
422+
}
423+
final Lookup lookup = new Lookup(phonenumber);
424+
return this.viewLookup(lookup);
425+
}
426+
427+
/**
428+
* Request a Lookup HLR (lookup)
429+
*
430+
* @param LookupHlr
431+
* @return lookupHlr
432+
* @throws UnauthorizedException
433+
* @throws GeneralException
434+
*/
435+
public LookupHlr requestLookupHlr(final LookupHlr lookupHlr) throws UnauthorizedException, GeneralException {
436+
if (lookupHlr.getPhoneNumber() == null) {
437+
throw new IllegalArgumentException("Phonenumber must be specified.");
438+
}
439+
if (lookupHlr.getReference() == null) {
440+
throw new IllegalArgumentException("Reference must be specified.");
441+
}
442+
final Map<String, Object> payload = new LinkedHashMap<String, Object>();
443+
payload.put("phoneNumber", lookupHlr.getPhoneNumber());
444+
payload.put("reference", lookupHlr.getReference());
445+
if (lookupHlr.getCountryCode() != null) {
446+
payload.put("countryCode", lookupHlr.getCountryCode());
447+
}
448+
return messageBirdService.sendPayLoad(String.format(LOOKUPHLRPATH, lookupHlr.getPhoneNumber()), payload, LookupHlr.class);
449+
}
450+
451+
/**
452+
* Request a Lookup HLR (lookup)
453+
*
454+
* @param phonenumber
455+
* @param reference
456+
* @return lookupHlr
457+
* @throws UnauthorizedException
458+
* @throws GeneralException
459+
*/
460+
public LookupHlr requestLookupHlr(final BigInteger phonenumber, final String reference) throws UnauthorizedException, GeneralException {
461+
if (phonenumber == null) {
462+
throw new IllegalArgumentException("Phonenumber must be specified.");
463+
}
464+
if (reference == null) {
465+
throw new IllegalArgumentException("Reference must be specified.");
466+
}
467+
final LookupHlr lookupHlr = new LookupHlr();
468+
lookupHlr.setPhoneNumber(phonenumber);
469+
lookupHlr.setReference(reference);
470+
return this.requestLookupHlr(lookupHlr);
471+
}
472+
473+
/**
474+
* View a Lookup HLR (lookup)
475+
*
476+
* @param LookupHlr
477+
* @return LookupHlr
478+
* @throws UnauthorizedException
479+
* @throws GeneralException
480+
* @throws NotFoundException
481+
*/
482+
public LookupHlr viewLookupHlr(final LookupHlr lookupHlr) throws UnauthorizedException, GeneralException, NotFoundException {
483+
if (lookupHlr.getPhoneNumber() == null) {
484+
throw new IllegalArgumentException("Phonenumber must be specified");
485+
}
486+
final Map<String, Object> params = new LinkedHashMap<String, Object>();
487+
if (lookupHlr.getCountryCode() != null) {
488+
params.put("countryCode", lookupHlr.getCountryCode());
489+
}
490+
return messageBirdService.requestByID(String.format(LOOKUPHLRPATH, lookupHlr.getPhoneNumber()), "", params, LookupHlr.class);
491+
}
492+
493+
/**
494+
* View a Lookup HLR (lookup)
495+
*
496+
* @param phonenumber
497+
* @return LookupHlr
498+
* @throws UnauthorizedException
499+
* @throws GeneralException
500+
* @throws NotFoundException
501+
*/
502+
public LookupHlr viewLookupHlr(final BigInteger phonenumber) throws UnauthorizedException, GeneralException, NotFoundException {
503+
if (phonenumber == null) {
504+
throw new IllegalArgumentException("Phonenumber must be specified");
505+
}
506+
final LookupHlr lookupHlr = new LookupHlr();
507+
lookupHlr.setPhoneNumber(phonenumber);
508+
return this.viewLookupHlr(lookupHlr);
509+
}
388510
}

api/src/main/java/com/messagebird/MessageBirdServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class MessageBirdServiceImpl implements MessageBirdService {
3232
private static final List<String> REQUESTMETHODS = Arrays.asList(new String[]{"GET", "POST", "DELETE"});
3333
private final String accessKey;
3434
private final String serviceUrl = "https://rest.messagebird.com";
35-
private final String clientVersion = "1.1.1";
35+
private final String clientVersion = "1.2.0";
3636
private final String userAgentString = "MessageBird/Java ApiClient/" + clientVersion;
3737
private Proxy proxy = null;
3838

@@ -65,7 +65,7 @@ public <R> R requestByID(String request, String id, Map<String, Object> params,
6565
if (id != null) {
6666
path = "/" + id;
6767
}
68-
// Make rest of get request
68+
// Make rest of GET request
6969
String queryParams = "";
7070
if (!params.isEmpty()) {
7171
queryParams = "?" + getPathVariables(params);

api/src/main/java/com/messagebird/objects/Hlr.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
public class Hlr {
1515
private String id;
1616
private String href;
17-
private BigInteger msisdn;
17+
protected BigInteger msisdn;
1818
private String network;
19-
private String reference;
19+
protected String reference;
2020
private String status;
2121
private Date createdDatetime;
2222
private Date statusDatetime;
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.messagebird.objects;
2+
3+
import java.io.Serializable;
4+
import java.math.BigInteger;
5+
6+
public class Lookup implements Serializable {
7+
8+
private static final long serialVersionUID = 8927014359452296030L;
9+
10+
private String href;
11+
private String countryCode;
12+
private Integer countryPrefix;
13+
private BigInteger phoneNumber;
14+
private String type;
15+
private Formats formats;
16+
private LookupHlr hlr;
17+
18+
@Override
19+
public String toString() {
20+
return "Lookup{" +
21+
"href=" + href +
22+
", countryCode=" + countryCode +
23+
", countryPrefix=" + countryPrefix +
24+
", phoneNumber=" + phoneNumber +
25+
", type=" + type +
26+
", formats=" + formats +
27+
", hlr=" + hlr +
28+
"}";
29+
}
30+
31+
public Lookup() {
32+
}
33+
34+
public Lookup(BigInteger phoneNumber) {
35+
this.phoneNumber = phoneNumber;
36+
}
37+
38+
public String getHref() {
39+
return href;
40+
}
41+
42+
public String getCountryCode() {
43+
return countryCode;
44+
}
45+
46+
public void setCountryCode(String countryCode) {
47+
this.countryCode = countryCode;
48+
}
49+
50+
public Integer getCountryPrefix() {
51+
return countryPrefix;
52+
}
53+
54+
public BigInteger getPhoneNumber() {
55+
return phoneNumber;
56+
}
57+
58+
public String getType() {
59+
return type;
60+
}
61+
62+
public Formats getFormats() {
63+
return formats;
64+
}
65+
66+
public Hlr getHlr() {
67+
return hlr;
68+
}
69+
70+
static public class Formats implements Serializable {
71+
72+
private static final long serialVersionUID = 2165916336570704972L;
73+
74+
private String e164;
75+
private String international;
76+
private String national;
77+
private String rfc3966;
78+
79+
public Formats() {
80+
}
81+
82+
@Override
83+
public String toString() {
84+
return "Formats{" +
85+
"e164=" + e164 +
86+
", international=" + international +
87+
", national=" + national +
88+
", rfc3966=" + rfc3966 +
89+
'}';
90+
}
91+
92+
public String getE164() {
93+
return e164;
94+
}
95+
96+
public String getInternational() {
97+
return international;
98+
}
99+
100+
public String getNational() {
101+
return national;
102+
}
103+
104+
public String getRfc3966() {
105+
return rfc3966;
106+
}
107+
}
108+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.messagebird.objects;
2+
3+
import java.math.BigInteger;
4+
5+
public class LookupHlr extends Hlr {
6+
private String countryCode;
7+
8+
public String getCountryCode() {
9+
return countryCode;
10+
}
11+
12+
public void setCountryCode(String countryCode) {
13+
this.countryCode = countryCode;
14+
}
15+
16+
public BigInteger getPhoneNumber() {
17+
return msisdn;
18+
}
19+
20+
public void setPhoneNumber(BigInteger phoneNumber) {
21+
this.msisdn = phoneNumber;
22+
}
23+
24+
public void setReference(String reference) {
25+
this.reference = reference;
26+
}
27+
}

examples/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.messagebird</groupId>
88
<artifactId>examples</artifactId>
9-
<version>1.0.1</version>
9+
<version>1.2.0</version>
1010

1111
<licenses>
1212
<license>
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>com.messagebird</groupId>
2222
<artifactId>messagebird-api</artifactId>
23-
<version>1.1.1</version>
23+
<version>1.2.0</version>
2424
</dependency>
2525
</dependencies>
2626

0 commit comments

Comments
 (0)