Hi All,
I am trying to create a post request using REST Client API in ruby.
I have created a ruby class TargetService.rb, this class is having a method called createlockbox that will creates target. the class is described as
#!/usr/bin/ruby
require 'rubygems'
require 'base64'
require 'json'
class TargetService
def initialize()
end
def createLockbox ()
puts "Inside create lockbox target function"
# user='admin'
# pwd='admin'
# url = ""
https://devops.com:18102/opam"
response = RestClient::Request.new(
:method => :post,
:url =">" '
https://devops.com:18102/opam/target',
:targetType => 'lockbox',
:user => 'admin',
:password => 'admin',
:targetName => 'Test-5',
:domain => 'GDE',
:host => 'Test-5',
:content_type => 'application/json',
:accept => 'application/json',
).execute
results = JSON.parse(response.to_str)
p results
rescue RestClient::Exception => e
puts e.http_body
end
end
I am calling this class from another ruby file as
#!/usr/bin/env ruby
require './TargetService'
puts "Hello world!"
tar_ser = TargetService.new()
target_create= tar_ser.createLockbox()
while executing this ruby file, I am getting error as
C:\Users\sachkkum\sachin\cookbooks\Test\recipes>ruby test1.rb
Hello TargetService Class###########
Hello world!
Inside create lockbox target function
A JSONObject text must begin with '{' at character 0 of
Getting Status code as "201 created" in response header.
Can anyone help, what wrong I am doing in this post request using ruby class?/