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
|
Web service
===========
Articles
--------
.. code-block:: python
>>> import requests, json
>>> r = requests.get("https://pyaggr3g470r.herokuapp.com/api/v2.0/articles",
... auth=("your-nickname", "your-password"))
>>> r.status_code
200 # OK
>>> rjson = r.json()
>>> rjson[0]["title"]
'Sponsors required for KDE code sprint in Randa'
>>> rjson[0]["date"]
'Wed, 18 Jun 2014 14:25:18 GMT'
Add an article:
.. code-block:: python
>>> import requests, json
>>> headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
>>> payload = {'link': 'http://blog.cedricbonhomme.org/2014/05/24/sortie-de-pyaggr3g470r-5-3/',
... 'title': 'Sortie de pyAggr3g470r 5.3',
... 'content':'La page principale de pyAggr3g470r a été améliorée...',
... 'date':'2014/06/23T11:42:20 GMT',
... 'feed_id':'42'}
>>> r = requests.post("https://pyaggr3g470r.herokuapp.com/api/v2.0/article",
... headers=headers, auth=("your-nickname", "your-password"),
... data=json.dumps(payload))
>>> r.status_code
201 # Created
>>> # creating several articles at once
>>> r = requests.post("https://pyaggr3g470r.herokuapp.com/api/v2.0/article",
... headers=headers, auth=("your-nickname", "your-password"),
... data=json.dumps([payload, payload]))
>>> r.status_code
201 # Created
>>> r.json()
[123456, 234567]
>>> r = requests.get("https://pyaggr3g470r.herokuapp.com/api/v2.0/articles",
... auth=("your-nickname", "your-password")
... data=json.dumps({'feed_id': 42, 'limit': 1}))
>>> r.json()[0]["title"]
"Sortie de pyAggr3g470r 5.3"
Update an article:
.. code-block:: python
>>> import requests, json
>>> r = requests.put("https://pyaggr3g470r.herokuapp.com/api/v2.0/article/65",
... headers={'Content-Type': 'application/json'},
... auth=("your-nickname", "your-password"),
... data=json.dumps({"like":True, "readed": False}))
>>> r.status_code
200 # OK
>>> r = requests.put("https://pyaggr3g470r.herokuapp.com/api/v2.0/articles",
... headers={'Content-Type': 'application/json'},
... auth=("your-nickname", "your-password"),
... data=json.dumps([[1, {"like": True, "readed": False}],
... [2, {"like": True, "readed": True}]]))
>>> r.json()
['ok', 'ok']
Delete one or several article(s):
.. code-block:: python
>>> import json, requests
>>> r = requests.delete("https://pyaggr3g470r.herokuapp.com/api/v2.0/article/84574",
... headers={'Content-Type': 'application/json'},
... auth=("your-nickname", "your-password"))
>>> r.status_code
204 # deleted - No content
>>> r = requests.delete("https://pyaggr3g470r.herokuapp.com/api/v2.0/article/84574",
... headers={'Content-Type': 'application/json'},
... auth=("your-nickname", "your-password"))
>>> r.status_code
404 # not found
>>> r = requests.delete("https://pyaggr3g470r.herokuapp.com/api/v2.0/articles",
... headers={'Content-Type': 'application/json'},
... auth=("your-nickname", "your-password")
... data=json.dumps([84574]))
>>> r.status_code
500 # already deleted
>>> r = requests.delete("https://pyaggr3g470r.herokuapp.com/api/v2.0/articles",
... headers={'Content-Type': 'application/json'},
... auth=("your-nickname", "your-password")
... data=json.dumps([84575, 84576]))
>>> r.status_code
204 # deleted - No content
>>> r = requests.delete("https://pyaggr3g470r.herokuapp.com/api/v2.0/articles",
... headers={'Content-Type': 'application/json'},
... auth=("your-nickname", "your-password")
... data=json.dumps([84575, 84576, 84577]))
>>> r.status_code
206 # partial - some deleted
>>> r.json()
['404 - Not Found', '404 - Not Found', 'ok']
Feeds
-----
Add a feed:
.. code-block:: python
>>> import json, requests
>>> r = requests.post("https://pyaggr3g470r.herokuapp.com/api/v2.0/feeds",
... auth=("your-nickname", "your-password"),
... headers={'Content-Type': 'application/json'},
... data=json.dumps({'link': 'http://blog.cedricbonhomme.org/feed'}))
>>> r.status_code
200
Update a feed:
.. code-block:: python
>>> import json, requests
>>> r = requests.put("https://pyaggr3g470r.herokuapp.com/api/v2.0/feeds/42",
... auth=("your-nickname", "your-password"),
... headers={'Content-Type': 'application/json'},
... data=json.dumps({"title":"Feed new title", "description":"New description"})
>>> r.status_code
201
Delete a feed:
.. code-block:: python
>>> import requests
>>> r = requests.delete("https://pyaggr3g470r.herokuapp.com/api/v2.0/feeds/29",
... auth=("your-nickname", "your-password"))
|