Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ jobs:
if: ${{ github.ref == 'refs/heads/main' }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: >-
mvn --batch-mode verify sonar:sonar
-Dsonar.java.jdkHome=$JAVA_HOME_11_X64
-Dsonar.projectKey=pgmarc_space-java-client
run: mvn --projects space-client --batch-mode verify sonar:sonar \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.organization=pgmarc \
-Dsonar.projectKey=pgmarc_space-java-client \
-Dsonar.java.jdkHome=$JAVA_HOME_11_X64 \
-Pcoverage
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ buildNumber.properties

# VSCode

.vscode
.vscode

# Intellij
.idea/
*.iml
*.iws

# Mac
.DS_Store
23 changes: 23 additions & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.github.pgmarc.space</groupId>
<artifactId>space-client-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>space-client-examples</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>space-client-examples</name>

<dependencies>
<dependency>
<groupId>io.github.pgmarc.space</groupId>
<artifactId>space-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package io.github.pgmarc.space.examples;

import java.io.IOException;
import java.util.Objects;

import io.github.pgmarc.space.SpaceClient;
import io.github.pgmarc.space.contracts.Subscription;
import io.github.pgmarc.space.contracts.SubscriptionRequest;
import io.github.pgmarc.space.contracts.SubscriptionUpdateRequest;
import io.github.pgmarc.space.contracts.UserContact;
import okhttp3.*;

/**
* In this example you will be subscribing to a service with only a single
* plan available. After that you will update your subscription to the
* lastest available version of the service pricing.
*
* <p>
* You have the corresponding <code>Pricing2Yaml</code> files in
* <code>src/main/resources/single</code> folder.
* </p>
*/
public class SingleService {

/**
* Before executing the code snippets you have to do the following:
* <ul>
* <li>Start a SPACE instance</li>
* <li>Get a <code>MANAGER</code> or <code>ADMIN</code> api key</li>
* </ul>
*
* You are free to experiment with the API and adjust the code to your needs.
* Happy Hacking :)
*
* @see <a href="https://github.com/isa-group/Pricing4SaaS-docs"></a>
*
*/
public static void main(String[] args) throws IOException {

String apiKey = Objects.requireNonNull(System.getenv("SPACE_API_KEY"),
"You need to set SPACE_API_KEY env variable") ;

SpaceClient client = SpaceClient.builder("localhost", apiKey).build();

// A subscription at least requires a user id and a username
String userId = "4427d118-073d-4da2-a145-f77a75b52595";
String username = "alex";
UserContact contact = UserContact.builder(userId, username).build();

// But, you can provide more user contact information if you want
UserContact contact2 = UserContact
.builder("3f5f934c-951b-4a2d-ad10-b1679ac9b7ba", "janedoe")
.firstName("Jane")
.lastName("Doe")
.email("janedoe@example.com")
.phone("280-689-4646").build();

SubscriptionRequest subReq = SubscriptionRequest.builder(contact)
.startService("WireMock", "2024")
.plan("Enterprise")
.endService()
.build();

Subscription newSubscription = client.contracts().addContract(subReq);
System.out.println(newSubscription);

Subscription subscription = client.contracts().getContractByUserId(userId);
System.out.println(subscription);

// Updating (novating) the contract to version of 2025
SubscriptionUpdateRequest upReq = SubscriptionUpdateRequest.builder()
.service("WireMock", "2025")
.plan("Enterprise")
.add();

Subscription updatedSubscription = client.contracts().updateContractByUserId(userId, upReq);
System.out.println(updatedSubscription);
}

}
60 changes: 60 additions & 0 deletions examples/src/main/resources/single/2024-03-02-wiremock.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
saasName: WireMock
syntaxVersion: "3.0"
createdAt: 2025-08-23
version: "2024"
currency: USD
url: https://web.archive.org/web/20240302003353/https://www.wiremock.io/get-pricing
features:
mockAPI:
type: DOMAIN
valueType: BOOLEAN
defaultValue: true
expression:
pricingContext['features']['mockAPI'] &&
(subscriptionContext['mockAPICallsLimit'] < pricingContext['usageLimits']['mockAPICallsLimit'])
RBAC:
type: DOMAIN
valueType: BOOLEAN
defaultValue: false
expression: pricingContext['features']['RBAC']
gitSync:
type: DOMAIN
valueType: BOOLEAN
defaultValue: false
expression: pricingContext['features']['gitSync']
usageLimits:
mockAPICallsLimit:
type: RENEWABLE
valueType: NUMERIC
defaultValue: 1000
period:
value: 1
unit: MONTH
unit: call/month
linkedFeatures:
- mockAPI
maxUsers:
type: NON_RENEWABLE
valueType: NUMERIC
trackable: true
defaultValue: 1
unit: user
plans:
Free:
description: $0 free forever. No credit card required.
price: 0
features: null
usageLimits: null
Enterprise:
description: For larger teams or API Volume
price: Get in touch
features:
RBAC:
value: true
gitSync:
value: true
usageLimits:
mockAPICallsLimit:
value: .inf
maxUsers:
value: .inf
79 changes: 79 additions & 0 deletions examples/src/main/resources/single/2025-08-23-wiremock.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
saasName: WireMock
syntaxVersion: "3.0"
createdAt: 2025-08-23
version: "2025"
currency: USD
url: https://web.archive.org/web/20250823073700/https://www.wiremock.io/get-pricing
features:
mockAPI:
description: Get rid of testing environment infrastructure bills.
type: DOMAIN
valueType: BOOLEAN
defaultValue: true
expression:
pricingContext['features']['mockAPI'] &&
(subscriptionContext['mockAPICallsLimit'] < pricingContext['usageLimits']['mockAPICallsLimit'])
RBAC:
description: Connect your SSO provider for easy access
type: DOMAIN
valueType: BOOLEAN
defaultValue: false
expression: pricingContext['features']['RBAC']
gitSync:
description: Use an OpenAPI spec in Git as the source of truth for your mock APis
type: DOMAIN
valueType: BOOLEAN
defaultValue: false
expression: pricingContext['features']['gitSync']
testDataImport:
description: Connect external data sources to instantly bring your test data into your mock APIs
type: DOMAIN
valueType: BOOLEAN
defaultValue: false
expression: pricingContext['features']['testDataImport']
fakeDataGeneration:
description: Choose from hundreds of patterns tor randomly generating critical test data
type: DOMAIN
valueType: BOOLEAN
defaultValue: false
expression: pricingContext['features']['fakeDataGeneration']
usageLimits:
mockAPICallsLimit:
type: RENEWABLE
valueType: NUMERIC
defaultValue: 1000
period:
value: 1
unit: MONTH
unit: call/month
linkedFeatures:
- mockAPI
maxUsers:
type: NON_RENEWABLE
valueType: NUMERIC
trackable: true
defaultValue: 1
unit: user
plans:
Free:
description: $0 free forever. No credit card required.
price: 0
features: null
usageLimits: null
Enterprise:
description: For larger teams or API Volume
price: Get in touch
features:
RBAC:
value: true
gitSync:
value: true
testDataImport:
value: true
fakeDataGeneration:
value: true
usageLimits:
mockAPICallsLimit:
value: .inf
maxUsers:
value: .inf
Loading