Class: Rails::Ding::HttpService

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/ding/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/rails/ding/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



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rails/ding/http_service.rb', line 24

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.last == "&" &&  url.chop!
  end
  return url
end

.post(url, params, data) ⇒ Object



20
21
22
# File 'lib/rails/ding/http_service.rb', line 20

def self.post(url, params, data)
  res = RestClient.post joinParams(url, params), data, :content_type => :json, :accept => :json
end