Class: Dingtalktool::HttpService
- Inherits:
-
Object
- Object
- Dingtalktool::HttpService
- Defined in:
- lib/dingtalktool/http_service.rb
Constant Summary collapse
- @@oapi_host =
'https://oapi.dingtalk.com'
Class Method Summary collapse
Class Method Details
.get(url, params) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# 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) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# 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) ⇒ Object
20 21 22 23 24 25 26 |
# 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 |