class Dingtalktool::HttpService
Public Class Methods
get(url,params)
click to toggle source
# File lib/dingtalktool/http_service.rb, line 10 def self.get(url,params) uri = URI.parse("#{@@oapi_host}/#{url}?") uri.query = URI.encode_www_form(params) res = Net::HTTP.get_response(uri) if res.code == "200" return resbody = JSON.parse(res.body) end return nil end
joinParams(path,params)
click to toggle source
# File lib/dingtalktool/http_service.rb, line 28 def self.joinParams(path,params) url = "#{@@oapi_host}#{path}" if params.count > 0 url = url + "?" params.each do |key,value| url = url + key.to_s + "=" + value.to_s + "&"; end url[-1] == "&" && url.chop! end return url end
post(url, params, data)
click to toggle source
# File lib/dingtalktool/http_service.rb, line 20 def self.post(url, params, data) res = RestClient.post joinParams(url, params), data, :content_type => :json, :accept => :json if res.code == 200 return resbody = JSON.parse(res.body) end return nil end