Skip to content

Commit 1e2967a

Browse files
committed
Tweak docs
1 parent 8fa5efb commit 1e2967a

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed

docs/examples.rst

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Below is an example illustrating how to retrieve information about a repository:
2424
print("Repository is not a fork")
2525

2626

27-
Example 2: Updating a User
27+
Example 2: Updating a user
2828
--------------------------
2929

3030
Below is an example demonstrating how to update a user (requires admin privileges)::
@@ -50,25 +50,13 @@ Below is an example demonstrating how to update a user (requires admin privilege
5050
Example 3: Creating a token
5151
---------------------------
5252

53-
Below is an example illustrating how to create a token for you application::
53+
Below is an example illustrating how to create a token::
5454

5555
import gogs_client
56-
from getpass import getpass
57-
from platform import node
5856

59-
api = GogsApi("https://try.gogs.io/")
60-
61-
try: token_str = open("tokenfile.txt","r").read()
62-
except OSError: token_str = None
63-
if token_str:
64-
token = gogs_client.Token(token_str)
65-
else:
66-
username = input("username> ")
67-
password = getpass("password> ")
68-
login = gogs_client.UsernamePassword(username, password)
69-
token = api.ensure_token(login, "my cool app on "+node(), username)
70-
open("tokenfile.txt", "w".write(token.token))
57+
api = gogs_client.GogsApi("https://try.gogs.io/")
7158

72-
username = api.authenticated_user(token)
73-
print("User {} authenticated by token {}".format(username, token_str))
59+
auth = gogs_client.UsernamePassword("username", "password")
60+
token = api.create_token(auth, "my_token")
7461

62+
print("token: {}, name: {}".format(token.token, token.name))

gogs_client/interface.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, base_url, session=None):
2121

2222
def valid_authentication(self, auth):
2323
"""
24-
Returns whether the provided authentication is valid
24+
Returns whether ``auth`` is valid
2525
2626
:param auth.Authentication auth: authentication object
2727
:return: whether the provided authentication is valid
@@ -32,11 +32,11 @@ def valid_authentication(self, auth):
3232

3333
def authenticated_user(self, auth):
3434
"""
35-
Returns the user authenticated by the given authentication
35+
Returns the user authenticated by ``auth``
3636
3737
:param auth.Authentication auth: authentication for user to retrieve
3838
39-
:return: user corresponding to the provided authentication
39+
:return: user authenticated by the provided authentication
4040
:rtype: GogsUser
4141
:raises NetworkFailure: if there is an error communicating with the server
4242
:raises ApiFailure: if the request cannot be serviced
@@ -46,14 +46,15 @@ def authenticated_user(self, auth):
4646

4747
def get_tokens(self, auth, username=None):
4848
"""
49-
Returns tokens defined for specified user.
50-
If no user specified uses user authenticated by the given authentication.
51-
Right now, authentication must be UsernamePassword (not Token).
49+
Returns the tokens owned by the specified user. If no user is specified,
50+
uses the user authenticated by ``auth``.
5251
53-
:param auth.Authentication auth: authentication for user to retrieve
52+
:param auth.Authentication auth: authentication for user to retrieve.
53+
Must be a username-password authentication, due to a restriction of the
54+
Gogs API
5455
:param str username: username of owner of tokens
5556
56-
:return: list of token representation
57+
:return: list of tokens
5758
:rtype: List[Token]
5859
:raises NetworkFailure: if there is an error communicating with the server
5960
:raises ApiFailure: if the request cannot be serviced
@@ -65,11 +66,12 @@ def get_tokens(self, auth, username=None):
6566

6667
def create_token(self, auth, name, username=None):
6768
"""
68-
Creates new token with specified name for specified user.
69-
If no user specified uses user authenticated by the given authentication.
70-
Right now, authentication must be UsernamePassword (not Token).
69+
Creates a new token with the specified name for the specified user.
70+
If no user is specified, uses user authenticated by ``auth``.
7171
72-
:param auth.Authentication auth: authentication for user to retrieve
72+
:param auth.Authentication auth: authentication for user to retrieve.
73+
Must be a username-password authentication, due to a restriction of the
74+
Gogs API
7375
:param str name: name of new token
7476
:param str username: username of owner of new token
7577
@@ -86,11 +88,13 @@ def create_token(self, auth, name, username=None):
8688

8789
def ensure_token(self, auth, name, username=None):
8890
"""
89-
Creates new token if token with specified name for specified user does not exists.
90-
If no user specified uses user authenticated by the given authentication.
91-
Right now, authentication must be UsernamePassword (not Token).
91+
Ensures the existence of a token with the specified name for the
92+
specified user. Creates a new token if none exists. If no user is
93+
specified, uses user authenticated by ``auth``.
9294
93-
:param auth.Authentication auth: authentication for user to retrieve
95+
:param auth.Authentication auth: authentication for user to retrieve.
96+
Must be a username-password authentication, due to a restriction of the
97+
Gogs API
9498
:param str name: name of new token
9599
:param str username: username of owner of new token
96100

0 commit comments

Comments
 (0)