Skip to content

Commit b427fa7

Browse files
committed
added support for headers in response
1 parent f72bc72 commit b427fa7

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using System.Net;
4+
5+
#if NET35
6+
using Headers = System.Net.WebHeaderCollection;
7+
#else
8+
using Headers = System.Net.Http.Headers.HttpResponseHeaders;
9+
#endif
10+
11+
namespace Twilio.Base
12+
{
13+
/// <summary>
14+
/// Wrapper class that contains both the resource set and HTTP response headers.
15+
/// Implements IEnumerable to allow direct iteration over records.
16+
/// </summary>
17+
/// <typeparam name="T">The type of the resource</typeparam>
18+
public class ResourceSetWithHeaders<T> : IEnumerable<T> where T : Resource
19+
{
20+
/// <summary>
21+
/// The resource set containing the records
22+
/// </summary>
23+
public ResourceSet<T> Records { get; }
24+
25+
/// <summary>
26+
/// HTTP response headers from the initial request
27+
/// </summary>
28+
public Headers Headers { get; }
29+
30+
/// <summary>
31+
/// HTTP status code from the initial request
32+
/// </summary>
33+
public HttpStatusCode StatusCode { get; }
34+
35+
/// <summary>
36+
/// Create a new ResourceSetWithHeaders
37+
/// </summary>
38+
/// <param name="records">The resource set containing records</param>
39+
/// <param name="headers">HTTP response headers</param>
40+
/// <param name="statusCode">HTTP status code</param>
41+
public ResourceSetWithHeaders(ResourceSet<T> records, Headers headers, HttpStatusCode statusCode)
42+
{
43+
Records = records;
44+
Headers = headers;
45+
StatusCode = statusCode;
46+
}
47+
48+
/// <summary>
49+
/// Get enumerator for iterating over resources
50+
/// </summary>
51+
/// <returns>IEnumerator of resources</returns>
52+
public IEnumerator<T> GetEnumerator()
53+
{
54+
return Records.GetEnumerator();
55+
}
56+
57+
/// <summary>
58+
/// Get enumerator for iterating over resources
59+
/// </summary>
60+
/// <returns>IEnumerator of resources</returns>
61+
IEnumerator IEnumerable.GetEnumerator()
62+
{
63+
return GetEnumerator();
64+
}
65+
}
66+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Net;
2+
3+
#if NET35
4+
using Headers = System.Net.WebHeaderCollection;
5+
#else
6+
using Headers = System.Net.Http.Headers.HttpResponseHeaders;
7+
#endif
8+
9+
namespace Twilio.Base
10+
{
11+
/// <summary>
12+
/// Wrapper class that contains both the resource and HTTP response headers
13+
/// </summary>
14+
/// <typeparam name="T">The type of the resource</typeparam>
15+
public class ResourceWithHeaders<T>
16+
{
17+
/// <summary>
18+
/// The resource data
19+
/// </summary>
20+
public T Data { get; }
21+
22+
/// <summary>
23+
/// HTTP response headers
24+
/// </summary>
25+
public Headers Headers { get; }
26+
27+
/// <summary>
28+
/// HTTP status code
29+
/// </summary>
30+
public HttpStatusCode StatusCode { get; }
31+
32+
/// <summary>
33+
/// Create a new ResourceWithHeaders
34+
/// </summary>
35+
/// <param name="data">The resource data</param>
36+
/// <param name="headers">HTTP response headers</param>
37+
/// <param name="statusCode">HTTP status code</param>
38+
public ResourceWithHeaders(T data, Headers headers, HttpStatusCode statusCode)
39+
{
40+
Data = data;
41+
Headers = headers;
42+
StatusCode = statusCode;
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)