Update examples to support v0.11

This commit is contained in:
SantaSpeen 2022-03-17 21:36:08 +03:00
parent 41d84948d2
commit 2dd969db93
2 changed files with 44 additions and 27 deletions

View File

@ -1,27 +0,0 @@
from gitflic import Gitflic, GitflicAuth
token = "token_here" # https://gitflic.ru/settings/oauth/token/create
gf_session = GitflicAuth(token)
gf = Gitflic(gf_session)
def main():
me_call = gf.call("/user/me")
print(me_call)
# Register call
gf.user = gf.reg_call("/user")
# Request "https://api.gitflic.ru/user/me"
me_with_reg = gf.user("/me")
print(me_with_reg)
print("Is me_with_reg equals me_call:", me_with_reg == me_call)
# Request "https://api.gitflic.ru/user/a4189db1-3e4f-4c2e-8adf-19c58c28e61f"
author = gf.user("/a4189db1-3e4f-4c2e-8adf-19c58c28e61f")
print("\nAuthor: ", author)
if __name__ == '__main__':
main()

44
examples/reg_call.py Normal file
View File

@ -0,0 +1,44 @@
from gitflic import Gitflic, GitflicAuth
# Your authentication token.
# See: https://gitflic.ru/settings/oauth/token/create
token = "token_here"
# Creating authorized session with our token.
gf_session = GitflicAuth(token)
gf = Gitflic(gf_session)
def main():
print("Simple call:")
# Call method "https://api.gitflic.ru/user/me"
call = gf.call("/user/me")
print("gf.call:", call)
print("\nSimple register call:")
# Register call
gf.user_simple = gf.reg_call("/user")
# Request "https://api.gitflic.ru/user/me"
reg_user_simple = gf.user_simple(end="/me")
print("reg_user_simple:", reg_user_simple)
print("Is reg_user_simple equals call:", reg_user_simple == call)
print("\nAnother register call:")
# Another way to register
# Add at v0.11
gf.user = gf.reg_call("/user/{user}") # Supports "/user/{}" and "/user/%(user)s" and "/user/%s"
# Request "https://api.gitflic.ru/user/me"
reg_user = gf.user(user="me")
print("reg_user:", reg_user)
print("Is reg_user equals call:", reg_user == call)
# Request "https://api.gitflic.ru/user/a4189db1-3e4f-4c2e-8adf-19c58c28e61f"
author = gf.user(user="a4189db1-3e4f-4c2e-8adf-19c58c28e61f")
print("\nAuthor: ", author)
if __name__ == '__main__':
main()