コード例 #1
0
 public IDictionary <string, string> GetParameters()
 {
     if (this.apiParams == null)
     {
         this.apiParams = new LazopDictionary();
     }
     return(this.apiParams);
 }
コード例 #2
0
 public void AddHeaderParameter(string key, string value)
 {
     if (this.headerParams == null)
     {
         this.headerParams = new LazopDictionary();
     }
     this.headerParams.Add(key, value);
 }
コード例 #3
0
        private LazopResponse DoExecute(LazopRequest request, string accessToken, DateTime timestamp)
        {
            long start = DateTime.Now.Ticks;

            // add common params
            LazopDictionary txtParams = new LazopDictionary(request.GetParameters());

            txtParams.Add(Constants.APP_KEY, appKey);
            txtParams.Add(Constants.TIMESTAMP, GetTimestamp(timestamp));
            txtParams.Add(Constants.ACCESS_TOKEN, accessToken);
            txtParams.Add(Constants.PARTNER_ID, sdkVersion);
            txtParams.AddAll(this.customrParameters);
            txtParams.Add(Constants.SIGN_METHOD, this.signMethod);
            if (IsDebugEnabled())
            {
                txtParams.Add(Constants.DEBUG, true);
            }

            // compute and add sign
            txtParams.Add(Constants.SIGN, LazopUtils.SignRequest(request.GetApiName(), txtParams, appSecret, this.signMethod));

            string realServerUrl = GetServerUrl(this.serverUrl, request.GetApiName(), accessToken);
            string reqUrl        = WebUtils.BuildRequestUrl(realServerUrl, txtParams);

            try
            {
                string body;
                if (request.GetFileParameters() != null) // if file params is set
                {
                    body = webUtils.DoPost(realServerUrl, txtParams, request.GetFileParameters(), request.GetHeaderParameters());
                }
                else
                {
                    if (request.GetHttpMethod().Equals(Constants.METHOD_POST))
                    {
                        body = webUtils.DoPost(realServerUrl, txtParams, request.GetHeaderParameters());
                    }
                    else
                    {
                        body = webUtils.DoGet(realServerUrl, txtParams, request.GetHeaderParameters());
                    }
                }

                LazopResponse response = ParseResponse(body);

                // log error response
                if (response.IsError())
                {
                    TimeSpan latency = new TimeSpan(DateTime.Now.Ticks - start);
                    LogApiError(appKey, sdkVersion, request.GetApiName(), serverUrl, txtParams, latency.TotalMilliseconds, response.Body);
                }
                else
                {
                    if (IsDebugEnabled() || IsInfoEnabled())
                    {
                        TimeSpan latency = new TimeSpan(DateTime.Now.Ticks - start);
                        LogApiError(appKey, sdkVersion, request.GetApiName(), serverUrl, txtParams, latency.TotalMilliseconds, response.Body);
                    }
                }

                return(response);
            }
            catch (Exception e)
            {
                TimeSpan latency = new TimeSpan(DateTime.Now.Ticks - start);
                LogApiError(appKey, sdkVersion, request.GetApiName(), serverUrl, txtParams, latency.TotalMilliseconds, e.GetType() + ": " + e.Message);
                throw e;
            }
        }