-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d995432
commit c065a7d
Showing
18 changed files
with
728 additions
and
418 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package ci.bamba.regis; | ||
|
||
import java.util.HashMap; | ||
import java.util.UUID; | ||
|
||
import ci.bamba.regis.exceptions.RequestException; | ||
import ci.bamba.regis.models.ApiCredentials; | ||
import ci.bamba.regis.models.ApiUser; | ||
import io.reactivex.Observable; | ||
|
||
public class Provisioning { | ||
|
||
private String subscriptionKey; | ||
private String baseUrl; | ||
private Environment environment; | ||
|
||
Provisioning(String subscriptionKey, String baseUrl) { | ||
this.subscriptionKey = subscriptionKey; | ||
this.baseUrl = baseUrl; | ||
this.environment = Environment.SANDBOX; | ||
} | ||
|
||
public Environment getEnvironment() { | ||
return environment; | ||
} | ||
|
||
public String getSubscriptionKey() { | ||
return subscriptionKey; | ||
} | ||
|
||
public String getBaseUrl() { | ||
return baseUrl; | ||
} | ||
|
||
public Observable<String> createApiUser() { | ||
return createApiUser("string"); | ||
} | ||
|
||
public Observable<String> createApiUser(String providerCallbackHost) { | ||
String referenceId = UUID.randomUUID().toString(); | ||
HashMap<String, String> body = new HashMap<>(); | ||
body.put("providerCallbackHost", providerCallbackHost); | ||
return RestClient | ||
.getService(getBaseUrl()) | ||
.createApiUser(getSubscriptionKey(), referenceId, body) | ||
.map(response -> { | ||
if (response.code() == 201) { | ||
return referenceId; | ||
} else { | ||
throw new RequestException(response.code(), response.message()); | ||
} | ||
}); | ||
} | ||
|
||
public Observable<ApiUser> getApiUser(String referenceId) { | ||
return RestClient.getService(getBaseUrl()) | ||
.getApiUser(getSubscriptionKey(), referenceId) | ||
.map(response -> { | ||
if (response.code() == 200) { | ||
return response.body(); | ||
} else { | ||
throw new RequestException(response.code(), response.message()); | ||
} | ||
}); | ||
} | ||
|
||
public Observable<ApiCredentials> createApiKey(String referenceId) { | ||
return RestClient | ||
.getService(getBaseUrl()) | ||
.createApiKey(getSubscriptionKey(), referenceId) | ||
.map(response -> { | ||
if (response.code() == 201) { | ||
if (response.body() != null) { | ||
return new ApiCredentials(referenceId, response.body().getApiKey()); | ||
} else { | ||
throw new RequestException(response.code(), response.message()); | ||
} | ||
} else { | ||
throw new RequestException(response.code(), response.message()); | ||
} | ||
}); | ||
} | ||
|
||
} |
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
Oops, something went wrong.