-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGimmeProxyRequest.cs
More file actions
183 lines (150 loc) · 4.83 KB
/
GimmeProxyRequest.cs
File metadata and controls
183 lines (150 loc) · 4.83 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace GimmeProxy;
/// <summary>
/// Defines the filtering parameters when requesting a random proxy.
/// </summary>
[DataContract]
public class GimmeProxyRequest
{
/// <summary>
/// Optional API key, allows to scrape faster and enables the <see cref="Websites"/> option.
/// </summary>
/// <remarks>
/// https://gimmeproxy.com/#pricing
/// </remarks>
public string? ApiKey { get; set; }
/// <summary>
/// Return only proxies that support GET requests.
/// </summary>
public bool? SupportsGet { get; set; }
/// <summary>
/// Return only proxies that support POST requests.
/// </summary>
public bool? SupportsPost { get; set; }
/// <summary>
/// Return only proxies that support cookies.
/// </summary>
public bool? SupportsCookies { get; set; }
/// <summary>
/// Return only proxies that support the 'referer' header.
/// </summary>
public bool? SupportsReferer { get; set; }
/// <summary>
/// Return only proxies that support the 'user-agent' header.
/// </summary>
public bool? SupportsUserAgent { get; set; }
/// <summary>
/// Return only proxies that support HTTPS.
/// </summary>
public bool? SupportsHttps { get; set; }
/// <summary>
/// Return only anonymous proxies.
/// </summary>
public bool? AnonymousOnly { get; set; }
/// <summary>
/// Return only proxies with supported protocols.
/// </summary>
public Protocols Protocols { get; set; }
/// <summary>
/// Return only proxies with supported ports.
/// </summary>
public ICollection<int> Ports { get; } = [];
/// <summary>
/// Return only proxies with specified countries.
/// </summary>
/// <remarks>
/// https://www.nationsonline.org/oneworld/country_code_list.htm
/// </remarks>
public ICollection<string> IncludeCountries { get; } = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Exclude proxies with specified countries.
/// </summary>
/// <remarks>
/// https://www.nationsonline.org/oneworld/country_code_list.htm
/// </remarks>
public ICollection<string> ExcludeCountries { get; } = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Return only proxies checked in last number of seconds.
/// </summary>
public int? CheckedSecondsAgo { get; set; }
/// <summary>
/// Return only proxies allowed by particular websites.
/// </summary>
/// <remarks>
/// Requires an API key.
/// </remarks>
public Websites Websites { get; set; }
/// <summary>
/// Return only proxies with speed more than specified maximum.
/// </summary>
public float? MinimumSpeedInKilobytes { get; set; }
/// <inheritdoc/>
public override string ToString()
{
// https://gimmeproxy.com/#api
var parameters = new List<string>();
if (!string.IsNullOrEmpty(ApiKey))
{
parameters.Add($"api_key={ApiKey}");
}
if (SupportsGet.HasValue)
{
parameters.Add($"get={SupportsGet.Value.ToString().ToLowerInvariant()}");
}
if (SupportsPost.HasValue)
{
parameters.Add($"post={SupportsPost.Value.ToString().ToLowerInvariant()}");
}
if (SupportsCookies.HasValue)
{
parameters.Add($"cookies={SupportsCookies.Value.ToString().ToLowerInvariant()}");
}
if (SupportsReferer.HasValue)
{
parameters.Add($"referer={SupportsReferer.Value.ToString().ToLowerInvariant()}");
}
if (SupportsUserAgent.HasValue)
{
parameters.Add($"user-agent={SupportsUserAgent.Value.ToString().ToLowerInvariant()}");
}
if (SupportsHttps.HasValue)
{
parameters.Add($"supportsHttps={SupportsHttps.Value.ToString().ToLowerInvariant()}");
}
if (AnonymousOnly.HasValue)
{
parameters.Add($"anonymityLevel={(AnonymousOnly.Value ? "1" : "0")}");
}
if (Protocols != Protocols.None)
{
parameters.Add($"protocol={Protocols.ToString().ToLowerInvariant().Replace(" ", string.Empty)}");
}
if (Ports.Count > 0)
{
parameters.Add($"port={string.Join(",", Ports)}");
}
if (IncludeCountries.Count > 0)
{
parameters.Add($"country={string.Join(",", IncludeCountries).ToUpperInvariant()}");
}
if (ExcludeCountries.Count > 0)
{
parameters.Add($"notCountry={string.Join(",", ExcludeCountries).ToUpperInvariant()}");
}
if (CheckedSecondsAgo.HasValue)
{
parameters.Add($"maxCheckPeriod={CheckedSecondsAgo.Value.ToString().ToLowerInvariant()}");
}
if (Websites != Websites.None)
{
parameters.Add($"websites={Websites.ToString().ToLowerInvariant().Replace(" ", string.Empty)}");
}
if (MinimumSpeedInKilobytes.HasValue)
{
parameters.Add($"minSpeed={MinimumSpeedInKilobytes.Value}");
}
return ("https://gimmeproxy.com/api/getProxy?" + string.Join("&", parameters)).TrimEnd('?');
}
}