Class: YunTongXun::Service
- Inherits:
-
Object
- Object
- YunTongXun::Service
- Defined in:
- lib/yuntongxun/service.rb
Direct Known Subclasses
Instance Method Summary collapse
- #base_url ⇒ Object
- #get_response(header, data, path) ⇒ Object
-
#headers(account_sid) ⇒ Object
account_sid: 主账号或子账号.
-
#initialize(sub_account_sid = nil, sub_auth_token = nil, version = "2013-12-26") ⇒ Service
constructor
子账号调用接口时需传入子账号信息.
-
#sign(account_sid, auth_token) ⇒ Object
account_sid: 主账号或子账号.
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(sub_account_sid = nil, sub_auth_token = nil, version = "2013-12-26") @sub_account_sid = sub_account_sid @sub_auth_token = sub_auth_token @version = version end |
Instance Method Details
#base_url ⇒ Object
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(account_sid) { 'Accept' => 'application/json', 'Content-Type' => 'application/json;charset=utf-8', 'Authorization' => Base64.strict_encode64(account_sid + ':' + YunTongXun::Utils.) } end |
#sign(account_sid, auth_token) ⇒ Object
account_sid: 主账号或子账号
28 29 30 |
# File 'lib/yuntongxun/service.rb', line 28 def sign(account_sid, auth_token) Digest::MD5.hexdigest(account_sid + auth_token + YunTongXun::Utils.).upcase end |