Ejemplo n.º 1
0
        /// <summary>
        /// Call the DataSift API.
        /// </summary>
        /// <param name="endpoint">The endpoint to call.</param>
        /// <param name="parameters">The parameters to be passed.</param>
        /// <returns>A JSONdn object containing the JSON response data.</returns>
        public JSONdn callApi(string endpoint, Dictionary <string, string> parameters)
        {
            string errmsg = String.Empty;

            if (m_apiclient == null)
            {
                m_apiclient = new ApiClient(getUsername(), getApiKey(), API_BASE_URL, USER_AGENT);
            }

            ApiResponse res = m_apiclient.callAPI(endpoint, parameters);

            m_rate_limit           = res.rate_limit;
            m_rate_limit_remaining = res.rate_limit_remaining;

            switch (res.response_code)
            {
            case 200:
            case 202:
            case 204:
                return(res.data);

            case 401:
                errmsg = "Authentication failed";
                if (res.data.has("error"))
                {
                    errmsg = res.data.getStringVal("error");
                }
                throw new AccessDeniedException(errmsg);

            case 403:
                if (m_rate_limit_remaining == 0)
                {
                    throw new RateLimitExceededException(/* get 'comment' from JSON */);
                }
                goto default;

            default:
                errmsg = "Unknown error (" + res.response_code + ")";
                if (res.data.has("error"))
                {
                    errmsg = res.data.getStringVal("error");
                }
                throw new ApiException(errmsg, res.response_code);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Call the DataSift API.
        /// </summary>
        /// <param name="endpoint">The endpoint to call.</param>
        /// <param name="parameters">The parameters to be passed.</param>
        /// <returns>A JSONdn object containing the JSON response data.</returns>
        public JSONdn callApi(string endpoint, Dictionary<string, string> parameters)
        {
            string errmsg = String.Empty;

            if (m_apiclient == null)
            {
                m_apiclient = new ApiClient(getUsername(), getApiKey(), API_BASE_URL, USER_AGENT);
            }

            ApiResponse res = m_apiclient.callAPI(endpoint, parameters);

            m_rate_limit = res.rate_limit;
            m_rate_limit_remaining = res.rate_limit_remaining;

            switch (res.response_code)
            {
                case 200:
                case 202:
                case 204:
                    return res.data;
                case 401:
                    errmsg = "Authentication failed";
                    if (res.data.has("error"))
                    {
                        errmsg = res.data.getStringVal("error");
                    }
                    throw new AccessDeniedException(errmsg);
                case 403:
                    if (m_rate_limit_remaining == 0)
                    {
                        throw new RateLimitExceededException(/* get 'comment' from JSON */);
                    }
                    goto default;
                default:
                    errmsg = "Unknown error (" + res.response_code + ")";
                    if (res.data.has("error"))
                    {
                        errmsg = res.data.getStringVal("error");
                    }
                    throw new ApiException(errmsg, res.response_code);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Set the API client delegate.
 /// </summary>
 /// <param name="callapi">The delegate.</param>
 public void setApiClient(AbstractApiClient apiclient)
 {
     m_apiclient = apiclient;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Set the API client delegate.
 /// </summary>
 /// <param name="callapi">The delegate.</param>
 public void setApiClient(AbstractApiClient apiclient)
 {
     m_apiclient = apiclient;
 }