This shows you the differences between two versions of the page.
userspace:webservice_corner:ruby-rpc [2014/06/20 09:28] dkoch |
userspace:webservice_corner:ruby-rpc [2021/08/23 08:37] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Ruby JSON-RPC ====== | ||
- | This is an example for a json-rpc in Ruby. | ||
- | Change **test: | ||
- | <code ruby> | ||
- | require ' | ||
- | require ' | ||
- | require ' | ||
- | |||
- | class OpsiRPC | ||
- | def initialize(service_url) | ||
- | @uri = URI.parse(service_url) | ||
- | end | ||
- | |||
- | def method_missing(name, | ||
- | post_body = { ' | ||
- | resp = JSON.parse( http_post_request(post_body) ) | ||
- | raise JSONRPCError, | ||
- | resp[' | ||
- | end | ||
- | |||
- | def http_post_request(post_body) | ||
- | http = Net:: | ||
- | http.use_ssl = true | ||
- | http.verify_mode = OpenSSL:: | ||
- | request = Net:: | ||
- | request.basic_auth(@uri.user, | ||
- | request.content_type = ' | ||
- | request.body = post_body | ||
- | http.request(request).body | ||
- | end | ||
- | |||
- | class JSONRPCError < RuntimeError; | ||
- | end | ||
- | |||
- | h = OpsiRPC.new(' | ||
- | |||
- | |||
- | prodcuts=h.product_getObjects | ||
- | prodcuts.each do |product| | ||
- | puts product[' | ||
- | end | ||
- | </ |