Live demo
Here you can find live demo of the Camera store sample application. This is the application we are going to build here.
Prerequisites
To follow along with this tutorial, you have to have:
- Active account in Tradenity (sign up here )
- Create the sample “Camera store”, and load the sample data (This option is available on the create store page).
- Have a working Java development environment (JDK 1.7 installed, IDE)
- Basic familiarity with the Spring MVC framework, prior experience with Spring Boot will help.
Create skeleton project
We will use spring boot as it makes it easy to create spring based applications. go to start.spring.io,
specify the name of the application, add Web
, Security
to the dependencies, and press download. Unzip the downloaded file, and open the project in your favorite IDE.
Add SDK to your dependencies
The SDK is available through our maven repository, You can install it using any compatible tool.
Add this repository definition to your maven pom.xml
file.
<repository>
<id>tradenity-public</id>
<name>tradenity-public-releases</name>
<url>http://artifacts.tradenity.com/artifactory/tradenity-release-public</url>
</repository>
Now you can add the required dependencies
<dependency>
<groupId>com.tradenity</groupId>
<artifactId>java-sdk</artifactId>
<version>0.8.1</version>
</dependency>
<dependency>
<groupId>com.tradenity</groupId>
<artifactId>java-sdk-spring-ext</artifactId>
<version>0.8.0</version>
</dependency>
Setup your credentials
First of all, you have to get API keys for your store, you can find it in your store Edit
page.
To get there navigate to the stores list page, click on the Edit
button next to your store name, scroll down till you find the API Keys
section.
In the application.properties file, insert the following properties, Make sure to replace the api keys with the ones for your store, otherwise you will get authentication error
tradenity.publicKey=pk_1234567 tradenity.secretKey=sk_1234567
Initialize the library
You can easily initialize the library by adding @EnableTradenity
annotation on any @Configuration
class.
Our application uses Spring Boot framework, so it is appropriate to add this annotation to the application class
@SpringBootApplication
@EnableTradenity
public class ShopApplication {
public static void main(String[] args) {
SpringApplication.run(ShopApplication.class, args);
}
}
@EnableTradenity
annotation initialize a TradenityClient
with your Store’s credentials, and register it as a spring bean.
It also initialize all the Tradenity SDK’s services and register them as spring beans.
Make your First call
The tradenity SDK is organized into a group of *Service
classes, each contains the operation for a specific entity model,
for example to perform operations related to the Brand
entity you can use the associated BrandService
.
Using spring’s standard spring dependency injection mechanism you can inject any service using either @Autowire
or @Inject
in your calling class.
@Autowired
BrandService brandService;
Now, just call any method in your code.
Brand brand = brandService.findById("1243-9786786-jhgjtu-789s6i");