Skip to content

Commit

Permalink
Disabled control parental API when version>v6
Browse files Browse the repository at this point in the history
  • Loading branch information
jbguillois committed Jul 21, 2020
1 parent 32ee282 commit faf59b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main/java/com/github/freebox/api/FreeBoxHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,16 @@ public LANHost getLANHostByMacAddr(String macAddr) {
}

/**
* <p>Returns the parental filter configuration
* <p>Returns the parental filter configuration.
* Supported only on Freebox with API version up to v6.
* </p>
* @return The parental filter configuration
*/
public ParentalFilterConfiguration getParentalFilterConfiguration() {

// Bail out if api version is > v6
if(serverApiMetadata.getApiVersionNumber()>6) return new ParentalFilterConfiguration();

HttpResponse<GetParentalFilterConfigurationResponse> response = Unirest.get(serverApiMetadata.getApiEndpoint()+"/parental/config/")
.header(X_FBX_APP_AUTH, freeboxSessionToken)
.asObject(GetParentalFilterConfigurationResponse.class);
Expand All @@ -516,6 +520,9 @@ public ParentalFilterConfiguration getParentalFilterConfiguration() {
*/
public ParentalFilterConfiguration setParentalFilterConfiguration(String mode) {

// Bail out if api version is > v6
if(serverApiMetadata.getApiVersionNumber()>6) return new ParentalFilterConfiguration();

// Get existing mode
HttpResponse<GetParentalFilterConfigurationResponse> response = Unirest.get(serverApiMetadata.getApiEndpoint()+"/parental/config/")
.header(X_FBX_APP_AUTH, freeboxSessionToken)
Expand Down Expand Up @@ -569,6 +576,9 @@ public List<ParentalFilterRule> getParentalFilterRules() {
*/
public ParentalFilterRule addParentalFilterRule(ParentalFilterRule newRule) {

// Bail out if api version is > v6
if(serverApiMetadata.getApiVersionNumber()>6) return null;

HttpResponse<GetParentalFilterRuleResponse> response = Unirest.post(serverApiMetadata.getApiEndpoint()+"/parental/filter/")
.header(X_FBX_APP_AUTH, freeboxSessionToken)
.header("Content-Type", "application/json")
Expand All @@ -589,6 +599,9 @@ public ParentalFilterRule addParentalFilterRule(ParentalFilterRule newRule) {
*/
public boolean deleteParentalFilterRule(String ruleId) {

// Bail out if api version is > v6
if(serverApiMetadata.getApiVersionNumber()>6) return false;

HttpResponse<GetParentalFilterRuleResponse> response = Unirest.delete(serverApiMetadata.getApiEndpoint()+"/parental/filter/"+ruleId)
.header(X_FBX_APP_AUTH, freeboxSessionToken)
.header("Content-Type", "application/json")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.freebox.api.model;

import org.apache.commons.lang3.StringUtils;

public class ServerApiVersionApiResponse {
private String box_model_name;
private String api_base_url;
Expand Down Expand Up @@ -41,6 +43,11 @@ public String getUid() {
public String getApiVersion() {
return api_version;
}
public int getApiVersionNumber() {
if(StringUtils.isAlpha(api_version)) return 0;
if(StringUtils.isNumeric(api_version.substring(0, 1))) return Integer.valueOf(api_version.substring(0, 1)).intValue();
return 0;
}
public String getDeviceType() {
return device_type;
}
Expand Down

0 comments on commit faf59b4

Please sign in to comment.