예제 #1
0
        public PushListResponse GetAllPushes(PushListRequestContent listPushParams)
        {
            if (listPushParams == null)
            {
                throw new ParameterValueIsNullException("listPushParams is null.");
            }

            if (Helpers.IsNullOrEmpty(ClientAccessToken))
            {
                throw new IncorrectAccessTokenException(ClientAccessToken);
            }

            string requestUrl = "https://api.pushbullet.com/v2/pushes";
            Dictionary <string, string> paramsValue = new Dictionary <string, string>();

            if (!Helpers.IsNullOrEmpty(listPushParams.Cursor))
            {
                paramsValue.Add("cursor", listPushParams.Cursor);
            }

            if (!Helpers.IsNullOrEmpty(listPushParams.ModifiedAfter))
            {
                paramsValue.Add("modified_after", listPushParams.ModifiedAfter);
            }

            if (listPushParams.MaxResults > 0)
            {
                paramsValue.Add("limit", listPushParams.MaxResults.ToString());
            }

            if (listPushParams.ActiveOnly)
            {
                paramsValue.Add("active", listPushParams.ActiveOnly.ToString().ToLower());
            }

            (bool requestStatus, string response) = FetchApiResponse(requestUrl, Method.GET, false, paramsValue);

            if (!requestStatus && Helpers.IsNullOrEmpty(response))
            {
                return(null);
            }

            if (!requestStatus)
            {
                throw new RequestFailedException();
            }

            if (Helpers.IsNullOrEmpty(response))
            {
                throw new ResponseIsNullException();
            }

            Logger.Log("Fetched all push notifications!");
            return(DeserializeJsonObject <PushListResponse>(response));
        }
예제 #2
0
        public async Task <PushesBase[]?> GetAllPushes(PushListRequestContent requestParams)
        {
            if (requestParams == null)
            {
                throw new ParameterValueIsNullException("listPushParams is null.");
            }

            if (string.IsNullOrEmpty(ClientAccessToken))
            {
                throw new IncorrectAccessTokenException();
            }

            string requestUrl = API_BASE_URL + GetRoute(EPUSH_ROUTES.PUSH);
            List <(string paramName, object paramValue, ParameterType paramType)> parameters = new List <(string paramName, object paramValue, ParameterType paramType)>();

            if (!string.IsNullOrEmpty(requestParams.Cursor))
            {
                parameters.Add(("cursor", requestParams.Cursor, ParameterType.QueryString));
            }

            if (!string.IsNullOrEmpty(requestParams.ModifiedAfter))
            {
                parameters.Add(("modified_after", requestParams.ModifiedAfter, ParameterType.QueryString));
            }

            if (requestParams.MaxResults > 0)
            {
                parameters.Add(("limit", requestParams.MaxResults.ToString(), ParameterType.QueryString));
            }

            if (requestParams.ActiveOnly)
            {
                parameters.Add(("active", requestParams.ActiveOnly.ToString(), ParameterType.QueryString));
            }

            var response = await GetResponseAsync(requestUrl, Method.GET, null, parameters);

            if (response == null || response.Pushes == null)
            {
                throw new RequestFailedException();
            }

            Logger.Log(nameof(GetAllPushes) + " successful.", LogLevels.Trace);
            return(response.Pushes);
        }