Skip to content

Add support for the Lookup API #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ If you are using maven simply add the messagebird API to your dependencies like
<dependency>
<groupId>com.messagebird</groupId>
<artifactId>messagebird-api</artifactId>
<version>1.1.1</version>
<version>1.2.0</version>
</dependency>
```

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

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

Please see the other examples for a complete overview of all the available API calls.
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.messagebird</groupId>
<artifactId>messagebird-api</artifactId>
<version>1.1.1</version>
<version>1.2.0</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
122 changes: 122 additions & 0 deletions api/src/main/java/com/messagebird/MessageBirdClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class MessageBirdClient {
private static final String MESSAGESPATH = "/messages";
private static final String VOICEMESSAGESPATH = "/voicemessages";
private static final String VERIFYPATH = "/verify";
private static final String LOOKUPPATH = "/lookup";
private static final String LOOKUPHLRPATH = "/lookup/%s/hlr";
private MessageBirdService messageBirdService;

public MessageBirdClient(final MessageBirdService messageBirdService) {
Expand Down Expand Up @@ -385,4 +387,124 @@ public void deleteVerifyObject(String id) throws NotFoundException, GeneralExcep
}
messageBirdService.deleteByID(VERIFYPATH, id);
}

/**
* Send a Lookup request
*
* @param Lookup
* @return Lookup
* @throws UnauthorizedException
* @throws GeneralException
* @throws NotFoundException
*/
public Lookup viewLookup(final Lookup lookup) throws UnauthorizedException, GeneralException, NotFoundException {
if (lookup.getPhoneNumber() == null) {
throw new IllegalArgumentException("Phonenumber must be specified.");
}
final Map<String, Object> params = new LinkedHashMap<String, Object>();
if (lookup.getCountryCode() != null) {
params.put("countryCode", lookup.getCountryCode());
}
return messageBirdService.requestByID(LOOKUPPATH, String.valueOf(lookup.getPhoneNumber()), params, Lookup.class);
}

/**
* Send a Lookup request
*
* @param phonenumber
* @return Lookup
* @throws UnauthorizedException
* @throws GeneralException
*/
public Lookup viewLookup(final BigInteger phonenumber) throws UnauthorizedException, GeneralException, NotFoundException {
if (phonenumber == null) {
throw new IllegalArgumentException("Phonenumber must be specified.");
}
final Lookup lookup = new Lookup(phonenumber);
return this.viewLookup(lookup);
}

/**
* Request a Lookup HLR (lookup)
*
* @param LookupHlr
* @return lookupHlr
* @throws UnauthorizedException
* @throws GeneralException
*/
public LookupHlr requestLookupHlr(final LookupHlr lookupHlr) throws UnauthorizedException, GeneralException {
if (lookupHlr.getPhoneNumber() == null) {
throw new IllegalArgumentException("Phonenumber must be specified.");
}
if (lookupHlr.getReference() == null) {
throw new IllegalArgumentException("Reference must be specified.");
}
final Map<String, Object> payload = new LinkedHashMap<String, Object>();
payload.put("phoneNumber", lookupHlr.getPhoneNumber());
payload.put("reference", lookupHlr.getReference());
if (lookupHlr.getCountryCode() != null) {
payload.put("countryCode", lookupHlr.getCountryCode());
}
return messageBirdService.sendPayLoad(String.format(LOOKUPHLRPATH, lookupHlr.getPhoneNumber()), payload, LookupHlr.class);
}

/**
* Request a Lookup HLR (lookup)
*
* @param phonenumber
* @param reference
* @return lookupHlr
* @throws UnauthorizedException
* @throws GeneralException
*/
public LookupHlr requestLookupHlr(final BigInteger phonenumber, final String reference) throws UnauthorizedException, GeneralException {
if (phonenumber == null) {
throw new IllegalArgumentException("Phonenumber must be specified.");
}
if (reference == null) {
throw new IllegalArgumentException("Reference must be specified.");
}
final LookupHlr lookupHlr = new LookupHlr();
lookupHlr.setPhoneNumber(phonenumber);
lookupHlr.setReference(reference);
return this.requestLookupHlr(lookupHlr);
}

/**
* View a Lookup HLR (lookup)
*
* @param LookupHlr
* @return LookupHlr
* @throws UnauthorizedException
* @throws GeneralException
* @throws NotFoundException
*/
public LookupHlr viewLookupHlr(final LookupHlr lookupHlr) throws UnauthorizedException, GeneralException, NotFoundException {
if (lookupHlr.getPhoneNumber() == null) {
throw new IllegalArgumentException("Phonenumber must be specified");
}
final Map<String, Object> params = new LinkedHashMap<String, Object>();
if (lookupHlr.getCountryCode() != null) {
params.put("countryCode", lookupHlr.getCountryCode());
}
return messageBirdService.requestByID(String.format(LOOKUPHLRPATH, lookupHlr.getPhoneNumber()), "", params, LookupHlr.class);
}

/**
* View a Lookup HLR (lookup)
*
* @param phonenumber
* @return LookupHlr
* @throws UnauthorizedException
* @throws GeneralException
* @throws NotFoundException
*/
public LookupHlr viewLookupHlr(final BigInteger phonenumber) throws UnauthorizedException, GeneralException, NotFoundException {
if (phonenumber == null) {
throw new IllegalArgumentException("Phonenumber must be specified");
}
final LookupHlr lookupHlr = new LookupHlr();
lookupHlr.setPhoneNumber(phonenumber);
return this.viewLookupHlr(lookupHlr);
}
}
4 changes: 2 additions & 2 deletions api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class MessageBirdServiceImpl implements MessageBirdService {
private static final List<String> REQUESTMETHODS = Arrays.asList(new String[]{"GET", "POST", "DELETE"});
private final String accessKey;
private final String serviceUrl = "https://rest.messagebird.com";
private final String clientVersion = "1.1.1";
private final String clientVersion = "1.2.0";
private final String userAgentString = "MessageBird/Java ApiClient/" + clientVersion;
private Proxy proxy = null;

Expand Down Expand Up @@ -65,7 +65,7 @@ public <R> R requestByID(String request, String id, Map<String, Object> params,
if (id != null) {
path = "/" + id;
}
// Make rest of get request
// Make rest of GET request
String queryParams = "";
if (!params.isEmpty()) {
queryParams = "?" + getPathVariables(params);
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/com/messagebird/objects/Hlr.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
public class Hlr {
private String id;
private String href;
private BigInteger msisdn;
protected BigInteger msisdn;
private String network;
private String reference;
protected String reference;
private String status;
private Date createdDatetime;
private Date statusDatetime;
Expand Down
108 changes: 108 additions & 0 deletions api/src/main/java/com/messagebird/objects/Lookup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.messagebird.objects;

import java.io.Serializable;
import java.math.BigInteger;

public class Lookup implements Serializable {

private static final long serialVersionUID = 8927014359452296030L;

private String href;
private String countryCode;
private Integer countryPrefix;
private BigInteger phoneNumber;
private String type;
private Formats formats;
private LookupHlr hlr;

@Override
public String toString() {
return "Lookup{" +
"href=" + href +
", countryCode=" + countryCode +
", countryPrefix=" + countryPrefix +
", phoneNumber=" + phoneNumber +
", type=" + type +
", formats=" + formats +
", hlr=" + hlr +
"}";
}

public Lookup() {
}

public Lookup(BigInteger phoneNumber) {
this.phoneNumber = phoneNumber;
}

public String getHref() {
return href;
}

public String getCountryCode() {
return countryCode;
}

public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}

public Integer getCountryPrefix() {
return countryPrefix;
}

public BigInteger getPhoneNumber() {
return phoneNumber;
}

public String getType() {
return type;
}

public Formats getFormats() {
return formats;
}

public Hlr getHlr() {
return hlr;
}

static public class Formats implements Serializable {

private static final long serialVersionUID = 2165916336570704972L;

private String e164;
private String international;
private String national;
private String rfc3966;

public Formats() {
}

@Override
public String toString() {
return "Formats{" +
"e164=" + e164 +
", international=" + international +
", national=" + national +
", rfc3966=" + rfc3966 +
'}';
}

public String getE164() {
return e164;
}

public String getInternational() {
return international;
}

public String getNational() {
return national;
}

public String getRfc3966() {
return rfc3966;
}
}
}
27 changes: 27 additions & 0 deletions api/src/main/java/com/messagebird/objects/LookupHlr.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.messagebird.objects;

import java.math.BigInteger;

public class LookupHlr extends Hlr {
private String countryCode;

public String getCountryCode() {
return countryCode;
}

public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}

public BigInteger getPhoneNumber() {
return msisdn;
}

public void setPhoneNumber(BigInteger phoneNumber) {
this.msisdn = phoneNumber;
}

public void setReference(String reference) {
this.reference = reference;
}
}
4 changes: 2 additions & 2 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.messagebird</groupId>
<artifactId>examples</artifactId>
<version>1.0.1</version>
<version>1.2.0</version>

<licenses>
<license>
Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>com.messagebird</groupId>
<artifactId>messagebird-api</artifactId>
<version>1.1.1</version>
<version>1.2.0</version>
</dependency>
</dependencies>

Expand Down
Loading