store2

package module
v2.1.5+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

README

Meplato Store 2 API Go Client

Build Status

This is the Go client for the Meplato Store 2 API. It consists of a library to integrate your infrastructure with Meplato suite for suppliers. It also has a command line tool you can use to immediately interact with Meplato Store. The command line tool also illustrates how to write your own clients.

Prerequisites

You need at two things to use the Meplato Store 2 API.

  1. A login to Meplato Store 2.
  2. An API token.

Get your login by contacting Meplato Supplier Network Services. The API token is required to securely communicate with the Meplato Store 2 API. You can find it in the personalization section when logged into Meplato Store.

Getting started

We use the command line tool to illustrate how easy it is to get started with Meplato Store. First, we need to clone the repository and build the command line client:

  1. Get the library via: go get github.com/meplato/store2-go-client
  2. Install the dependencies: make deps
  3. Set the API token, e.g. via an environment variable: export STORE2_USER=<your-api-token>. If you're an old Unix guy, you can also add a line to your ~/.netrc file, e.g. machine store2.meplato.com login <your-api-token>; the command line client will happily pick it up without any environment variables.
  4. Build the command line client: make

You should now have an executable binary at ./store. If you run it, you can see a help page regarding the various commands.

If you successfully set your API token, either via environment variable or via netrc, you should now be able to run ./store catalogs and it should list all the catalogs in your Meplato Store.

$ ./store catalogs
4 catalogs found.
 ID  Name                                               Created
==============================================================================
  4. Excel-Test                                         2015-07-17
  3. Demokatalog                                        2015-06-18
  2. Büromaterial                                       2015-06-18
  1. Büromaterial                                       2015-06-18

Using the library

Using the library is actually quite simple. All functionality is separated into services. So you e.g. have a service to work with catalogs, another service to work with products in a catalog etc. All services need to be initialized with your API token.

import (
	"net/http"
	"log"

	catalogs "github.com/meplato/store2-go-client/catalogs"
)

...

// Create and initialize your service with your API token
service, err := catalogs.New(http.DefaultClient)
if err != nil {
  log.Fatal(err)
}
service.User = "<your-api-token>"

Now that you have access to your service, you can set up parameters and execute the service call. For example, the following snippet will print the first 10 catalogs in your Meplato Store, sorted by catalog name.

res, err := service.Search().Skip(0).Take(10).Sort("name").Do()
if err != nil {
	log.Fatal(err)
}

fmt.Printf("You have a total of %d catalog(s).\n", res.TotalItems)
for _, c := range res.Items {
	fmt.Printf("Catalog with ID=%d has name %q and was created at %v.\n",
		c.ID, c.Name, c.Created.Format("2006-01-02"))
}

Feel free to read the unit tests for the various usage scenarios of the library.

Running tests

To run all tests use go test ./...

Documentation

Complete documentation for the Meplato Store 2 API can be found at https://developer.meplato.com/store2.

License

This software is licensed under the Apache 2 license.

Copyright (c) 2015 Meplato GmbH, Switzerland <http://www.meplato.com>

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

	    http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.

Documentation

Overview

Package store2 implements the Meplato Store API.

See https://developer.meplato.com/store2/.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MeResponse

type MeResponse struct {
	// CatalogsLink is the URL for retrieving the list of catalogs.
	CatalogsLink string `json:"catalogsLink,omitempty"`
	// Kind is store#me for this entity.
	Kind string `json:"kind,omitempty"`
	// Merchant returns information about your merchant account.
	Merchant *Merchant `json:"merchant,omitempty"`
	// SelfLink is the URL of this request.
	SelfLink string `json:"selfLink,omitempty"`
	// User returns information about your user account.
	User *User `json:"user,omitempty"`
}

MeResponse returns various information about the user and endpoints.

type MeService

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

Me returns information about your user profile and the API endpoints of the Meplato Store 2.0 API.

func NewMeService

func NewMeService(s *Service) *MeService

NewMeService creates a new instance of MeService.

func (*MeService) Do

func (s *MeService) Do() (*MeResponse, error)

Do executes the operation.

type Merchant

type Merchant struct {
	// Country is the ISO code for the country of the merchant, e.g. DE or CH.
	Country string `json:"country,omitempty"`
	// Created is the date/time when the merchant was created, e.g.
	// 2015-03-19T12:09:45Z
	Created *time.Time `json:"created,omitempty"`
	// Currency is the default ISO code for new catalogs, e.g. EUR or GBP.
	Currency string `json:"currency,omitempty"`
	// ID is a unique (internal) identifier of the merchant.
	ID int64 `json:"id,omitempty"`
	// Kind is store#merchant for this entity.
	Kind string `json:"kind,omitempty"`
	// Language is the code for the language of the merchant, e.g. de or en.
	Language string `json:"language,omitempty"`
	// Locale is the regional code in the format de_AT.
	Locale string `json:"locale,omitempty"`
	// Mpcc: MPCC is the Meplato Company Code, a unique identifier.
	Mpcc string `json:"mpcc,omitempty"`
	// Mpsc: MPSC is the Meplato Supplier Code.
	Mpsc string `json:"mpsc,omitempty"`
	// Name is the name of the merchant.
	Name string `json:"name,omitempty"`
	// Ou: OU is the default ISO code of the order unit, e.g. PCE or EA.
	Ou string `json:"ou,omitempty"`
	// SelfLink is the URL for this merchant.
	SelfLink string `json:"selfLink,omitempty"`
	// SelfService indicates whether this merchant is on self-service or
	// managed by Meplato.
	SelfService bool `json:"selfService,omitempty"`
	// TimeZone is the time zone in the format Europe/Berlin.
	TimeZone string `json:"timeZone,omitempty"`
	// Token is a shared token for this merchant.
	Token string `json:"token,omitempty"`
	// Updated is the date/time when the merchant was last modified, e.g.
	// 2015-03-19T12:09:45Z
	Updated *time.Time `json:"updated,omitempty"`
}

Merchant holds account data for the merchant/supplier in Meplato Store.

type PingService

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

Ping allows you to test if the Meplato Store 2.0 API is currently operational.

func NewPingService

func NewPingService(s *Service) *PingService

NewPingService creates a new instance of PingService.

func (*PingService) Do

func (s *PingService) Do() error

Do executes the operation.

type Service

type Service struct {
	BaseURL  string
	User     string
	Password string
	// contains filtered or unexported fields
}

func New

func New(client *http.Client) (*Service, error)

func (*Service) Me

func (s *Service) Me() *MeService

func (*Service) Ping

func (s *Service) Ping() *PingService

type User

type User struct {
	// Country is the ISO code for the country, e.g. DE or CH.
	Country string `json:"country,omitempty"`
	// Created is the date/time when the user was created, e.g.
	// 2015-03-19T12:09:45Z
	Created *time.Time `json:"created,omitempty"`
	// Currency is the default ISO code for currencies, e.g. EUR or GBP.
	Currency string `json:"currency,omitempty"`
	// Email is the email address.
	Email string `json:"email,omitempty"`
	// ID is a unique (internal) identifier of the user.
	ID int64 `json:"id,omitempty"`
	// Kind is store#user for this entity.
	Kind string `json:"kind,omitempty"`
	// Language is the code for the language, e.g. de or en.
	Language string `json:"language,omitempty"`
	// Locale is the regional code in the format de_AT.
	Locale string `json:"locale,omitempty"`
	// Name is the user, including first and last name.
	Name string `json:"name,omitempty"`
	// Provider is used internally.
	Provider string `json:"provider,omitempty"`
	// TimeZone is the time zone in the format Europe/Berlin.
	TimeZone string `json:"timeZone,omitempty"`
	// Uid: UID is used internally.
	Uid string `json:"uid,omitempty"`
	// Updated is the date/time when the user was last modified, e.g.
	// 2015-03-19T12:09:45Z
	Updated *time.Time `json:"updated,omitempty"`
}

User holds account data for the user in Meplato Store.

Directories

Path Synopsis
Package catalogs implements the Meplato Store API.
Package catalogs implements the Meplato Store API.
cmd
internal
Package jobs implements the Meplato Store API.
Package jobs implements the Meplato Store API.
Package products implements the Meplato Store API.
Package products implements the Meplato Store API.

Jump to

Keyboard shortcuts

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