Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/cadox8/XenAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
cadox8 committed Aug 7, 2018
2 parents fe24f17 + c6247fc commit 7a2c8a5
Show file tree
Hide file tree
Showing 10 changed files with 5,937 additions and 25 deletions.
18 changes: 5 additions & 13 deletions Java-API/src/me/cadox8/xenapi/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,15 @@
public class Launcher {

public static void main(String... args) {
XenAPI api = new XenAPI("e65ef8da-ca6a-437c-ab8b-4b2e9e86cd10");
api.setBaseURL("http://192.168.1.2/foro");
XenAPI api = new XenAPI("e65ef8da-ca6a-437c-ab8b-4b2e9e86cd10", "http://192.168.1.2/foro");

Request r = RequestBuilder.newBuilder(RequestType.GET_ACCTIONS).createRequest();
Request r = RequestBuilder.newRequest(RequestType.GET_ACCTIONS).createRequest();

System.out.println("URL: " + r.getURL(api));
System.out.println("Raw: " + XenAPI.getWebInfo(r.getURL(api)) + "\n\n");


api.getReply(r, (Callback<ActionsReply>) (failCause, result)-> {
api.getReply(r, (Callback<ActionsReply>) (failCause, result) -> {
try {
result.checkError();
if (failCause != null) {
failCause.printStackTrace();
} else {
System.out.println("Result: " + result.toString());
}
if (failCause != null) failCause.printStackTrace();
System.out.println("Result: " + result.toString());
} catch (ArgsErrorException e) {
e.printStackTrace();
}
Expand Down
17 changes: 14 additions & 3 deletions Java-API/src/me/cadox8/xenapi/XenAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,26 @@ public class XenAPI {

@Getter private final String token;


/**
* Default constructor
*
* @param token The API token
* @apiNote Default url is http://localhost
*/
public XenAPI(String token) {
this(token, "http://localhost");
}

/**
* Default constructor
*
* @param token The API token
* @param url The URL to the forum
*/
public XenAPI(String token, String url) {
instance = this;

setBaseURL(url);
this.token = token;

httpClient = HttpClientBuilder.create().build();
Expand All @@ -72,8 +83,8 @@ public XenAPI(String token) {
*
* @param url Base URL to the forum
*/
public void setBaseURL(String url) {
if (!url.endsWith("/")) url = url.replaceAll(url, url + "/");
private void setBaseURL(String url) {
if (!url.endsWith("/")) url += "/";
Request.setBASE_URL(url);
}

Expand Down
2 changes: 1 addition & 1 deletion Java-API/src/me/cadox8/xenapi/reply/AbstractReply.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public abstract class AbstractReply {
/**
* Check if you miss any args in the request
*
* @throws ArgsErrorException
* @throws ArgsErrorException(Integer, String, RequestType)
*/
public void checkError() throws ArgsErrorException {
if (getError() != 0) throw new ArgsErrorException(getError(), getMessage(), getRequestType());
Expand Down
35 changes: 35 additions & 0 deletions Java-API/src/me/cadox8/xenapi/reply/LoginReply.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2018.
*
* This file is part of XenAPI <https://github.com/cadox8/XenAPI>.
*
* XenAPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* XenAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.cadox8.xenapi.reply;

import lombok.Getter;
import lombok.ToString;
import me.cadox8.xenapi.request.RequestType;

@ToString
public class LoginReply extends AbstractReply {

@Getter private String hash;

@Override
public RequestType getRequestType() {
return RequestType.AUTHENTICATE;
}
}
2 changes: 1 addition & 1 deletion Java-API/src/me/cadox8/xenapi/request/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Request(RequestType requestType, Map<RequestParam, Object> params) {
* @param username The username to grab
* @return A Request
*/
public Request withGrab_As(String username) {
public Request grab_as(String username) {
grab_as = username;
return this;
}
Expand Down
4 changes: 2 additions & 2 deletions Java-API/src/me/cadox8/xenapi/request/RequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private RequestBuilder(RequestType requestType) {
*
* @see RequestType
*/
public static RequestBuilder newBuilder(RequestType requestType) {
public static RequestBuilder newRequest(RequestType requestType) {
return new RequestBuilder(requestType);
}

Expand Down Expand Up @@ -72,6 +72,6 @@ public Request createRequest() {
}

public Request createRequest(String username) {
return new Request(requestType, params).withGrab_As(username);
return new Request(requestType, params).grab_as(username);
}
}
8 changes: 3 additions & 5 deletions Java-API/src/me/cadox8/xenapi/request/RequestParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
@AllArgsConstructor
public enum RequestParam {

AUTH_USER(RequestType.AUTHENTICATE, "username", String.class),
AUTH_PASS(RequestType.AUTHENTICATE, "password", String.class),
AUTH_USER(RequestType.LOGIN, RequestType.AUTHENTICATE, "username", String.class),
AUTH_PASS(RequestType.LOGIN, RequestType.AUTHENTICATE, "password", String.class),
AUTH_IP(RequestType.AUTHENTICATE, RequestType.LOGIN, "ip_address", String.class),

CREATE_ALERT_USER(RequestType.CREATE_ALERT, "user", String.class),
CREATE_ALERT_CAUSE_USER(RequestType.CREATE_ALERT, "cause_user", String.class),
Expand Down Expand Up @@ -86,9 +87,6 @@ public enum RequestParam {
AVATAR_USER(RequestType.GET_AVATAR, "value", String.class),
AVATAR_SIZE(RequestType.GET_AVATAR, "size", Character.class);


private static final RequestParam[] v = values();

@Getter private final RequestType requestType;
@Getter private final RequestType requestType2;
@Getter private final String queryField;
Expand Down
1 change: 1 addition & 0 deletions Java-API/src/me/cadox8/xenapi/request/RequestType.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
public enum RequestType {

AUTHENTICATE("authenticate", AuthenticateReply.class),
LOGIN("login", LoginReply.class),
LOGOUT("logout", LogoutReply.class),
REGISTER("register", RegisterReply.class),

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
-----

## Summary
* [XenAPI for Xenforo 2.X](#xenapi-for-xenforo-2x)
* [Downloads & Repo](#downloads--repo)
* [Documentation](#documentation)
* [Bug Reporting](#bug-reporting)
Expand All @@ -27,6 +28,11 @@
- [TODO Docs](#todo-docs)
-----

## XenAPI for Xenforo 2.X
This repo contains the Java and the Web API for Xenforo 1.X.

A Java version for Xenforo 2.X is being developed, but I recommend you to use [this](https://xfrocks.com/resources/bd-api-for-xenforo-2-0.36/) for the WebAPI.

## Downloads & Repo
All downloads are hosted in [Github](https://github.com/cadox8/XenAPI/releases).

Expand Down

0 comments on commit 7a2c8a5

Please sign in to comment.