def _get_client() -> Client: client = Client.access_token(config.ASANA_CREDENTIALS.token) # This suppresses a warning from the Asana API that they're moving to string based IDs # it's not an issue for us. client.headers.update({"Asana-Enable": "string_ids,new_sections"}) return client
def client(self) -> Client: """Instantiates python-asana Client""" if not self.connection.password: raise ValueError( "Asana connection password must contain a personal access token: " "https://developers.asana.com/docs/personal-access-token") return Client.access_token(self.connection.password)
def __init__(self, access_token: str) -> None: self._client = AsanaClient.access_token(access_token) self._client.headers.update({ "Asana-Enable": "new_sections,string_ids", "User-Agent": f"asana-archie/{__version__}", }) self._client.session.mount( "https://", HTTPAdapter(pool_maxsize=_CONNECTION_POOL_SIZE))
def __init__( self, token: str, project_id: Optional[str] = None, section_id: Optional[str] = None, tag_id: Optional[str] = None, ): self._client = Client.access_token(token) if project_id is not None: filter_func = lambda: self._client.tasks.find_by_project(project_id) elif section_id is not None: filter_func = lambda: self._client.tasks.find_by_section(section_id) elif tag_id is not None: filter_func = lambda: self._client.tasks.find_by_tag(tag_id) else: raise ValueError("You should set one of filter_props") self.filter_func = filter_func
def authenticate(self): """Connects to Github and Asana and authenticates via OAuth.""" if self.oauth: return False # Save asana. self.settings.apply('api-asana', self.args.asana_api, "enter asana api key") # Save github.com self.settings.apply('api-github', self.args.github_api, "enter github.com token") logging.debug("authenticating asana api.") self.asana = Client.basic_auth(self.settings['api-asana']) self.asana_errors = asana_errors self.asana_me = self.asana.users.me() logging.debug("authenticating github api") self.github = Github(self.settings['api-github']) self.github_user = self.github.get_user() self.oauth = True
def init(access_token: str): """ Use this helper to get specific values from Asana API and choose the tasks you need. Before launch you should make or get access_token — https://asana.com/guide/help/api/api """ client = Client.access_token(access_token) click.echo('Starting validation of access_token...') with click_spinner.spinner(): try: user = client.users.me() except NoAuthorizationError: click.secho( 'Token is invalid. Please check your token and read the ' + 'official documentation: https://asana.com/guide/help/api/api', fg='red') return click.echo('Hello, {0}'.format(user['name'])) click.echo('Fetching workspaces...') with click_spinner.spinner(): workspaces = list(client.workspaces.find_all()) click.echo('Please choose workspace') for i, w in enumerate(workspaces, 1): click.echo('{index}: {name} ({gid})'.format( index=i, name=w['name'], gid=w['gid'], )) workspace_index = click.prompt('Your choice', type=int) - 1 workspace = workspaces[workspace_index] click.echo('Selected workspace {name} ({gid})'.format( name=workspace['name'], gid=workspace['gid'])) filter_type = click.prompt( 'You can use only one type of fetching tasks:\n' + '1. Show in status bar last task filtered by tag\n' + '2. Show in status bar last task filtered by project\n' + '3. Show in status bar last task filtered by column of board (so-called section)\n' 'Your choice', type=int) if filter_type == 1: click.echo('Fetching tags...') with click_spinner.spinner(): tags = list(client.tags.find_all(workspace=workspace['gid'])) click.echo('Please choose tag') for i, t in enumerate(tags, 1): click.echo('{index}: {name} ({gid})'.format( index=i, name=t['name'], gid=t['gid'], )) tag_index = click.prompt('Your choice', type=int) - 1 tag = tags[tag_index] click.secho('Use run command with "--tag-id {0}"'.format(tag['gid']), fg='green') return click.echo('Fetching projects...') with click_spinner.spinner(): projects = list(client.projects.find_all(workspace=workspace['gid'])) click.echo('Please choose project') for i, p in enumerate(projects, 1): click.echo('{index}: {name} ({gid})'.format( index=i, name=p['name'], gid=p['gid'], )) project_index = click.prompt('Your choice', type=int) - 1 project = projects[project_index] if filter_type == 2: click.secho('Use run command with "--project-id {0}"'.format( project['gid']), fg='green') return if filter_type == 3: click.echo('Fetching sections...') with click_spinner.spinner(): sections = list( client.sections.find_by_project(project=project['gid'])) click.echo('Please choose column of board (section)') for i, s in enumerate(sections, 1): click.echo('{index}: {name} ({gid})'.format( index=i, name=s['name'], gid=s['gid'], )) section_index = click.prompt('Your choice', type=int) - 1 section = sections[section_index] click.secho('Use run command with "--section-id {0}"'.format( section['gid']), fg='green') return
# Workflow settings BACKLOG_TAG_ID = <FILL ME IN> BAG_OF_TASKS_TAG_ID = <FILL ME IN> MAIN_PRJ_ID = <FILL ME IN> MAIN_PRJ = {'id': MAIN_PRJ_ID, 'name': 'Main'} ASANA_TIMEOUT = 60 # If `entrypoint` is not defined in app.yaml, App Engine will look for an app # called `app` in `main.py`. app = Flask(__name__) app.config['JWT_SECRET_KEY'] = JWT_SECRET_KEY jwt = JWTManager(app) asana_client = Client.access_token(ASANA_API_KEY) @app.route('/api/login', methods=['POST']) def login(): if not request.is_json: return jsonify({"msg": "Missing JSON in request"}), 400 params = request.get_json() username = params.get('username', None) password = params.get('password', None) if not username: return jsonify({"msg": "Missing username parameter"}), 400 if not password: return jsonify({"msg": "Missing password parameter"}), 400
def __init__(self, settings): self.settings = settings self.asana = Client.basic_auth(self.settings['api-asana']) self.asana_me = self.asana.users.me() self.github = Github(self.settings['api-github']) self.github_user = self.github.get_user()
from github import Github from asana import Client import getpass githubUsername = raw_input("Enter Your Github Username: "******"Enter Your Github Password: "******"Enter Your Full Github Repository Name (owner/repoName): ") asanaAPIKey = getpass.getpass("Enter Your Asana API Key: ") asanaWorkplaceId = raw_input("Enter Your Asana Workplace ID: ") asanaProjectId = raw_input("Enter Your Asana Project ID: ") asanaClient = Client.basic_auth(asanaAPIKey) github = Github(githubUsername, githubPassword) repo = github.get_repo(githubRepoName) labels = repo.get_labels() tagMapping = {} for label in labels: print(label.name) tagId = asanaClient.tags.create( name = label.name, workspace = asanaWorkplaceId )["id"] tagMapping[label.name] = tagId issues = repo.get_issues() for issue in issues: print(issue.title) taskId = asanaClient.tasks.create(
def request(self, method, path, **options): if self._dump_api: print("{}: {}".format(method, path)) self._num_requests += 1 return Client.request(self, method, path, **options)
def __init__(self, dump_api=False, session=None, auth=None, **options): Client.__init__(self, session=session, auth=auth, **options) self._dump_api = dump_api self._num_requests = 0
def asana_client(): a_client = Client.access_token(settings.ASANA_PAT) return a_client