-
Notifications
You must be signed in to change notification settings - Fork 129
/
Request.cs
54 lines (46 loc) · 1.47 KB
/
Request.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LinqToTwitter
{
public class Request
{
public string Endpoint { get; set; }
public IList<QueryParameter> RequestParameters { get; internal set; }
public Request(string endpoint)
{
this.Endpoint = endpoint;
this.RequestParameters = new List<QueryParameter>();
}
public string FullUrl
{
get
{
var queryString = this.QueryString;
if (queryString.Length > 0)
return Endpoint + "?" + QueryString;
else return Endpoint;
}
}
public string QueryString
{
get
{
if (RequestParameters == null)
throw new ArgumentNullException("parameters");
StringBuilder builder = new StringBuilder();
foreach (var pair in RequestParameters.Where(p => !string.IsNullOrWhiteSpace(p.Value)))
{
builder.Append(Uri.EscapeUriString(pair.Name));
builder.Append('=');
builder.Append(Uri.EscapeUriString(pair.Value));
builder.Append('&');
}
if (builder.Length > 1)
builder.Length--; // truncate trailing &
return builder.ToString();
}
}
}
}