rest - Ruby -> RestClient::Resource -> post -> arguments -
i constructed restclient wrapper
require 'json' require 'rest_client' $url_common_part = 'http://host:port/cgi-bin/cgi_script' class grabber def initialize @site = restclient::resource.new($url_common_part) end def post ( path, params ) site_and_path = @site["#{path}"] payload = params.to_json puts "\n", payload response = site_and_path.post ( payload, headers = { 'my-header' => 'my-value', 'content_type' => 'json', 'accept' => 'json' } ) return response end end
and works well, post gives error syntax error, unexpected ',', expecting ')' (syntaxerror)
may suggest doing wrong?
the problem in call post:
response = site_and_path.post ( payload, headers = { 'my-header' => 'my-value', 'content_type' => 'json', 'accept' => 'json' } )
you doing assignment headers
when second parameter hash (which can include headers):
response = site_and_path.post ( payload, headers: { 'my-header' => 'my-value', 'content_type' => 'json', 'accept' => 'json' } )
Comments
Post a Comment