Class: YunTongXun::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/yuntongxun/service.rb

Direct Known Subclasses

Calls

Instance Method Summary collapse

Constructor Details

#initialize(sub_account_sid = nil, sub_auth_token = nil, version = "2013-12-26") ⇒ Service

子账号调用接口时需传入子账号信息



5
6
7
8
9
# File 'lib/yuntongxun/service.rb', line 5

def initialize( = nil, sub_auth_token = nil, version = "2013-12-26")
  @sub_account_sid = 
  @sub_auth_token = sub_auth_token
  @version = version
end

Instance Method Details

#base_urlObject



41
42
43
# File 'lib/yuntongxun/service.rb', line 41

def base_url
  YunTongXun.base_url || "https://app.cloopen.com:8883"
end

#get_response(header, data, path) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/yuntongxun/service.rb', line 11

def get_response(header, data, path)
  uri = URI(base_url + path)

  http = Net::HTTP.new(uri.host, uri.port)

  http.use_ssl = true

  request = Net::HTTP::Post.new(base_url + path, header)
  
  request.body = data.to_json

  response = http.request(request)

  result response.body
end

#headers(account_sid) ⇒ Object

account_sid: 主账号或子账号



33
34
35
36
37
38
39
# File 'lib/yuntongxun/service.rb', line 33

def headers()
  {
    'Accept' => 'application/json',
    'Content-Type' => 'application/json;charset=utf-8',
    'Authorization' => Base64.strict_encode64( + ':' + YunTongXun::Utils.timestamp)
  }
end

#sign(account_sid, auth_token) ⇒ Object

account_sid: 主账号或子账号



28
29
30
# File 'lib/yuntongxun/service.rb', line 28

def sign(, auth_token)
  Digest::MD5.hexdigest( + auth_token + YunTongXun::Utils.timestamp).upcase
end