#SPHERE IO ANDROID SDK
Android SDK for Sphere API
The sphere-jvm-sdk is built on Java 8. Android supports only up to Java 7. This version was built with an Android app in mind.
This project connects with the Sphere API using Retrofit and RxJava Observables.
// build auth config
SphereAuthConfig sphereAuthConfig = new SphereAuthConfig.Builder()
.authUrl("<AUTH_URL>")
.projectKey("<PROJECT_KEY>")
.clientId("<CLIENT_ID>")
.clientSecret("<CLIENT_SECRET>")
.build();
// generate a Tokens object using the auth config
AuthService authService = new AuthServiceImpl(sphereAuthConfig);
Tokens tokens = authService.getAccessTokenObs().toBlocking().first();
// build the API configuration object using the auth config and the tokens object
SphereApiConfig sphereApiConfig = new SphereApiConfig.Builder()
.apiUrl("<API_ENDPOINT_URL>")
.authConfig(sphereAuthConfig)
.tokens(tokens)
.build();
// build the client
SphereClient sphereClient = new SphereClient(sphereApiConfig);
// create a product type
ProductTypeService productTypeService = new ProductTypeServiceImpl(sphereClient);
ProductTypeDraft productTypeDraft = new ProductTypeDraft.Builder()
.name("Cheap Product")
.description("So cheap lol")
.build();
ProductType productType = productTypeService.createProductTypeObs(productTypeDraft).toBlocking().first();
// create a product using the new product type
ProductService productService = new ProductServiceImpl(sphereClient);
Product product = productService.createProductObs(new ProductDraft.Builder()
.name(new LocalizedName(Locale.ENGLISH.getLanguage(), "Sample Product"))
.slug(new LocalizedSlug(Locale.ENGLISH.getLanguage(), new Slugify().slugify("Sample Product 1")))
.productType(productType)
.build()).toBlocking().first();
// you will need to convert your image/JPEG to byte[]
productService.uploadImage(product, imageByteArray).toBlocking().first();