Exemplo n.º 1
0
        internal static IObservable <object> Send(this IRestAttribute attribute, object instance, ICredentialBearer user, string requestUrl = null, Func <string, object[]> deserializeResponse = null)
        {
            requestUrl ??= attribute.RequestUrl(instance);
            var url          = $"{user.BaseAddress}{requestUrl}";
            var pollInterval = attribute.PollInterval > 0?TimeSpan.FromSeconds(attribute.PollInterval) :(TimeSpan?)null;

            return(attribute.HttpMethod().Send(url, instance, user.Key, user.Secret, deserializeResponse, pollInterval)
                   .HandleAttributeErrors(url, instance, attribute.HandleErrors));
        }
Exemplo n.º 2
0
        public static string RequestUrl(this IRestAttribute operationAttribute, object instance)
        {
            var regexObj = new Regex("(.*){([^}]*)}(.*)", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            var match    = regexObj.Match(operationAttribute.RequestUrl);

            if (match.Success)
            {
                var value = match.Groups[2].Value;
                value = $"{instance.GetTypeInfo().FindMember(value).GetValue(instance)}";
                return(Regex.Replace(operationAttribute.RequestUrl, "(?<before>.*){([^}]*)}(?<after>.*)", $"${{before}}{value}${{after}}",
                                     RegexOptions.IgnoreCase | RegexOptions.Singleline).TrimEnd('/'));
            }

            return(operationAttribute.RequestUrl.TrimEnd('/'));
        }
Exemplo n.º 3
0
 private static HttpMethod HttpMethod(this IRestAttribute attribute)
 => attribute.HttpMethod == null && attribute is RestOperationAttribute operationAttribute