Skip to content

Commit 58ca90e

Browse files
committed
documentation
1 parent fbbf7be commit 58ca90e

File tree

4 files changed

+137
-6
lines changed

4 files changed

+137
-6
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,20 @@ proxy_py has server based on aiohttp which is listening 127.0.0.1:55555(you can
3737
{
3838
'model': 'proxy',
3939
'method': 'get',
40+
'order_by': 'response_time, uptime'
4041
}
4142
```
4243

44+
Note: order_by makes result sorting by one or more fields separated by comma.
45+
You can skip it. The required fields are model and method.
46+
4347
It will return json response like this:
4448

4549
```
4650
{
4751
'status': 'ok',
4852
'count': 1,
49-
'last_page': True,
53+
'has_more': True,
5054
'data': [{
5155
"address": "http://127.0.0.1:8080",
5256
"auth_data": null,
@@ -57,19 +61,19 @@ It will return json response like this:
5761
"port": 8080,
5862
"protocol": "http",
5963
"uptime": 1509460949,
60-
"white_ip_v4": null,
61-
"white_ip_v6": null,
6264
}
6365
]
6466
}
6567
```
6668

69+
Note: All fields except *protocol*, *domain*, *port*, *auth_data*, *checking_period* and *address* can be null
70+
6771
Or error if something went wrong:
6872

6973
```
7074
{
7175
'status': 'error',
72-
'error': 'You should specify model',
76+
'error_message': 'You should specify model',
7377
}
7478
```
7579

@@ -124,6 +128,10 @@ async def get_proxies():
124128
return result
125129
```
126130

131+
## API
132+
133+
More about API read [here](https://github.com/DevAlone/proxy_py/tree/master/docs/API.md)
134+
127135
## How to deploy on production using supervisor, nginx and postgresql in 8 steps?
128136

129137
1 Install supervisor, nginx and postgresql

docs/API.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# proxy_py API
2+
3+
proxy_py expects HTTP POST requests with JSON as a body, so you need
4+
to add header `Content-Type: application/json` and send correct
5+
JSON document.
6+
7+
Example of correct request:
8+
```json
9+
{
10+
"model": "proxy",
11+
"method": "get"
12+
}
13+
```
14+
15+
## Possible keys
16+
17+
* `model` - specifies what you will work with.
18+
Now it's only supported to work with `proxy` model.
19+
* `method` - what you're gonna do with it
20+
* `get` - get model items as json objects.
21+
Detailed description is below
22+
* `count` - count how many items there are.
23+
Detailed description is below
24+
25+
26+
### get method
27+
28+
`get` method supports following keys:
29+
* `order_by` (string) - specifies ordering fields as comma separated
30+
value.
31+
32+
Examples:
33+
34+
`"uptime"` just sorts proxies by uptime field ascending.
35+
36+
Note: `uptime` is the timestamp from which proxy is working,
37+
NOT proxy's working time
38+
39+
To sort descending use `-` before field name.
40+
41+
`"-response_time"` returns proxies with maximum response_time first
42+
(in microseconds)
43+
44+
It's possible to sort using multiple fields
45+
46+
`"number_of_bad_checks, response_time"` returns proxies with minimum
47+
`number_of_bad_checks` first, if there are proxies with the same
48+
`number_of_bad_checks`, sorts them by `response_time`
49+
50+
* `limit` (integer) - specifying how many proxies to return
51+
* `offset` (integer) - specifying how many proxies to skip
52+
53+
Example of `get` request:
54+
```json
55+
56+
{
57+
"model": "proxy",
58+
"method": "get",
59+
"order_by": "number_of_bad_checks, response_time",
60+
"limit": 100,
61+
"offset": 200
62+
}
63+
```
64+
65+
Response
66+
67+
```json
68+
{
69+
"count": 6569,
70+
"data": [
71+
{
72+
"address": "socks5://localhost:9999",
73+
"auth_data": "",
74+
"bad_proxy": false,
75+
"domain": "localhost",
76+
"last_check_time": 1517089048,
77+
"number_of_bad_checks": 0,
78+
"port": 9999,
79+
"protocol": "socks5",
80+
"response_time": 1819186,
81+
"uptime": 1517072132
82+
},
83+
84+
...
85+
86+
],
87+
"has_more": true,
88+
"status": "ok"
89+
}
90+
```
91+
92+
* `count` (integer) - total number of proxies for that request
93+
* `data` (array) - list of proxies
94+
* `has_more` (boolean) - value indicating whether you can increase
95+
offset to get more proxies or not
96+
* `status` (string) - "error" if error happened, "ok" otherwise
97+
98+
Example of error:
99+
100+
Request:
101+
102+
```json
103+
{
104+
"model": "user",
105+
"method": "get",
106+
"order_by": "number_of_bad_checks, response_time",
107+
"limit": 100,
108+
"offset": 200
109+
}
110+
```
111+
112+
Response:
113+
114+
```json
115+
{
116+
"error_message": ""Model \"user\" doesn't exist or isn't allowed",
117+
"status": "error"
118+
}
119+
```
120+
121+
### count method
122+
123+
Same as get, but not returns data

models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class Proxy(Base):
2828
port = Column(Integer, nullable=False)
2929
auth_data = Column(String(64), default="", nullable=False)
3030

31-
last_check_time = Column(Integer, default=0)
3231
checking_period = Column(Integer, default=settings.MIN_PROXY_CHECKING_PERIOD, nullable=False)
32+
last_check_time = Column(Integer, default=0)
3333
number_of_bad_checks = Column(Integer, default=0)
3434
uptime = Column(Integer, nullable=True, default=None)
3535
bad_uptime = Column(Integer, nullable=True, default=None)

server/requests_to_models/request_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def parse_dict(self, req_dict):
9696
raise ParseError('You should specify "model"')
9797

9898
if req_dict['model'] not in self.config:
99-
raise ParseError("Model doesn't exist or isn't allowed")
99+
raise ParseError("Model \"{}\" doesn't exist or isn't allowed".format(req_dict['model']))
100100

101101
config = self.config[req_dict['model']]
102102

0 commit comments

Comments
 (0)