Skip to content

Commit deea8ac

Browse files
committed
Add doc
1 parent 27eaf1b commit deea8ac

File tree

2 files changed

+85
-12
lines changed

2 files changed

+85
-12
lines changed

doc/Telegraph.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# class Telegraph(object):
2+
3+
## Methods defined here:
4+
### \_\_init\_\_
5+
6+
- access_token (default: `None`) — Telegraph access token
7+
8+
### create_account
9+
Create a new Telegraph account
10+
- short_name — Account name, helps users with several accounts remember which they are currently using. Displayed to the user above the "Edit/Publish" button on Telegra.ph, other users don't see this name
11+
- author_name (default: `None`) — Default author name used when creating new articles
12+
- author_url (default: `None`) — Default profile link, opened when users click on the author's name below the title. Can be any link, not necessarily to a Telegram profile or channels
13+
- replace_token (default: `True`) — Replaces current token to a new user's token
14+
15+
### create_page
16+
Create a new Telegraph page
17+
- title — Page title
18+
- content (default: `None`) — Content in nodes list format (see doc)
19+
- html_content (default: `None`) — Content in HTML format
20+
- author_name (default: `None`) — Author name, displayed below the article's title
21+
- author_url (default: `None`) — Profile link, opened when users click on the author's name below the title
22+
- return_content (default: `False`) — If true, a content field will be returned
23+
24+
### edit_account_info
25+
Update information about a Telegraph account. Pass only the parameters that you want to edit
26+
- short_name (default: `None`) — Account name, helps users with several accounts remember which they are currently using. Displayed to the user above the "Edit/Publish" button on Telegra.ph, other users don't see this name
27+
- author_name (default: `None`) — Default author name used when creating new articles
28+
- author_url (default: `None`) — Default profile link, opened when users click on the author's name below the title. Can be any link, not necessarily to a Telegram profile or channels
29+
30+
### edit_page
31+
Edit an existing Telegraph page
32+
- path — Path to the page
33+
- title — Page title
34+
- content (default: `None`) — Content in nodes list format (see doc)
35+
- html_content (default: `None`) — Content in HTML format
36+
- author_name (default: `None`) — Author name, displayed below the article's title
37+
- author_url (default: `None`) — Profile link, opened when users click on the author's name below the title
38+
- return_content (default: `False`) — If true, a content field will be returned
39+
40+
### get_access_token
41+
Return current access_token
42+
43+
### get_account_info
44+
Get information about a Telegraph account
45+
- fields (default: `None`) — List of account fields to return. Available fields: short_name, author_name, author_url, auth_url, page_count Default: [“short_name”,“author_name”,“author_url”]
46+
47+
### get_page
48+
Get a Telegraph page
49+
- path — Path to the Telegraph page (in the format Title-12-31, i.e. everything that comes after [http://telegra.ph/](http://telegra.ph/))
50+
- return_content (default: `True`) — If true, content field will be returned
51+
- return_html (default: `True`) — If true, returns HTML instead of Nodes list
52+
53+
### get_page_list
54+
Get a list of pages belonging to a Telegraph account sorted by most recently created pages first
55+
- offset (default: `0`) — Sequential number of the first page to be returned (default = 0)
56+
- limit (default: `50`) — Limits the number of pages to be retrieved (0-200, default = 50)
57+
58+
### get_views
59+
Get the number of views for a Telegraph article
60+
- path — Path to the Telegraph page
61+
- year (default: `None`) — Required if month is passed. If passed, the number of page views for the requested year will be returned
62+
- month (default: `None`) — Required if day is passed. If passed, the number of page views for the requested month will be returned
63+
- day (default: `None`) — Required if hour is passed. If passed, the number of page views for the requested day will be returned
64+
- hour (default: `None`) — If passed, the number of page views for the requested hour will be returned
65+
66+
### revoke_access_token
67+
Revoke access_token and generate a new one, for example, if the user would like to reset all connected sessions, or you have reasons to believe the token was compromised. On success, returns dict with new access_token and auth_url fields
68+

telegraph/api.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99

1010
class TelegraphApi(object):
11+
""" Telegraph Api Client
12+
13+
"""
14+
1115
__slots__ = ('access_token', 'session')
1216

1317
def __init__(self, access_token=None):
@@ -19,33 +23,33 @@ def __init__(self, access_token=None):
1923
self.access_token = access_token
2024
self.session = requests.Session()
2125

22-
def method(self, method, values=None, path=None):
23-
24-
if values is not None:
25-
values = values.copy()
26-
else:
27-
values = {}
26+
def method(self, method, values=None, path=''):
27+
values = values.copy() if values is not None else {}
2828

2929
if 'access_token' not in values and self.access_token:
3030
values['access_token'] = self.access_token
3131

3232
response = self.session.post(
33-
'https://api.telegra.ph/{}/{}'.format(method, path if path else ''),
33+
'https://api.telegra.ph/{}/{}'.format(method, path),
3434
values
3535
).json()
3636

3737
if response.get('ok'):
3838
return response['result']
39-
else:
40-
raise TelegraphException(response.get('error'))
39+
40+
raise TelegraphException(response.get('error'))
4141

4242

4343
class Telegraph(object):
44-
__slots__ = ('_telegraph', '_method')
44+
__slots__ = ('_telegraph',)
45+
46+
def __init__(self, access_token=None):
47+
"""
48+
49+
:param access_token: Telegraph access token
50+
"""
4551

46-
def __init__(self, access_token=None, method=None):
4752
self._telegraph = TelegraphApi(access_token)
48-
self._method = method
4953

5054
def get_access_token(self):
5155
""" Return current access_token
@@ -121,6 +125,7 @@ def get_page(self, path, return_content=True, return_html=True):
121125
i.e. everything that comes after http://telegra.ph/)
122126
123127
:param return_content: If true, content field will be returned
128+
:param return_html: If true, returns HTML instead of Nodes list
124129
"""
125130

126131
response = self._telegraph.method('getPage', path=path, values={

0 commit comments

Comments
 (0)