@ThreadSafe
public class Sphere
extends java.lang.Object
To obtain a thread-safe singleton instance of this class that can be used from all controllers
in your application, use the static method getInstance
.
Modifier and Type | Method and Description |
---|---|
CategoryTree |
categories()
All categories in the project, represented as an in-memory tree.
|
SphereClient |
client()
Provides access to the low-level Sphere Java client, may you need it to perform tasks that
are not common in a typical online shop scenario.
|
CommentService |
comments()
Sphere HTTP API for working with product comments.
|
CurrentCart |
currentCart()
Returns a Cart API object for the current request.
|
CurrentCustomer |
currentCustomer()
Customer object for the current session.
|
CustomerService |
customers()
Sphere HTTP API for working with customers in a given project.
|
CustomObjectService |
customObjects()
Sphere HTTP API for storing arbitrary JSON data.
|
static Sphere |
getInstance()
Returns a thread-safe client for accessing the Sphere APIs.
|
InventoryService |
inventory()
Sphere HTTP API for working with product inventory.
|
boolean |
isLoggedIn()
Returns true if a customer is currently logged in, false otherwise.
|
boolean |
login(java.lang.String email,
java.lang.String password)
Authenticates a customer and stores customer id in the session.
|
play.libs.F.Promise<SphereResult<SignInResult>> |
loginAsync(java.lang.String email,
java.lang.String password)
Authenticates an existing customer asynchronously and store customer id in the session when finished.
|
void |
logout()
Removes the customer and cart information from the session.
|
OrderService |
orders()
Sphere HTTP API for working with orders.
|
ProductService |
products()
Sphere HTTP API for working with products.
|
ReviewService |
reviews()
Sphere HTTP API for working with product reviews.
|
ShippingMethodService |
shippingMethods()
Sphere HTTP API for working with shipping methods.
|
SignInResult |
signup(SignUpBuilder signUpBuilder) |
SignInResult |
signup(java.lang.String email,
java.lang.String password,
CustomerName customerName)
Creates and authenticates a new customer
(you don't have to to call
login explicitly). |
play.libs.F.Promise<SphereResult<SignInResult>> |
signupAsync(SignUpBuilder signUpBuilder) |
play.libs.F.Promise<SphereResult<SignInResult>> |
signupAsync(java.lang.String email,
java.lang.String password,
CustomerName customerName)
Creates and authenticates a new customer asynchronously
(you don't have to to call
login explicitly). |
public ProductService products()
public CategoryTree categories()
public OrderService orders()
public CustomerService customers()
currentCustomer()
for working with the currently logged in customer.public ReviewService reviews()
public CommentService comments()
public InventoryService inventory()
public ShippingMethodService shippingMethods()
public CustomObjectService customObjects()
public SphereClient client()
Using the shop client, you can access all Sphere HTTP API endpoints, so you can for example create shopping carts freely, fetch orders for any customer, etc.
@Nonnull public CurrentCart currentCart()
public static Sphere getInstance()
public boolean isLoggedIn()
currentCustomer() != null
but more readable.public CurrentCustomer currentCustomer()
public boolean login(java.lang.String email, java.lang.String password)
currentCustomer()
will always return a CurrentCustomer
instance,
until logout()
is called.public play.libs.F.Promise<SphereResult<SignInResult>> loginAsync(java.lang.String email, java.lang.String password)
public SignInResult signup(java.lang.String email, java.lang.String password, CustomerName customerName)
login
explicitly).EmailAlreadyInUseException
- if the email is already taken.public SignInResult signup(SignUpBuilder signUpBuilder)
public play.libs.F.Promise<SphereResult<SignInResult>> signupAsync(java.lang.String email, java.lang.String password, CustomerName customerName)
login
explicitly).EmailAlreadyInUseException
if the email is already taken. public play.libs.F.Promise<SphereResult<SignInResult>> signupAsync(SignUpBuilder signUpBuilder)
public void logout()
After calling logout, currentCustomer()
will return null.
Make sure you don't keep old CurrentCustomer
instances around as they become invalid after logout.