Skip to content

Instantly share code, notes, and snippets.

@fabiobarboza7
Last active March 18, 2020 01:02
Show Gist options
  • Save fabiobarboza7/a780619e53f93668cb1a8ff7c4aff69d to your computer and use it in GitHub Desktop.
Save fabiobarboza7/a780619e53f93668cb1a8ff7c4aff69d to your computer and use it in GitHub Desktop.
require 'net/http'
require 'uri'
require 'json'
require 'mime/types'
@body ={
"name": "Banana de Pijamas!",
"type": "variable",
"regular_price": "21.99",
"status": "publish",
"catalog_visibility": "visible",
"description": "TEste de cadastro de Produtos",
"short_description": "Produto Pequeno",
"categories": [
{
"id": "9"
},
{
"id": "14"
}
],
"images": [
{
"src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg"
},
{
"src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg"
}
],
"attributes":[
{
"name": "Color",
"position": 0,
"visible": true,
"variation": true,
"options":[
"p",
"m",
"g"
]}],
"variations":[]
}
uri = URI('https://luaclara.ind.br/wp-json/wc/v3/products/')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json')
req.basic_auth 'ck_962653bd56c3a93c91c5a6cf9a90aa7be5dba873', 'cs_7a55edb9f321462cd5941de971d0268af72ffe0b'
req.body = @body.to_json
res = http.request(req)
puts "response #{res.body}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment