Skip to content

Commit

Permalink
Better handling of namespaced resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Jan 18, 2019
1 parent 0bc043b commit 2ead9f1
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/main/java/com/stripe/net/ApiResource.java
Expand Up @@ -86,18 +86,13 @@ private static String className(Class<?> clazz) {
.replaceAll("([a-z0-9])([A-Z])", "$1_$2")
.toLowerCase();

// Issuing or Sigma resources are in their own package. Until we can support adding OBJECT_NAME
// to all classes, we use this dirty trick to properly format the API endpoints
if (clazz.getName().contains("com.stripe.model.issuing.")) {
className = "issuing/" + className;
} else if (clazz.getName().contains("com.stripe.model.sigma.")) {
className = "sigma/" + className;
} else if (clazz.getName().contains("com.stripe.model.radar.")) {
className = "radar/" + className;
} else if (clazz.getName().contains("com.stripe.model.reporting.")) {
className = "reporting/" + className;
} else if (clazz.getName().contains("com.stripe.model.terminal.")) {
className = "terminal/" + className;
// Handle namespaced resources by checking if the class is in a sub-package, and if so prepend
// it to the class name
String[] parts = clazz.getPackage().getName().split("\\.");
if (parts.length == 4)
{
// The first three parts are always "com.stripe.model", the fourth part is the namespace
className = parts[3] + "/" + className;
}

// Handle special cases
Expand Down

0 comments on commit 2ead9f1

Please sign in to comment.