GithubHelp home page GithubHelp logo

danielbrezoi / commercetools-dotnet-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from commercetools/commercetools-dotnet-sdk

0.0 2.0 0.0 7.84 MB

License: MIT License

C# 98.94% PowerShell 0.72% Shell 0.35%

commercetools-dotnet-sdk's Introduction

commercetools-dotnet-sdk

Travis Build Status AppVeyor Build Status NuGet Version and Downloads count

The commercetools.NET SDK allows developers to work effectively with the commercetools platform in their .NET applications by providing typesafe access to the commercetools HTTP API.

For more documentation please see the wiki

Supported Platforms

  • .NET Framework 4.5 and 4.6

Using the SDK

You will need a commercetools project to use the SDK. If you don't already have one, you can create a free trial project on the commercetools platform and configure the API credentials.

The namespaces in the SDK mirror the sections of the commercetools HTTP API. Access to these namespaces is provided by a fluent interface on the Client class.

Responses from the client are wrapped in a Reponse object so you can determine if the request was successful and view the error(s) returned from the API if it was not.

using System;
using System.Threading.Tasks;

using commercetools.Common;
using commercetools.Products;

class Program
{
    static void Main(string[] args)
    {
        new Program().Run().Wait();

        Console.WriteLine("Press any key to exit.");
        Console.ReadKey();
    }

    private async Task Run()
    {
        Configuration config = new Configuration(
            "https://auth.sphere.io/oauth/token",
            "https://api.sphere.io",
            "[your project key]",
            "[your client ID]",
            "[your client secret]",
            ProjectScope.ManageProject);

        Client client = new Client(config);
        
        Response<ProductQueryResult> response = await client.Products().QueryProductsAsync();

        if (response.Success)
        {
            ProductQueryResult productQueryResult = response.Result;

            foreach (Product product in productQueryResult.Results)
            {
                Console.WriteLine(product.Id);
            }
        }
        else
        {
            Console.WriteLine("{0}: {1}", response.StatusCode, response.ReasonPhrase);

            foreach (ErrorMessage errorMessage in response.Errors)
            {
                Console.WriteLine("{0}: {1}", errorMessage.Code, errorMessage.Message);
            }
        }
    }
}

Not all API sections and representations have been implemented in the SDK. If you need to work with areas of the API that have not yet been covered, you can use the Client to make JSON requests directly. Ask the client for a JObject and you will get the entire JSON response that is returned from the API.

This code snippet will have the same output as the code snippet above:

Response<JObject> response = await client.GetAsync<JObject>("/products");

if (response.Success)
{
    dynamic responseObj = response.Result;

    foreach (dynamic product in responseObj.results)
    {
        Console.WriteLine(product.id);
    }
}
else
{
    Console.WriteLine("{0}: {1}", response.StatusCode, response.ReasonPhrase);

    foreach (ErrorMessage errorMessage in response.Errors)
    {
        Console.WriteLine("{0}: {1}", errorMessage.Code, errorMessage.Message);
    }
}

License, Contributing

This software is licenses under the MIT License, which allows commercial use and modification as well as open source collaboration.

We are warmly welcoming contributors and are happy to help out. To contribute changes or improvements, please fork the repository into your account on GitHub and create a pull request.

Developing

Mac Users

The Visual Studio IDE is available for Mac OS (preview version as of 2016)

A more lightweight Coding Environment that also manages the .NET setup automatically for you is Microsoft Visual Studio Code (free).

commercetools-dotnet-sdk's People

Contributors

hajoeichler avatar jhumber avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.