Sha256: baa6b8182ef9c87763250e7015e30b1451de7f1eb3c0b9f63fdf4ac998f72ff8
Contents?: true
Size: 1.71 KB
Versions: 59
Compression:
Stored size: 1.71 KB
Contents
require 'rest-client' require 'json' require 'data_magic' options = { headers: { # accept: "application/xml", accept: "application/json", content_type: "application/json" # log: Logger.new('logs/traffic.log') } } RestClient.log = Logger.new('logs/traffic.log') data_string = <<-EOF { "id": 1, "category": { "id": 1, "name": "string" }, "name": "test_rest", "photoUrls": [ "string" ], "tags": [ { "id": 1, "name": "string" } ], "status": "sold" } EOF data = { 'id' => '1', 'category' => { 'id' => '1', 'name' => "string" }, 'name' => "test_rest", 'photoUrls' => [ "string" ], 'tags' => [ { 'id' => '1', 'name' => "string" } ], 'status' => "sold" } # puts data.to_s # include DataMagic id = '1' default = data_for 'default/pet' merged_result = default.merge({ 'id' => id }) #converted_data = JSON.generate(data).to_s converted_data = JSON.generate(merged_result).to_s puts converted_data # puts 'data' # puts data_string resource = RestClient::Resource.new('http://petstore.swagger.io/v2', options) # begin # response = resource['pet'].post(data) # rescue RestClient::ExceptionWithResponse => e # puts e.response # end begin #response = resource['store/order/1'].get #response = resource['store/inventory'].get # #response = resource['pet/findByStatus?status=sold'].get(accept: 'application/xml') #response = resource['pet'].post(data_string) #response = resource['pet'].post(converted_data) response = resource['pet/' + id].get #response = resource['pet/' + id].delete rescue RestClient::ExceptionWithResponse => e puts e.response end puts response.body puts response.code puts response.request
Version data entries
59 entries across 59 versions & 1 rubygems