Download and install the ruby SDK and intro to its structure.

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
  • Create the sample “Camera store”, and load the sample data (This option is available on the create store page).
  • Have a working ruby development environment (Ruby > 1.9.3, 2.2.x installation, your IDE of choice)
  • Basic familiarity with the Sinatra framework.

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.

Initialize the library

With the API key in hand, you can initialize the Tradenity client. Tradenity client needs the API key and an instance of AuthTokenHolder which is an object that makes Tradenity session integrates with the web framework’s (Flask in our case) session mechanism. The SDK provide implementation for Flask and Django and it’s easy to implement youe own

You must initialize the library before making any API call. In a Sinatra application, you can put the initialization code before calling run Sinatra::Application method.

config.ru


require 'rubygems'
require 'bundler'
require 'bundler/setup'

Bundler.require

require 'tradenity'
require './camerastore'
require './camerastore_accounts'
require './camerastore_shop'
require './camerastore_cart'
require './camerastore_orders'

run Sinatra::Application

Make sure to replace the api keys with the ones for your store, otherwise you will get authentication error

Introducing CameraStore sample application

CameraStore application is a typical e-store web application, a web store for a camera shop.

The application code is divided into these modules:

  • camerastore_shop.rb : navigating the and browsing the store, the corresponding templates are in the camerastore/views/shop directory.
  • camerastore_cart.rb : Shopping cart manipulation code. the corresponding template camerastore/views/shop/cart.erb.
  • camerastore_account.rb : login management and registering new customers. the corresponding templates are in the camerastore/views/account directory.
  • camerastore_orders.prb : placing new order, viewing list and details of customer’s past orders. the corresponding templates are in the camerastore/views/orders directory.