ruby - error 400 from 'rest-client' gem -
i have simple ruby script invoke crontab entry, entire script below:
require 'rest-client' require 'json' valve_id, gpio_pin, cmd, http_host = argv # puts "valve_id --> #{valve_id}, cmd --> #{cmd}, http_host --> #{http_host}" restclient.put "http://#{http_host}/api/valves/#{valve_id}.json", { "params" => {"cmd" => "#{cmd}"}}.to_json , :content_type => :json, :accept => :json
here crontab entry:
ruby /home/kenb/development/coffeewater/lib/tasks/rest_client.rb 5 23 0 stargate:9292
the resource being accessed simple rails model, valve, integer attribute 'cmd'.
i can't seem encoding right, keep getting error 400.
i have tried code , works fine own url http://zoker.sinaapp.com/sonar.php
i think there wrong api interface, maybe should cache error message begin...rescue
see happened api
here test code
ruby.rb
require 'rest-client' require 'json' valve_id, gpio_pin, cmd, http_host = argv # puts "valve_id --> #{valve_id}, cmd --> #{cmd}, http_host --> #{http_host}" begin restclient.put "http://zoker.sinaapp.com/sonar.php", { "params" => {"cmd" => "#{cmd}","valve_id"=>"#{valve_id}","http_host"=>"#{http_host}"}}.to_json , :content_type => :json, :accept => :json rescue => e puts e end
run ruby ruby.rb 5 23 0 stargate:9292
here api got
{"params":{"cmd":"0","valve_id":"5","http_host":"stargate:9292"}}---------x-forwarded-for: 112.97.38.29, 112.97.38.29------------------host: zoker.sinaapp.com------------------appname: zoker------------------appversion: 1------------------accesskey: loy5m01zk1------------------apphash: 132------------------mysqlport: 3321------------------appcookie: default_version=1;debug=1;------------------appsrvc: 0000000000000000------------------connection: close------------------content-length: 65------------------accept: application/json------------------accept-encoding: gzip, deflate------------------content-type: application/json------------------user-agent: ruby---------
you can see result here
Comments
Post a Comment