meli

package module
v0.0.0-...-0707764 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2016 License: MIT Imports: 10 Imported by: 1

README

MercadoLibre's GO SDK

This is unofficial GO SDK for MercadoLibre's Platform.

GoDoc

How to install

go get github.com/tiaguinho/mercadolibre-go-sdk

How do I use it?

The first thing to do is to instance a Meli class. You'll need to give a clientId and a clientSecret. You can obtain both after creating your own application. For more information on this please read: creating an application

Using the package

After import the package, you have to get new meli.Client struct

client := meli.New(1234, "secret")

If you already have the access_token and refresh_token you can call another method for receive the same client

client := meli.NewWithAccessToken(1234, "secret", "access_token", "refresh_token")
Redirect users to authorize the application

First get the link to redirect the user.

redirectUrl := meli.GetAuthUrl("redirect_url", meli.AuthUrls["site_code"])

You have to change de redirect_url for the url of your application and site_code for the code of the country you are implementing, for example: MLB, MLA, MCO (see the file auth.go to get the list).

Once the user is redirected to your redirect_url, you'll receive in the query string, a parameter named code. You'll need this value for authorize the app.

client.Authorize(url.Query().Get("code"), "redirect_url")

This will get a access_token and refresh_token for your application and your user.

After that your are ready to make call to the API.

Making GET calls
params := map[string]string{"access_token": client.MLToken.AccessToken}

body, err := client.Get("users/me", params)
Making POST calls
params := map[string]string{"access_token": client.MLToken.AccessToken}

product := MLProduct{Foo: Bar}

body, err := client.Post("items", product, params)
Making PUT calls
params := map[string]string{"access_token": client.MLToken.AccessToken}

product := MLProduct{Foo: Bar2}

body, err := client.Put("items", product, params)
Making DELETE calls
params := map[string]string{"access_token": client.MLToken.AccessToken}

body, err := client.Delete("questions/123", params)

Examples

For more examples, check out this repository.

License

The MIT License (MIT) Copyright (c) 2013

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AuthUrls = map[string]string{
		"MLA": "https://auth.mercadolibre.com.ar",
		"MLB": "https://auth.mercadolivre.com.br",
		"MCO": "https://auth.mercadolibre.com.co",
		"MCR": "https://auth.mercadolibre.com.cr",
		"MEC": "https://auth.mercadolibre.com.ec",
		"MLC": "https://auth.mercadolibre.cl",
		"MLM": "https://auth.mercadolibre.com.mx",
		"MLU": "https://auth.mercadolibre.com.uy",
		"MLV": "https://auth.mercadolibre.com.ve",
		"MPA": "https://auth.mercadolibre.com.pa",
		"MPE": "https://auth.mercadolibre.com.pe",
		"MPT": "https://auth.mercadolibre.com.pt",
		"MRD": "https://auth.mercadolibre.com.do",
	}
)

Functions

This section is empty.

Types

type Category

type Category struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Category struct

type Client

type Client struct {
	GrantType    string `json:"grant_type,omitempty"`
	Code         string `json:"code"`
	ClientID     int    `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	RedirectUri  string `json:"redirect_uri"`
	MLToken      MLToken
}

Client struct

func New

func New(clientID int, clientSecret string) *Client

New

func NewWithAccessToken

func NewWithAccessToken(clientID int, clientSecret, accessToken, refreshToken string) *Client

NewWithAccessToken

func (*Client) Authorize

func (c *Client) Authorize(code, redirectUri string) (err error)

Authorize

func (*Client) Delete

func (c *Client) Delete(path string, params map[string]string) ([]byte, error)

Delete

func (*Client) Get

func (c *Client) Get(path string, params map[string]string) ([]byte, error)

Get

func (*Client) GetAuthUrl

func (c *Client) GetAuthUrl(redirectUri, authUrl string) (authUri string, err error)

getAuthUrl

func (*Client) Post

func (c *Client) Post(path string, body interface{}, params map[string]string) ([]byte, error)

Post

func (*Client) Put

func (c *Client) Put(path string, body interface{}, params map[string]string) ([]byte, error)

Put

func (*Client) RefreshAccessToken

func (c *Client) RefreshAccessToken() (err error)

RefreshAccessToken

type Image

type Image struct {
	Source string `json:"source"`
}

Image struct

type MLError

type MLError struct {
	Message string `json:"message"`
	Error   string `json:"error"`
	Status  int    `json:"status"`
}

MLError struct

type MLToken

type MLToken struct {
	AccessToken  string `json:"access_token,omitempty"`
	TokenType    string `json:"token_type,omitempty"`
	ExpiresIn    int    `json:"expires_in,omitempty"`
	Scope        string `json:"scope,omitempty"`
	UserId       int    `json:"user_id,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`
}

MLToken struct

type Product

type Product struct {
	ID                string  `json:"id,omitempty"`
	ListingTypeID     string  `json:"listing_type_id"`
	Title             string  `json:"title"`
	Description       string  `json:"description"`
	CategoryID        string  `json:"category_id"`
	BuyingMode        string  `json:"buying_mode"`
	CurrencyID        string  `json:"currency_id"`
	Condition         string  `json:"condition"`
	Price             float32 `json:"price"`
	AvailableQuantity int32   `json:"available_quantity"`
	Pictures          []Image `json:"pictures"`
}

Product struct

type Status

type Status struct {
	Status string `json:"status"`
}

Status struct

Jump to

Keyboard shortcuts

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