Skip to content

Simply-Translate/Connector-CCVShop

Repository files navigation

Connector CCV Shop

.NET API connector for the CCV Shop
CCV Shop API documentation (https://www.ccvshop.nl/mogelijkheden/api)
Created by Simply Translate (http://www.simplytranslate.nl/)
Created by Dennis Rosenbaum, any questions, please e-mail me at [email protected]

Get Started

1.0 Setup

  1. Install
  2. Initialize

1. Install
Install the code with NuGet or pull the code and create the library yourself.

Install with NuGet

or

2. Initialize
You have to initialize some core values. In web projects this can be done within the global.asax. In other projects you can put it in the startup code.



Implement the urls that you also use within the CCV Shop backend. Your website MUST be https in order for CCV Shop to accept the requests.

info.HandshakeUrl = "[your CCV Shop handshake url]";
info.InstallUrl = "[your CCV Shop install url]";
info.UninstallUrl = "[your CCV Shop uninstall url]";


The AppId and SecretKey can also be found within the CCV Shop backend. You can find this at the 'Developer App Center'.

info.AppId = "[your AppId]";
info.SecretKey = "[your SecretKey]";




Optional: If you would like to add your own error handling, you can override the ErrorOccurred Action.
Connector.CcvShop.Error.ErrorLogger.ErrorOccurred = (error) => [your function or code];

In order for the connector to work, you must save the api public credentials and values in your own database. Because there are many ways to store the values (SQL database, Table Storage, Session based) you have to implement your own Connector.CcvShop.Interface.IConnectionCcvShopRepository.


The AddConnection is used when the Handshake Url is called. The values should be stored in your database.
The GetForApiPublic should return an IConnectionCcvShop that is stored in your database.

1.1 Install/handshake process

In order for the Connector to work, you must add some Handlers (Handshake, Uninstall, Install). Most of the handling can be done by the CCV Shop Connector.

Handshake

public ActionResult Handshake(Connector.CcvShop.Model.HandshakeModel model)
{
    var api = new Connector.CcvShop.ApiInstall();
    HttpStatusCode statusCode = api.StartHandshake(Request, model);
    return new HttpStatusCodeResult(statusCode);
}


Install

public async Task<ActionResult> Install(Connector.CcvShop.Model.InstallModel model)
{
    var connection = Connector.CcvShop.RepositoryContainer.ConnectionRepo.GetForApiPublic(model.api_public);

    var apiHandshake = new Connector.CcvShop.ApiInstall();
    bool succes = await apiHandshake.VerifyInstall(connection);

    if (succes)
    {
        // Connection is made and install is done, now you can access the API
    }
}


Uninstall

public ActionResult Uninstall(Connector.CcvShop.Model.UninstallModel model)
{
  // add your uninstall logic
}

1.2 Using the API

Well done, you have initialized your and connected your shop within the app. Now it is time to retrieve, update, delete stuff with the API. At the moment of writing, it is onlypossible to retrieve and update products and categories.

Note: An instance of the Connector.CcvShop.Interface.IConnectionCcvShop is neccesary to make calls. It is the responsibility of your code to retrieve the correct connection.

  • Retrieve
  • Update/Patch

Retrieve
Code to retrieve products

var context = new Connector.CcvShop.Api.Products.ProductContext();
var result = await context.Get(connection);
var products = result.items;

Adding parameters and target language:

var productParams = new Connector.CcvShop.Api.Products.Parameters();
productParams.SetProductName("shoe");
productParams.SetMinstock(20);
var acceptLanguage = "nl";
var result = await context.Get(connectionCcvShop, parameters: productParams, lan: acceptLanguage);

The difference between context.Get() and context.GetAll() is that the GetAll() will iterate through ALL the items, Get() will only do a single call. For instance: if there are 500 items and only 150 are returned per call, the Get() method will return 150 items, GetAll() will iterate 4 times and will return 500 items.

Update/Patch
When patching, the properties in the item will be read out (with reflection) and if the property does not have a default value, it is added to the update list. This makes the calls as slim as possible.

Code to update products

int productId = 12345;
var context = new Connector.CcvShop.Api.Products.ProductContext();
var updateItem = new Connector.CcvShop.Api.Products.ProductResult();
updateItem.description = "Some here";
updateItem.page_title = "And some here";
var success = await context.Patch(connection, productId, updateItem, lan: "en");

2.0 Contribute code

If you would like to contribute to this project, please note:

Note 1: Create result class
If you would like to create a Result class (like Connector.CcvShop.Api.Products.ProductResult), you can run the Tools project. You can enter the url provided in the API documentation (it's called 'Content-Type') in the textbox and the code will be generated for you. There is even a handy Copy to Clipboard button.

Note 2: The code is stateless

Note 3: RateLimit
Every url in the api has a ratelimit, this is not yet included. If you are going to include this, please keep stateless programming in mind.

Note 4: Structure
The idea behind the structure is that every type (products, attributes, categories, etc.) will get their own folder within the Api folder.

About

.NET API connector for the CCV Shop

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published