Class: YuntongxunSdk::API
- Inherits:
-
Object
- Object
- YuntongxunSdk::API
- Defined in:
- lib/yuntongxun_sdk/api.rb
Defined Under Namespace
Classes: RequestFailureError
Instance Method Summary collapse
-
#api(path, args = {}, verb = "post", options = {}) ⇒ Object
Makes a request to the appropriate YuntongxunSdk API.
-
#initialize(account_sid = YuntongxunSdk.config.account_sid, auth_token = YuntongxunSdk.config.auth_token, app_id = YuntongxunSdk.config.app_id) ⇒ API
constructor
A new instance of API.
Constructor Details
#initialize(account_sid = YuntongxunSdk.config.account_sid, auth_token = YuntongxunSdk.config.auth_token, app_id = YuntongxunSdk.config.app_id) ⇒ API
Returns a new instance of API.
3 4 5 6 7 |
# File 'lib/yuntongxun_sdk/api.rb', line 3 def initialize(account_sid = YuntongxunSdk.config.account_sid, auth_token = YuntongxunSdk.config.auth_token, app_id = YuntongxunSdk.config.app_id) @account_sid = account_sid @auth_token = auth_token @app_id = app_id end |
Instance Method Details
#api(path, args = {}, verb = "post", options = {}) ⇒ Object
Note:
You’ll rarely need to call this method directly.
Makes a request to the appropriate YuntongxunSdk API.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/yuntongxun_sdk/api.rb', line 33 def api(path, args = {}, verb = "post", = {}) args = { appId: @app_id }.merge(args) batch = DateTime.now.in_time_zone("Beijing").strftime("%Y%m%d%H%M%S") signature = "#{@account_sid}#{@auth_token}#{batch}" sig = Digest::MD5.hexdigest(signature).upcase gateway = .delete(:gateway) || YuntongxunSdk.config.gateway # add a leading / if needed... path = "/#{path}" unless path =~ /^\// url = "#{gateway}/2013-12-26/Accounts/#{@account_sid}#{path}?sig=#{sig}" headers = { "Accept" => "application/json", "Content-Type" => "application/json;charset=utf-8", "Authorization" => Base64.strict_encode64("#{@account_sid}:#{batch}") } response = YuntongxunSdk.make_request(url, verb, args, headers) build_reponse(response) end |