Skip to content

Commit

Permalink
Added API for getting API information
Browse files Browse the repository at this point in the history
  • Loading branch information
jbguillois committed May 27, 2020
1 parent a4a4855 commit c344749
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.github.freebox</groupId>
<artifactId>freebox-java-helper</artifactId>
<packaging>jar</packaging>
<version>1.1.8</version>
<version>1.1.9</version>
<name>FreeBox Java Helper</name>

<properties>
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/github/freebox/api/FreeBoxHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.github.freebox.api.model.LogoutApiResponse;
import com.github.freebox.api.model.ServerApiVersionApiResponse;
import com.github.freebox.api.model.ServerAuthorizeStatusApiResponse;
import com.github.freebox.api.model.data.ApiInformation;
import com.github.freebox.api.model.data.ApplicationDefinition;
import com.github.freebox.api.model.data.CallEntry;
import com.github.freebox.api.model.data.L2Identification;
Expand Down Expand Up @@ -300,6 +301,19 @@ public List<CallEntry> getCallLog() {

return null;
}

/**
* <p>Returns technical information about the Freebox server API
* </p>
* @return The Freebox Server API information
*/
public ApiInformation getApiInformation() {

HttpResponse<ApiInformation> response = Unirest.get(serverApiMetadata.getApiEndpoint()+"/api_version/")
.asObject(ApiInformation.class);

return response.getBody();
}

/**
* <p>Returns technical information about the Freebox server (version, CPU temperature, model...)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.github.freebox.api.model.data;

public class ApiInformation {
private String box_model_name;
private String api_base_url;
private String https_port;
private String device_name;
private String https_available;
private String box_model;
private String api_domain;
private String uid;
private String api_version;
private String device_type;

public String getBoxModelName() {
return box_model_name;
}
public String getApiBaseUrl() {
return api_base_url;
}
public String getHttpsPort() {
return https_port;
}
public String getDeviceName() {
return device_name;
}
public boolean isHttpsAvailable() {
if("true".contentEquals(https_available))
return true;
return false;
}
public String getBoxModel() {
return box_model;
}
public String getApiDomain() {
return api_domain;
}
public String getUid() {
return uid;
}
public String getApiVersion() {
return api_version;
}
public String getDeviceType() {
return device_type;
}

public String getApiEndpoint() {
StringBuffer buf = new StringBuffer();

if(isHttpsAvailable())
buf.append("https://");
else
buf.append("http://");
buf.append(getApiDomain());
buf.append(":");
buf.append(getHttpsPort());
buf.append(getApiBaseUrl());
buf.append("v");
buf.append(getApiVersion().substring(0,1));


return buf.toString();
}

public String toString() {
StringBuffer buf = new StringBuffer();

buf.append(getDeviceName());
buf.append(" "+getUid());
buf.append(" (");
buf.append(getDeviceType());
buf.append("), ");

buf.append("API URL: ");
buf.append(getApiEndpoint());

return buf.toString();
}
}

0 comments on commit c344749

Please sign in to comment.