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); }
protected HttpRequest(Resource resource, IRequestBody body) { Resource = resource; Body = body; AllowAutoRedirect = true; }
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); }
public Resource Append(Resource resource) { var combined = resource.Path.StartsWith("/") ? string.Concat(Path, resource.Path) : string.Concat(Path, "/", resource.Path); return new Resource(combined); }
protected override string BuildRequestUrl(Resource resource) { if (!resource.HasParameters) { return resource.Path; } var queryString = resource.GetEncodedParameters(); return string.Concat(resource.Path, "?", queryString); }
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; }
public DefaultRequestBody(Resource resource) { this.resource = resource; }
protected override string BuildRequestUrl(Resource resource) { return resource.Path; }
protected PostLikeRequest(Resource resource, IRequestBody body) : base(resource) { Body = body; }
protected PostLikeRequest(Resource resource) : base(resource) { Body = new DefaultRequestBody(resource); }
public HeadRequest(Resource resource) : base(resource) { }
public MultipartMimeDocumentBody(Resource resource, IFile[] files) { this.resource = resource; this.files = files; }
public OptionsRequest(Resource resource) : base(resource) { }
protected GetLikeRequest(Resource resource) : base(resource) { }
public PostRequestBody(Resource resource) { this.resource = resource; }