Skip to content

Creating interface for API to facilitate unit testing #1

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions src/io/userapp/client/IUserAppAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.userapp.client;

import io.userapp.client.exceptions.InvalidMethodException;
import io.userapp.client.exceptions.InvalidServiceException;
import io.userapp.client.exceptions.ServiceException;
import io.userapp.client.exceptions.TransportException;
import io.userapp.client.exceptions.UserAppException;

public interface IUserAppAPI {

public void setOptions(UserApp.ClientOptions options);

public UserApp.ClientOptions getOptions();

/* Set the API method */
public IUserAppAPI method(String name);

/* Add an input parameter */
public IUserAppAPI parameter(String name, Object value);

/* Perform the API call */
public UserApp.Result call() throws UserAppException,
TransportException, ServiceException, InvalidServiceException,
InvalidMethodException;

}
10 changes: 5 additions & 5 deletions src/io/userapp/client/UserApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public boolean toBoolean() {
}

/* API wrapper class */
public static class API {
public static class API implements IUserAppAPI {
private UserApp.ClientOptions options;
RestfulContext restfulContext = new RestfulContext();
URI serviceUrl;
Expand All @@ -205,7 +205,7 @@ public API(String appId, String token) {
public API(UserApp.ClientOptions options) {
this.setOptions(options);
}

public void setOptions(UserApp.ClientOptions options) {
this.options = options;
this.restfulContext.setBasicAuthenticationCredentials(new UserCredentials(
Expand All @@ -215,20 +215,20 @@ public void setOptions(UserApp.ClientOptions options) {
String.format("%s://%s/v%d/", (this.options.secure ? "https" : "http"), this.options.baseAddress, this.options.version)
);
}

public UserApp.ClientOptions getOptions() {
return this.options;
}

/* Set the API method */
public UserApp.API method(String name) {
public IUserAppAPI method(String name) {
this.methodName = name;
this.parameters.clear();
return this;
}

/* Add an input parameter */
public UserApp.API parameter(String name, Object value) {
public IUserAppAPI parameter(String name, Object value) {
this.parameters.add(new UserApp.Parameter(name, value));
return this;
}
Expand Down
3 changes: 2 additions & 1 deletion src/io/userapp/client/demo/Demo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;

import io.userapp.client.IUserAppAPI;
import io.userapp.client.UserApp;
import io.userapp.client.exceptions.*;

Expand All @@ -22,7 +23,7 @@ public static void main(String[] args) {
options.throwErrors = false;
UserApp.API api = new UserApp.API(options);*/

UserApp.API api = new UserApp.API("YOUR-USERAPP-APP-ID");
IUserAppAPI api = new UserApp.API("YOUR-USERAPP-APP-ID");

/*
* Sign up a new user
Expand Down