-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sonarr v4 support + update dependencies + refactor api urls across (
#86) Arr apis
- Loading branch information
Showing
32 changed files
with
672 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.botdarr.api; | ||
|
||
import com.botdarr.Config; | ||
import com.botdarr.connections.RequestBuilder; | ||
import org.apache.logging.log4j.util.Strings; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ArrRequestBuilder { | ||
private final String urlConfigName; | ||
private final String urlBaseConfigName; | ||
private final String tokenName; | ||
private final RequestBuilder requestBuilder = new RequestBuilder(); | ||
public ArrRequestBuilder(String urlConfigName, String urlBaseConfigName, String tokenName) { | ||
this.urlConfigName = urlConfigName; | ||
this.urlBaseConfigName = urlBaseConfigName; | ||
this.tokenName = tokenName; | ||
} | ||
|
||
private RequestBuilder tokens(RequestBuilder requestBuilder) { | ||
//TODO: which *arr's actually need the api key in path and headers? (this is likely a side effect from one | ||
//of the apis requiring one or the other and me being lazy) | ||
return requestBuilder.param("apiKey", Config.getProperty(this.tokenName)) | ||
.headers("X-Api-Key", Config.getProperty(this.tokenName)); | ||
} | ||
|
||
private String getRadarrHost() { | ||
String host = Config.getProperty(this.urlConfigName); | ||
String rawUrlBase = Config.getProperty(this.urlBaseConfigName); | ||
String urlBase = Strings.isBlank(rawUrlBase) ? "" : "/" + rawUrlBase; | ||
return host + urlBase + getApiSuffix(); | ||
} | ||
|
||
public String getApiSuffix() { | ||
return "/api/"; | ||
} | ||
|
||
public RequestBuilder buildGet(String path) { | ||
return buildGet(path, new HashMap<>()); | ||
} | ||
|
||
public RequestBuilder buildGet(String path, Map<String, String> params) { | ||
for (Map.Entry<String, String> entry : params.entrySet()) { | ||
this.requestBuilder.param(entry.getKey(), entry.getValue()); | ||
} | ||
RequestBuilder requestBuilder = this.requestBuilder.host(getRadarrHost() + path); | ||
return this.tokens(requestBuilder); | ||
} | ||
|
||
public RequestBuilder buildPost(String path, String postBody) { | ||
RequestBuilder requestBuilder = this.requestBuilder.host(getRadarrHost() + path).post(postBody); | ||
return this.tokens(requestBuilder); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.