core

package module
v1.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 13 Imported by: 0

README

Ozon Seller API Client

A Ozon Seller API client written in Golang

Coverage Status example workflow

Ozon is a marketplace for small and medium enterprises to launch and grow their businesses in Russia.

Read full documentation

You can check list of supported endpoints

How to start

API

Get Client-Id and Api-Key in your seller profile here

Just add dependency to your project and you're ready to go.

go get github.com/diphantxm/ozon-api-client

A simple example on how to use this library:

package main

import (
	"context"
	"fmt"
	"log"
	"net/http"

	"github.com/diphantxm/ozon-api-client/ozon"
)

func main() {
	// Create a client with your Client-Id and Api-Key
	// [Documentation]: https://docs.ozon.ru/api/seller/en/#tag/Auth
	opts := []ozon.ClientOption{
		ozon.WithAPIKey("api-key"),
		ozon.WithClientId("client-id"),
	}
	c := ozon.NewClient(opts...)

	// Send request with parameters
	resp, err := client.Products().GetProductDetails(context.Background(), &ozon.GetProductDetailsParams{
		ProductId: 123456789,
	})
	if err != nil || resp.StatusCode != http.StatusOK {
		log.Fatalf("error when getting product details: %s", err)
	}

	// Do some stuff
	for _, d := range resp.Result.Barcodes {
		fmt.Printf("Barcode %s\n", d)
	}
}
Notifications

Ozon can send push-notifications to your REST server. There is an implementation of REST server that handles notifications in this library.

Official documentation

How to use:

package main

import (
	"log"

	"github.com/diphantxm/ozon-api-client/ozon/notifications"
)

func main() {
	// Create server
	port := 5000
	server := notifications.NewNotificationServer(port)

	// Register handlers passing message type and handler itself
	server.Register(notifications.ChatClosedType, func(req interface{}) error {
		notification := req.(*notifications.ChatClosed)

		// Do something with the notification here...
		log.Printf("chat %s has been closed\n", notification.ChatId)

		return nil
	})

	// Run server
	if err := server.Run(); err != nil {
		log.Printf("error while running notification server: %s", err)
	}
}

Contribution

If you need some endpoints ASAP, create an issue and list all the endpoints. I will add them to library soon.

Or you can implement them and contribute to the project. Contribution to the project is welcome.

Documentation

Index

Constants

View Source
const ShortDateLayout = "2006-01-02"

Variables

This section is empty.

Functions

func NewMockHttpHandler

func NewMockHttpHandler(statusCode int, json string, headers map[string]string) http.HandlerFunc

func TimeFromString

func TimeFromString(t *testing.T, format, datetime string) time.Time

Types

type Client

type Client struct {
	Options map[string]string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(client HttpClient, baseUrl string, opts map[string]string) *Client

func NewMockClient

func NewMockClient(handler http.HandlerFunc) *Client

func (Client) Request

func (c Client) Request(ctx context.Context, method string, path string, req, resp interface{}, options map[string]string) (*Response, error)

type CommonResponse

type CommonResponse struct {
	StatusCode int
	Code       int                    `json:"code"`
	Details    []CommonResponseDetail `json:"details"`
	Message    string                 `json:"message"`
}

type CommonResponseDetail

type CommonResponseDetail struct {
	TypeUrl string `json:"typeUrl"`
	Value   string `json:"value"`
}

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type MockHttpClient

type MockHttpClient struct {
	// contains filtered or unexported fields
}

func NewMockHttpClient

func NewMockHttpClient(handler http.HandlerFunc) *MockHttpClient

func (MockHttpClient) Do

func (c MockHttpClient) Do(req *http.Request) (*http.Response, error)

type Response

type Response struct {
	CommonResponse
	Data interface{}
}

func (Response) CopyCommonResponse

func (r Response) CopyCommonResponse(rhs *CommonResponse)

type TimeFormat added in v1.13.0

type TimeFormat struct {
	time.Time
	// contains filtered or unexported fields
}

Do not use this structure for responses as there are no ways to unmarshal to any layout and leave nil if json field is null

func NewTimeFormat added in v1.13.0

func NewTimeFormat(t time.Time, layout string) *TimeFormat

func (*TimeFormat) MarshalJSON added in v1.13.0

func (rd *TimeFormat) MarshalJSON() ([]byte, error)

func (*TimeFormat) UnmarshalJSON added in v1.13.0

func (rd *TimeFormat) UnmarshalJSON(b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL