Initial working version
still a lot to do
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import configparser
|
||||
import logging
|
||||
from pprint import pprint
|
||||
|
||||
from ActiveCollabAPI.ACAuthenticator import ACAuthenticator
|
||||
from ActiveCollabAPI.ACClient import ACClient
|
||||
from ActiveCollabAPI.ACTokenAuthenticator import ACTokenAuthenticator
|
||||
|
||||
# Enabling debugging at http.client level (requests->urllib3->http.client)
|
||||
# you will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
|
||||
# the only thing missing will be the response.body which is not logged.
|
||||
from http.client import HTTPConnection
|
||||
|
||||
|
||||
HTTPConnection.debuglevel = 1
|
||||
|
||||
logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
requests_log = logging.getLogger("urllib3")
|
||||
requests_log.setLevel(logging.DEBUG)
|
||||
requests_log.propagate = True
|
||||
|
||||
if __name__ == "__main__":
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
|
||||
# FIXME: put into config
|
||||
username = config['LOGIN']['username']
|
||||
password = config['LOGIN']['password']
|
||||
account_name = config['LOGIN']['account_name']
|
||||
|
||||
# 1. you need to login to get a session and a list of accounts
|
||||
# (here we use only the first account)
|
||||
auth = ACAuthenticator()
|
||||
session = auth.login(username, password)
|
||||
pprint(session)
|
||||
user = session['user']
|
||||
# use first account
|
||||
account = auth.find_account(account_name)
|
||||
|
||||
# 2. you need to get a token for this account
|
||||
token = ACTokenAuthenticator(account, user).issue_token_intent()
|
||||
pprint(token)
|
||||
|
||||
# 3. now you can query the API
|
||||
ac = ACClient(account, token)
|
||||
res = ac.get_projects()
|
||||
pprint(res.json())
|
||||
|
||||
res = ac.get_info()
|
||||
pprint(res.json())
|
||||
Reference in New Issue
Block a user