Cleanup some mess
still a lot to do
This commit is contained in:
@@ -4,21 +4,21 @@ import json
|
||||
# 3rd party libs
|
||||
import requests
|
||||
|
||||
from ActiveCollabAPI import AC_LOGIN_BASE_URL, AC_USER_AGENT
|
||||
|
||||
|
||||
class ACAuthenticator:
|
||||
|
||||
base_url = AC_LOGIN_BASE_URL
|
||||
|
||||
user = None
|
||||
accounts = None
|
||||
|
||||
# FIXME: put into config
|
||||
# This is only for cloud instance!
|
||||
base_url = 'https://activecollab.com/api/v1/external/login'
|
||||
|
||||
def headers(self):
|
||||
return {
|
||||
'Content-Type': 'application/json; charset=utf8',
|
||||
'Accept': 'application/json',
|
||||
'User-Agent': 'Active Collab API Wrapper; v3.0.0'
|
||||
'User-Agent': AC_USER_AGENT
|
||||
}
|
||||
|
||||
def login(self, email, password):
|
||||
|
||||
@@ -2,33 +2,27 @@ import json
|
||||
|
||||
import requests
|
||||
|
||||
from ActiveCollabAPI import AC_USER_AGENT, AC_API_VERSION
|
||||
|
||||
|
||||
class ACClient:
|
||||
|
||||
base_url = None
|
||||
account = None
|
||||
token = None
|
||||
|
||||
base_url = None
|
||||
|
||||
# FIXME: put into config
|
||||
# API Version
|
||||
api_version = '1'
|
||||
|
||||
# FIXME: put into config
|
||||
user_agent = 'Active Collab API Wrapper; v3.0.0'
|
||||
|
||||
def __init__(self, account, token):
|
||||
self.account = account
|
||||
self.token = token
|
||||
#
|
||||
self.base_url = self.account['url'] + '/api/v%s' % self.api_version
|
||||
self.base_url = self.account['url'] + '/api/v%d' % AC_API_VERSION
|
||||
|
||||
def headers(self):
|
||||
return {
|
||||
'Content-Type': 'application/json; charset=utf8',
|
||||
'Accept': 'application/json',
|
||||
'X-Angie-AuthApiToken': self.token,
|
||||
'User-Agent': self.user_agent
|
||||
'User-Agent': AC_USER_AGENT
|
||||
}
|
||||
|
||||
def _get(self, url):
|
||||
|
||||
@@ -2,6 +2,8 @@ import json
|
||||
|
||||
import requests
|
||||
|
||||
from ActiveCollabAPI import AC_USER_AGENT, AC_API_VERSION, AC_API_CLIENT_NAME, AC_API_CLIENT_VENDOR
|
||||
|
||||
|
||||
class ACTokenAuthenticator:
|
||||
|
||||
@@ -10,29 +12,18 @@ class ACTokenAuthenticator:
|
||||
base_url = ""
|
||||
token = None
|
||||
|
||||
# FIXME: put into config
|
||||
client_name = 'Python Script'
|
||||
client_vendor = 'Me'
|
||||
|
||||
# FIXME: put into config
|
||||
# API Version
|
||||
api_version = '1'
|
||||
|
||||
# FIXME: put into config
|
||||
user_agent = 'Active Collab API Wrapper; v3.0.0'
|
||||
|
||||
def __init__(self, account, user):
|
||||
self.account = account
|
||||
self.user = user
|
||||
#
|
||||
self.base_url = self.account['url'] + '/api/v%s' % self.api_version
|
||||
self.base_url = self.account['url'] + '/api/v%s' % AC_API_VERSION
|
||||
|
||||
def issue_token_intent(self):
|
||||
# use intent to get a token
|
||||
data = {
|
||||
'intent': self.user['intent'],
|
||||
'client_name': self.client_name,
|
||||
'client_vendor': self.client_vendor
|
||||
'client_name': AC_API_CLIENT_NAME,
|
||||
'client_vendor': AC_API_CLIENT_VENDOR
|
||||
}
|
||||
r = requests.post(self.base_url+ '/issue-token-intent',
|
||||
headers=self.headers(),
|
||||
@@ -48,5 +39,5 @@ class ACTokenAuthenticator:
|
||||
return {
|
||||
'Content-Type': 'application/json; charset=utf8',
|
||||
'Accept': 'application/json',
|
||||
'User-Agent': self.user_agent
|
||||
'User-Agent': AC_USER_AGENT
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
# this is the base url for the cloud version
|
||||
AC_LOGIN_BASE_URL: str = 'https://activecollab.com/api/v1/external/login'
|
||||
|
||||
AC_API_VERSION: int = 1
|
||||
|
||||
AC_API_CLIENT_NAME: str = 'Python Script'
|
||||
AC_API_CLIENT_VENDOR: str = 'Me'
|
||||
|
||||
AC_USER_AGENT: str = 'Active Collab API Wrapper; v3.0.0'
|
||||
|
||||
Reference in New Issue
Block a user