https://github.com/tiaguinho/mercadolibre-go-sdk
SDK for Mercadolibre written in Go
https://github.com/tiaguinho/mercadolibre-go-sdk
Last synced: 6 months ago
JSON representation
SDK for Mercadolibre written in Go
- Host: GitHub
- URL: https://github.com/tiaguinho/mercadolibre-go-sdk
- Owner: tiaguinho
- License: mit
- Created: 2016-07-06T18:34:07.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-07-18T15:05:49.000Z (over 9 years ago)
- Last Synced: 2025-04-04T15:53:50.094Z (7 months ago)
- Language: Go
- Size: 7.81 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
MercadoLibre's GO SDK
========
This is unofficial GO SDK for MercadoLibre's Platform.
[](https://godoc.org/github.com/tiaguinho/mercadolibre-go-sdk)
## How to install ##
```go
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](http://developers.mercadolibre.com/application-manager/)
## Using the package ##
After import the package, you have to get new ```meli.Client``` struct
```go
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
```go
client := meli.NewWithAccessToken(1234, "secret", "access_token", "refresh_token")
```
### Redirect users to authorize the application ###
First get the link to redirect the user.
```go
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.
```go
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 ###
```go
params := map[string]string{"access_token": client.MLToken.AccessToken}
body, err := client.Get("users/me", params)
```
### Making POST calls ###
```go
params := map[string]string{"access_token": client.MLToken.AccessToken}
product := MLProduct{Foo: Bar}
body, err := client.Post("items", product, params)
```
### Making PUT calls ###
```go
params := map[string]string{"access_token": client.MLToken.AccessToken}
product := MLProduct{Foo: Bar2}
body, err := client.Put("items", product, params)
```
### Making DELETE calls ###
```go
params := map[string]string{"access_token": client.MLToken.AccessToken}
body, err := client.Delete("questions/123", params)
```
## Examples ##
For more examples, [check out this repository](https://github.com/tiaguinho/test-meli-go).
## License ##
[The MIT License (MIT) Copyright (c) 2013](http://opensource.org/licenses/MIT)