예제 #1
0
        private Resource MergeUrlSegments(Resource resource, object segments, IDictionary<string, PropertyInfo> properties)
        {
            var merged = resource.Path;

            foreach (var segmentName in resource.SegmentNames)
            {
                var lowerSegmentName = segmentName.ToLower();

                PropertyInfo property;
                if (!properties.TryGetValue(lowerSegmentName, out property))
                {
                    throw new ArgumentException("Could not find a property matching segment: " + segmentName);
                }

                var propertyValue = property.GetValue(segments, new object[0]);

                if (propertyValue == null)
                {
                    var message = string.Format(
                        "Could not merge url segment with name {0} because the value of the segment was null. " +
                        "When passing in segments for a url make sure each property has a value if it is to be used in the url.",
                        segmentName);

                    throw new ArgumentException(message);
                }

                merged = merged.Replace(":" + segmentName, propertyValue.ToString());

                properties.Remove(lowerSegmentName);
            }

            return new Resource(merged);
        }
예제 #2
0
        protected HttpRequest(Resource resource, IRequestBody body)
        {
            Resource = resource;
            Body = body;

            AllowAutoRedirect = true;
        }
예제 #3
0
        public Resource Merge(Resource resource, object segments, bool shouldMergeProperties = true)
        {
            if (!resource.HasSegments && segments == null)
            {
                return resource;
            }

            if (segments == null)
            {
                var message = string.Format(
                    "The resource {0} requires the following segments, but none were given: {1}",
                    resource.Path,
                    string.Join(", ", resource.SegmentNames));

                throw new ArgumentException(message);
            }

            var properties = segments
                .GetType()
                .GetProperties()
                .ToDictionary(p => p.Name.ToLower());

            var mergedResource = MergeUrlSegments(resource, segments, properties);

            if (!shouldMergeProperties)
            {
                return mergedResource;
            }

            return AddMergedParameters(mergedResource, segments, properties);
        }
예제 #4
0
        public Resource Append(Resource resource)
        {
            var combined =
                resource.Path.StartsWith("/")
                    ? string.Concat(Path, resource.Path)
                    : string.Concat(Path, "/", resource.Path);

            return new Resource(combined);
        }
예제 #5
0
        protected override string BuildRequestUrl(Resource resource)
        {
            if (!resource.HasParameters)
            {
                return resource.Path;
            }

            var queryString = resource.GetEncodedParameters();

            return string.Concat(resource.Path, "?", queryString);
        }
예제 #6
0
        private Resource AddMergedParameters(Resource mergedResource, object segments, Dictionary<string, PropertyInfo> properties)
        {
            foreach (var property in properties.Values)
            {
                var parameterName = NamingConvention.ConvertPropertyNameToParameterName(property.Name);
                var parameterValue = property.GetValue(segments, new object[0]);

                mergedResource.AddParameter(parameterName, parameterValue);
            }

            return mergedResource;
        }
예제 #7
0
 public DefaultRequestBody(Resource resource)
 {
     this.resource = resource;
 }
예제 #8
0
 protected override string BuildRequestUrl(Resource resource)
 {
     return resource.Path;
 }
예제 #9
0
 protected PostLikeRequest(Resource resource, IRequestBody body)
     : base(resource)
 {
     Body = body;
 }
예제 #10
0
 protected PostLikeRequest(Resource resource)
     : base(resource)
 {
     Body = new DefaultRequestBody(resource);
 }
예제 #11
0
 public HeadRequest(Resource resource)
     : base(resource)
 {
 }
 public MultipartMimeDocumentBody(Resource resource, IFile[] files)
 {
     this.resource = resource;
     this.files = files;
 }
예제 #13
0
 public OptionsRequest(Resource resource)
     : base(resource)
 {
 }
예제 #14
0
 protected GetLikeRequest(Resource resource)
     : base(resource)
 {
 }
예제 #15
0
 public PostRequestBody(Resource resource)
 {
     this.resource = resource;
 }