From 0111eb8852ffed6c9d9943926d0e73d2c32516da Mon Sep 17 00:00:00 2001 From: Martin Diaz Date: Fri, 21 Aug 2020 13:41:14 -0300 Subject: [PATCH] :wrench: Added new code examples for Ruby --- examples/get_token.rb | 21 +++++++++++ examples/restclient_post.rb | 73 +++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 examples/get_token.rb create mode 100644 examples/restclient_post.rb diff --git a/examples/get_token.rb b/examples/get_token.rb new file mode 100644 index 0000000..6c9d1a7 --- /dev/null +++ b/examples/get_token.rb @@ -0,0 +1,21 @@ +# You need use this code in to the main folder +# Load the gem +require 'Meli' + +api_instance = Meli::OAuth20Api.new +opts = { + grant_type: 'authorization_code', # Or 'refresh_token' if you need get one new token + client_id: 'client_id_example', # Your client_id + client_secret: 'client_secret_example', # Your client_secret + redirect_uri: 'redirect_uri_example', # Your redirect_uri + code: 'code_example', # The parameter CODE who was received in the query. + refresh_token: 'refresh_token_example' # Your refresh_token +} + +begin + #Request Access Token + result = api_instance.get_token(opts) + p result +rescue Meli::ApiError => e + puts "Exception when calling OAuth20Api->get_token: #{e}" +end \ No newline at end of file diff --git a/examples/restclient_post.rb b/examples/restclient_post.rb new file mode 100644 index 0000000..7a361b0 --- /dev/null +++ b/examples/restclient_post.rb @@ -0,0 +1,73 @@ +# You need use this code in to the main folder +# Load the gem +require 'Meli' + +api_instance = Meli::RestClientApi.new +resource = 'items' # A resource example like items, search, category, etc. +access_token = 'access_token_example' # Your access token. +body = { + "title": "Item de test from ruby - No Ofertar", + "category_id": "MLA5991", + "price": "350", + "currency_id": "ARS", + "available_quantity": "12", + "buying_mode": "buy_it_now", + "listing_type_id": "bronze", + "condition": "new", + "description": "Item de Teste. Mercado Livre SDK", + "video_id": "RXWn6kftTHY", + "pictures": [ + { + "source": "https://http2.mlstatic.com/storage/developers-site-cms-admin/openapi/319968615067-mp3.jpg" + } + ], + "attributes": [ + { + "id": "DATA_STORAGE_CAPACITY", + "name": "Capacidad de almacenamiento de datos", + "value_id": "null", + "value_name": "8 GB", + "value_struct": { + "number": 8, + "unit": "GB" + }, + "values": [ + { + "id": "null", + "name": "8 GB", + "struct": { + "number": 8, + "unit": "GB" + } + } + ], + "attribute_group_id": "OTHERS", + "attribute_group_name": "Otros" + } + ], + "variations": [ + { + "price": 350, + "attribute_combinations": [ + { + "name": "Color", + "value_id": "283165", + "value_name": "Gris" + } + ], + "available_quantity": 2, + "sold_quantity": 0, + "picture_ids": [ + "882629-MLA40983876214_032020" + ] + } + ] +} + +begin + #Resourse path POST + result = api_instance.resource_post(resource, access_token, body) + p result +rescue Meli::ApiError => e + puts "Exception when calling RestClientApi->resource_post: #{e}" +end