├── .coveragerc ├── .docgen ├── .flake8 ├── .github └── workflows │ └── build.yml ├── .gitignore ├── .tests ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── MANIFEST.in ├── README.md ├── example └── myapp.py ├── noxfile.py ├── setup.py ├── tests ├── __init__.py ├── routers │ ├── __init__.py │ ├── activities │ │ ├── __init__.py │ │ ├── test_activities_engagement.py │ │ └── test_activities_team.py │ ├── freelancers │ │ ├── test_freelancers_profile.py │ │ └── test_freelancers_search.py │ ├── hr │ │ ├── clients │ │ │ ├── test_hr_clients_applications.py │ │ │ └── test_hr_clients_offers.py │ │ ├── freelancers │ │ │ ├── test_hr_freelancers_applications.py │ │ │ └── test_hr_freelancers_offers.py │ │ ├── test_hr_contracts.py │ │ ├── test_hr_engagements.py │ │ ├── test_hr_interviews.py │ │ ├── test_hr_jobs.py │ │ ├── test_hr_milestones.py │ │ ├── test_hr_roles.py │ │ └── test_hr_submissions.py │ ├── jobs │ │ ├── test_jobs_profile.py │ │ └── test_jobs_search.py │ ├── organization │ │ ├── test_organization_companies.py │ │ ├── test_organization_teams.py │ │ └── test_organization_users.py │ ├── reports │ │ ├── finance │ │ │ ├── test_reports_finance_accounts.py │ │ │ ├── test_reports_finance_billings.py │ │ │ └── test_reports_finance_earnings.py │ │ └── test_reports_time.py │ ├── test_auth.py │ ├── test_messages.py │ ├── test_metadata.py │ ├── test_payments.py │ ├── test_snapshots.py │ ├── test_workdays.py │ └── test_workiary.py ├── test_client.py ├── test_config.py └── test_upwork.py └── upwork ├── __init__.py ├── client.py ├── config.py ├── routers ├── __init__.py ├── activities │ ├── __init__.py │ ├── engagement.py │ └── team.py ├── auth.py ├── freelancers │ ├── __init__.py │ ├── profile.py │ └── search.py ├── hr │ ├── __init__.py │ ├── clients │ │ ├── __init__.py │ │ ├── applications.py │ │ └── offers.py │ ├── contracts.py │ ├── engagements.py │ ├── freelancers │ │ ├── __init__.py │ │ ├── applications.py │ │ └── offers.py │ ├── interviews.py │ ├── jobs.py │ ├── milestones.py │ ├── roles.py │ └── submissions.py ├── jobs │ ├── __init__.py │ ├── profile.py │ └── search.py ├── messages.py ├── metadata.py ├── organization │ ├── __init__.py │ ├── companies.py │ ├── teams.py │ └── users.py ├── payments.py ├── reports │ ├── __init__.py │ ├── finance │ │ ├── __init__.py │ │ ├── accounts.py │ │ ├── billings.py │ │ └── earnings.py │ └── time.py ├── snapshots.py ├── workdays.py └── workdiary.py └── upwork.py /.coveragerc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/upwork/python-upwork/a8d8c1a349d4331b07d57e60c95cb929e37a68fc/.coveragerc -------------------------------------------------------------------------------- /.docgen: -------------------------------------------------------------------------------- 1 | pipenv shell && pdoc3 --html upwork 2 | -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 88 3 | ignore = E501, E203, W503, E231, B017 4 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | paths-ignore: 6 | - '**.md' 7 | pull_request: 8 | paths-ignore: 9 | - '**.md' 10 | 11 | jobs: 12 | test: 13 | 14 | runs-on: ${{ matrix.os }} 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | os: [ubuntu-latest, macos-latest] 19 | python: [ '3.9' ] 20 | 21 | name: Python ${{ matrix.python }} 22 | steps: 23 | - uses: actions/checkout@v2 24 | - name: Setup python 25 | uses: actions/setup-python@v2 26 | with: 27 | python-version: ${{ matrix.python }} 28 | # step 1: install dependencies 29 | - run: pip install nox 30 | - run: pip install types-requests 31 | # step 2: run test 32 | - run: nox --non-interactive --session "tests-${{ matrix.python }}" 33 | #- run: nox --non-interactive --session "lint" 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # pipenv 7 | Pipfile* 8 | 9 | # C extensions 10 | *.so 11 | 12 | # nox 13 | .nox/ 14 | 15 | # Distribution / packaging 16 | .Python 17 | env/ 18 | build/ 19 | develop-eggs/ 20 | dist/ 21 | downloads/ 22 | eggs/ 23 | .eggs/ 24 | lib/ 25 | lib64/ 26 | parts/ 27 | sdist/ 28 | var/ 29 | wheels/ 30 | *.egg-info/ 31 | .installed.cfg 32 | *.egg 33 | 34 | # PyInstaller 35 | # Usually these files are written by a python script from a template 36 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 37 | *.manifest 38 | *.spec 39 | 40 | # Installer logs 41 | pip-log.txt 42 | pip-delete-this-directory.txt 43 | 44 | # Unit test / coverage reports 45 | htmlcov/ 46 | .tox/ 47 | .coverage 48 | .coverage.* 49 | .cache 50 | nosetests.xml 51 | coverage.xml 52 | *.cover 53 | .hypothesis/ 54 | .pytest_cache/ 55 | 56 | # Translations 57 | *.mo 58 | *.pot 59 | 60 | # Django stuff: 61 | *.log 62 | local_settings.py 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # pyenv 81 | .python-version 82 | 83 | # celery beat schedule file 84 | celerybeat-schedule 85 | 86 | # SageMath parsed files 87 | *.sage.py 88 | 89 | # dotenv 90 | .env 91 | 92 | # virtualenv 93 | .venv 94 | venv/ 95 | ENV/ 96 | 97 | # Spyder project settings 98 | .spyderproject 99 | .spyproject 100 | 101 | # Rope project settings 102 | .ropeproject 103 | 104 | # mkdocs documentation 105 | /site 106 | 107 | # pdoc3 documentation 108 | html/ 109 | 110 | # mypy 111 | .mypy_cache/ 112 | 113 | # IDE settings 114 | .vscode/ 115 | -------------------------------------------------------------------------------- /.tests: -------------------------------------------------------------------------------- 1 | nox 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Release History 2 | 3 | ## 2.0.0 4 | * Release of Python 3 compatible library 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Install project automation tool [`nox`](https://nox.thea.codes/en/stable/): 2 | 3 | ``` 4 | python -m pip install --user nox 5 | ``` 6 | 7 | ### Unit Tests 8 | 9 | ``` 10 | nox -s tests 11 | ``` 12 | 13 | ### Lint 14 | 15 | ``` 16 | nox -s lint 17 | ``` 18 | 19 | ### Publish to PyPI 20 | 21 | ``` 22 | nox -s publish 23 | ``` -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include * 2 | include *.md LICENSE 3 | 4 | recursive-include example * 5 | 6 | exclude .flake8 noxfile.py .coverage .coveragerc .gitignore .travis.yml .tests .docgen Pipfile* 7 | prune example 8 | prune tests 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Python bindings for Upwork API (OAuth1) - DEPRECATED 2 | ============ 3 | 4 | [![License](https://img.shields.io/github/license/upwork/python-upwork)](http://www.apache.org/licenses/LICENSE-2.0.html) 5 | [![PyPI Version](https://badge.fury.io/py/python-upwork.svg)](http://badge.fury.io/py/python-upwork) 6 | [![GitHub release](https://img.shields.io/github/release/upwork/python-upwork.svg)](https://github.com/upwork/python-upwork/releases) 7 | [![Build Status](https://github.com/upwork/python-upwork/workflows/build/badge.svg)](https://github.com/upwork/python-upwork/actions) 8 | 9 | # Upwork API 10 | 11 | This project provides a set of resources of Upwork API from http://developers.upwork.com 12 | based on OAuth 1.0a. 13 | 14 | # Features 15 | These are the supported API resources: 16 | 17 | * My Info 18 | * Custom Payments 19 | * Hiring 20 | * Job and Freelancer Profile 21 | * Search Jobs and Freelancers 22 | * Organization 23 | * Messages 24 | * Time and Financial Reporting 25 | * Metadata 26 | * Snapshot 27 | * Team 28 | * Workd Diary 29 | * Activities 30 | 31 | # License 32 | 33 | Copyright 2020 Upwork Corporation. All Rights Reserved. 34 | 35 | python-upwork is licensed under the Apache License, Version 2.0 (the "License"); 36 | you may not use this file except in compliance with the License. 37 | You may obtain a copy of the License at 38 | 39 | http://www.apache.org/licenses/LICENSE-2.0 40 | 41 | Unless required by applicable law or agreed to in writing, software 42 | distributed under the License is distributed on an "AS IS" BASIS, 43 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 44 | See the License for the specific language governing permissions and 45 | limitations under the License. 46 | 47 | ## SLA 48 | The usage of this API is ruled by the Terms of Use at: 49 | 50 | https://developers.upwork.com/api-tos.html 51 | 52 | # Requirements 53 | To integrate this library you need to have: 54 | 55 | * Python 3.8+ 56 | * requests_oauthlib >= 1.3.0 57 | 58 | ## Installation 59 | 60 | pip3 install python-upwork 61 | 62 | All the dependencies will be automatically installed as well. 63 | 64 | ## Usage 65 | 66 | 1. 67 | Follow instructions from the `Installation` section. 68 | 69 | 2. 70 | Run `myapp.py` and follow the instructions, or open `myapp.py` and type the `consumer_key` and `consumer_secret` that you previously got from the API Center. 71 | ***That's all. Run your app as `python myapp.py` and have fun.***' 72 | -------------------------------------------------------------------------------- /example/myapp.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from pprint import pprint 3 | from upwork.routers import auth 4 | #from upwork.routers.jobs import search 5 | #from upwork.routers.activities import team 6 | #from upwork.routers.reports import time 7 | #from urllib.parse import quote 8 | 9 | def get_desktop_client(): 10 | """Emulation of a desktop application. 11 | Your key should be created with the project type "Desktop". 12 | 13 | Returns: ``upwork.Client`` instance ready to work. 14 | 15 | """ 16 | print("Emulating desktop app") 17 | 18 | consumer_key = input('Please enter consumer key: > ') 19 | consumer_secret = input('Please enter key secret: > ') 20 | config = upwork.Config({'consumer_key': consumer_key, 'consumer_secret': consumer_secret}) 21 | """Assign access_token and access_token_secret if they are known 22 | config = upwork.Config({\ 23 | 'consumer_key': 'xxxxxxxxxxx',\ 24 | 'consumer_secret': 'xxxxxxxxxxx',\ 25 | 'access_token': 'xxxxxxxxxxx',\ 26 | 'access_token_secret': 'xxxxxxxxxxx'}) 27 | """ 28 | 29 | client = upwork.Client(config) 30 | 31 | try: 32 | config.access_token 33 | config.access_token_secret 34 | except AttributeError: 35 | verifier = input( 36 | 'Please enter the verification code you get ' 37 | 'following this link:\n{0}\n\n> '.format( 38 | client.get_authorization_url())) 39 | 40 | print('Retrieving keys.... ') 41 | access_token, access_token_secret = client.get_access_token(verifier) 42 | print('OK') 43 | 44 | # For further use you can store ``access_toket`` and 45 | # ``access_token_secret`` somewhere 46 | 47 | return client 48 | 49 | if __name__ == '__main__': 50 | client = get_desktop_client() 51 | 52 | try: 53 | print("My info") 54 | pprint(auth.Api(client).get_user_info()) 55 | #pprint(search.Api(client).find({'q': 'php'})) 56 | #pprint(team.Api(client).add_activity('mycompany', 'mycompany', {'code': 'team-task-001', 'description': 'Description', 'all_in_company': '1'})) 57 | #pprint(time.Gds(client).get_by_freelancer_full('username', {'tq': quote('SELECT task, memo WHERE worked_on >= "2020-05-01" AND worked_on <= "2020-06-01"')})) 58 | except Exception as e: 59 | print("Catch or log exception details") 60 | raise e 61 | -------------------------------------------------------------------------------- /noxfile.py: -------------------------------------------------------------------------------- 1 | import nox # type: ignore 2 | from pathlib import Path 3 | 4 | nox.options.sessions = ["tests", "lint", "build"] 5 | 6 | python = ["3.9"] 7 | 8 | 9 | lint_dependencies = [ 10 | "-e", 11 | ".", 12 | "black", 13 | "flake8", 14 | "flake8-bugbear", 15 | "mypy", 16 | "check-manifest", 17 | ] 18 | 19 | 20 | @nox.session(python=python) 21 | def tests(session): 22 | session.install("-e", ".", "pytest", "pytest-cov") 23 | tests = session.posargs or ["tests"] 24 | session.run( 25 | "pytest", "--cov=upwork", "--cov-config", ".coveragerc", "--cov-report=", *tests 26 | ) 27 | session.notify("cover") 28 | 29 | 30 | @nox.session 31 | def cover(session): 32 | """Coverage analysis""" 33 | session.install("coverage") 34 | session.run("coverage", "report", "--show-missing", "--fail-under=0") 35 | session.run("coverage", "erase") 36 | 37 | 38 | @nox.session(python="3.9") 39 | def lint(session): 40 | session.install(*lint_dependencies) 41 | files = ["tests"] + [str(p) for p in Path(".").glob("*.py")] 42 | session.run("black", "--check", *files) 43 | session.run("flake8", *files) 44 | session.run("mypy", *files) 45 | session.run("python", "setup.py", "check", "--metadata", "--strict") 46 | if "--skip_manifest_check" in session.posargs: 47 | pass 48 | else: 49 | session.run("check-manifest") 50 | 51 | 52 | @nox.session(python="3.9") 53 | def build(session): 54 | session.install("setuptools") 55 | session.install("wheel") 56 | session.install("twine") 57 | session.install("types-requests") 58 | session.run("rm", "-rf", "dist", "build", external=True) 59 | session.run("python", "setup.py", "--quiet", "sdist", "bdist_wheel") 60 | 61 | 62 | @nox.session(python="3.9") 63 | def publish(session): 64 | build(session) 65 | print("REMINDER: Has the changelog been updated?") 66 | session.run("python", "-m", "twine", "upload", "dist/*") 67 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from setuptools import setup, find_packages # type: ignore 4 | 5 | with open("README.md") as readme_file: 6 | readme = readme_file.read() 7 | 8 | setup( 9 | author="Maksym Novozhylov", 10 | author_email="mnovozhilov@upwork.com", 11 | python_requires=">=3.8", 12 | classifiers=[ 13 | "Development Status :: 5 - Production/Stable", 14 | "Environment :: Web Environment", 15 | "Intended Audience :: Developers", 16 | "License :: OSI Approved :: Apache Software License", 17 | "Natural Language :: English", 18 | "Operating System :: OS Independent", 19 | "Programming Language :: Python :: 3", 20 | "Topic :: Software Development :: Libraries :: Python Modules", 21 | "Topic :: Utilities", 22 | ], 23 | description="Python bindings for Upwork API", 24 | install_requires=["requests_oauthlib>=1.3.0"], 25 | license="Apache Software License 2.0", 26 | long_description=readme, 27 | long_description_content_type="text/markdown", 28 | include_package_data=True, 29 | keywords="python-upwork", 30 | name="python-upwork", 31 | packages=find_packages(), 32 | setup_requires=[], 33 | url="https://github.com/upwork/python-upwork", 34 | version="2.1.0", 35 | zip_safe=False, 36 | ) 37 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | """Unit test package for upwork.""" 2 | -------------------------------------------------------------------------------- /tests/routers/__init__.py: -------------------------------------------------------------------------------- 1 | """Unit test package for upwork routers.""" 2 | -------------------------------------------------------------------------------- /tests/routers/activities/__init__.py: -------------------------------------------------------------------------------- 1 | """Unit test package for upwork routers.""" 2 | -------------------------------------------------------------------------------- /tests/routers/activities/test_activities_engagement.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.activities import engagement 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_specific(mocked_method): 8 | engagement.Api(upwork.Client).get_specific("1234") 9 | mocked_method.assert_called_with("/tasks/v2/tasks/contracts/1234") 10 | 11 | 12 | @patch.object(upwork.Client, "put") 13 | def test_assign(mocked_method): 14 | engagement.Api(upwork.Client).assign("company", "team", "1234", {"a": "b"}) 15 | mocked_method.assert_called_with( 16 | "/otask/v1/tasks/companies/company/teams/team/engagements/1234/tasks", 17 | {"a": "b"}, 18 | ) 19 | 20 | 21 | @patch.object(upwork.Client, "put") 22 | def test_assign_to_engagement(mocked_method): 23 | engagement.Api(upwork.Client).assign_to_engagement("1234", {"a": "b"}) 24 | mocked_method.assert_called_with("/tasks/v2/tasks/contracts/1234", {"a": "b"}) 25 | -------------------------------------------------------------------------------- /tests/routers/activities/test_activities_team.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.activities import team 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_list(mocked_method): 8 | team.Api(upwork.Client).get_list("company", "team") 9 | mocked_method.assert_called_with( 10 | "/otask/v1/tasks/companies/company/teams/team/tasks" 11 | ) 12 | 13 | 14 | @patch.object(upwork.Client, "get") 15 | def test_get_specific_list(mocked_method): 16 | team.Api(upwork.Client).get_specific_list("company", "team", "code") 17 | mocked_method.assert_called_with( 18 | "/otask/v1/tasks/companies/company/teams/team/tasks/code" 19 | ) 20 | 21 | 22 | @patch.object(upwork.Client, "post") 23 | def test_add_activity(mocked_method): 24 | team.Api(upwork.Client).add_activity("company", "team", {"a": "b"}) 25 | mocked_method.assert_called_with( 26 | "/otask/v1/tasks/companies/company/teams/team/tasks", {"a": "b"} 27 | ) 28 | 29 | 30 | @patch.object(upwork.Client, "put") 31 | def test_update_activities(mocked_method): 32 | team.Api(upwork.Client).update_activities("company", "team", "code", {"a": "b"}) 33 | mocked_method.assert_called_with( 34 | "/otask/v1/tasks/companies/company/teams/team/tasks/code", {"a": "b"} 35 | ) 36 | 37 | 38 | @patch.object(upwork.Client, "put") 39 | def test_archive_activities(mocked_method): 40 | team.Api(upwork.Client).archive_activities("company", "team", "code") 41 | mocked_method.assert_called_with( 42 | "/otask/v1/tasks/companies/company/teams/team/archive/code" 43 | ) 44 | 45 | 46 | @patch.object(upwork.Client, "put") 47 | def test_unarchive_activities(mocked_method): 48 | team.Api(upwork.Client).unarchive_activities("company", "team", "code") 49 | mocked_method.assert_called_with( 50 | "/otask/v1/tasks/companies/company/teams/team/unarchive/code" 51 | ) 52 | 53 | 54 | @patch.object(upwork.Client, "put") 55 | def test_update_batch(mocked_method): 56 | team.Api(upwork.Client).update_batch("company", {"a": "b"}) 57 | mocked_method.assert_called_with( 58 | "/otask/v1/tasks/companies/company/tasks/batch", {"a": "b"} 59 | ) 60 | -------------------------------------------------------------------------------- /tests/routers/freelancers/test_freelancers_profile.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.freelancers import profile 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_specific(mocked_method): 8 | profile.Api(upwork.Client).get_specific("key") 9 | mocked_method.assert_called_with("/profiles/v1/providers/key") 10 | 11 | 12 | @patch.object(upwork.Client, "get") 13 | def test_get_specific_brief(mocked_method): 14 | profile.Api(upwork.Client).get_specific_brief("key") 15 | mocked_method.assert_called_with("/profiles/v1/providers/key/brief") 16 | -------------------------------------------------------------------------------- /tests/routers/freelancers/test_freelancers_search.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.freelancers import search 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_find(mocked_method): 8 | search.Api(upwork.Client).find({"a": "b"}) 9 | mocked_method.assert_called_with("/profiles/v2/search/providers", {"a": "b"}) 10 | -------------------------------------------------------------------------------- /tests/routers/hr/clients/test_hr_clients_applications.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.hr.clients import applications 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_list(mocked_method): 8 | applications.Api(upwork.Client).get_list({"a": "b"}) 9 | mocked_method.assert_called_with("/hr/v4/clients/applications", {"a": "b"}) 10 | 11 | 12 | @patch.object(upwork.Client, "get") 13 | def test_get_specific(mocked_method): 14 | applications.Api(upwork.Client).get_specific("reference", {"a": "b"}) 15 | mocked_method.assert_called_with( 16 | "/hr/v4/clients/applications/reference", {"a": "b"} 17 | ) 18 | -------------------------------------------------------------------------------- /tests/routers/hr/clients/test_hr_clients_offers.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.hr.clients import offers 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_list(mocked_method): 8 | offers.Api(upwork.Client).get_list({"a": "b"}) 9 | mocked_method.assert_called_with("/offers/v1/clients/offers", {"a": "b"}) 10 | 11 | 12 | @patch.object(upwork.Client, "get") 13 | def test_get_specific(mocked_method): 14 | offers.Api(upwork.Client).get_specific("reference", {"a": "b"}) 15 | mocked_method.assert_called_with("/offers/v1/clients/offers/reference", {"a": "b"}) 16 | 17 | 18 | @patch.object(upwork.Client, "post") 19 | def test_make_offer(mocked_method): 20 | offers.Api(upwork.Client).make_offer({"a": "b"}) 21 | mocked_method.assert_called_with("/offers/v1/clients/offers", {"a": "b"}) 22 | -------------------------------------------------------------------------------- /tests/routers/hr/freelancers/test_hr_freelancers_applications.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.hr.freelancers import applications 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_list(mocked_method): 8 | applications.Api(upwork.Client).get_list({}) 9 | mocked_method.assert_called_with("/hr/v4/contractors/applications", {}) 10 | 11 | 12 | @patch.object(upwork.Client, "get") 13 | def test_get_specific(mocked_method): 14 | applications.Api(upwork.Client).get_specific("reference") 15 | mocked_method.assert_called_with("/hr/v4/contractors/applications/reference") 16 | -------------------------------------------------------------------------------- /tests/routers/hr/freelancers/test_hr_freelancers_offers.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.hr.freelancers import offers 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_list(mocked_method): 8 | offers.Api(upwork.Client).get_list({}) 9 | mocked_method.assert_called_with("/offers/v1/contractors/offers", {}) 10 | 11 | 12 | @patch.object(upwork.Client, "get") 13 | def test_get_specific(mocked_method): 14 | offers.Api(upwork.Client).get_specific("reference") 15 | mocked_method.assert_called_with("/offers/v1/contractors/offers/reference") 16 | 17 | 18 | @patch.object(upwork.Client, "post") 19 | def test_actions(mocked_method): 20 | offers.Api(upwork.Client).actions("reference", {"a": "b"}) 21 | mocked_method.assert_called_with( 22 | "/offers/v1/contractors/actions/reference", {"a": "b"} 23 | ) 24 | -------------------------------------------------------------------------------- /tests/routers/hr/test_hr_contracts.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.hr import contracts 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "put") 7 | def test_suspend_contract(mocked_method): 8 | contracts.Api(upwork.Client).suspend_contract("reference", {"a": "b"}) 9 | mocked_method.assert_called_with("/hr/v2/contracts/reference/suspend", {"a": "b"}) 10 | 11 | 12 | @patch.object(upwork.Client, "put") 13 | def test_restart_contract(mocked_method): 14 | contracts.Api(upwork.Client).restart_contract("reference", {"a": "b"}) 15 | mocked_method.assert_called_with("/hr/v2/contracts/reference/restart", {"a": "b"}) 16 | 17 | 18 | @patch.object(upwork.Client, "delete") 19 | def test_end_contract(mocked_method): 20 | contracts.Api(upwork.Client).end_contract("reference", {"a": "b"}) 21 | mocked_method.assert_called_with("/hr/v2/contracts/reference", {"a": "b"}) 22 | -------------------------------------------------------------------------------- /tests/routers/hr/test_hr_engagements.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.hr import engagements 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_list(mocked_method): 8 | engagements.Api(upwork.Client).get_list({"a": "b"}) 9 | mocked_method.assert_called_with("/hr/v2/engagements", {"a": "b"}) 10 | 11 | 12 | @patch.object(upwork.Client, "get") 13 | def test_get_specific(mocked_method): 14 | engagements.Api(upwork.Client).get_specific("reference") 15 | mocked_method.assert_called_with("/hr/v2/engagements/reference") 16 | -------------------------------------------------------------------------------- /tests/routers/hr/test_hr_interviews.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.hr import interviews 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "post") 7 | def test_invite(mocked_method): 8 | interviews.Api(upwork.Client).invite("key", {"a": "b"}) 9 | mocked_method.assert_called_with("/hr/v1/jobs/key/candidates", {"a": "b"}) 10 | -------------------------------------------------------------------------------- /tests/routers/hr/test_hr_jobs.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.hr import jobs 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_list(mocked_method): 8 | jobs.Api(upwork.Client).get_list({"a": "b"}) 9 | mocked_method.assert_called_with("/hr/v2/jobs", {"a": "b"}) 10 | 11 | 12 | @patch.object(upwork.Client, "get") 13 | def test_get_specific(mocked_method): 14 | jobs.Api(upwork.Client).get_specific("key") 15 | mocked_method.assert_called_with("/hr/v2/jobs/key") 16 | 17 | 18 | @patch.object(upwork.Client, "post") 19 | def test_post_job(mocked_method): 20 | jobs.Api(upwork.Client).post_job({"a": "b"}) 21 | mocked_method.assert_called_with("/hr/v2/jobs", {"a": "b"}) 22 | 23 | 24 | @patch.object(upwork.Client, "put") 25 | def test_edit_job(mocked_method): 26 | jobs.Api(upwork.Client).edit_job("key", {"a": "b"}) 27 | mocked_method.assert_called_with("/hr/v2/jobs/key", {"a": "b"}) 28 | 29 | 30 | @patch.object(upwork.Client, "delete") 31 | def test_delete_job(mocked_method): 32 | jobs.Api(upwork.Client).delete_job("key", {"a": "b"}) 33 | mocked_method.assert_called_with("/hr/v2/jobs/key", {"a": "b"}) 34 | -------------------------------------------------------------------------------- /tests/routers/hr/test_hr_milestones.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.hr import milestones 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_active_milestone(mocked_method): 8 | milestones.Api(upwork.Client).get_active_milestone("contract") 9 | mocked_method.assert_called_with( 10 | "/hr/v3/fp/milestones/statuses/active/contracts/contract" 11 | ) 12 | 13 | 14 | @patch.object(upwork.Client, "get") 15 | def test_get_submissions(mocked_method): 16 | milestones.Api(upwork.Client).get_submissions("milestone") 17 | mocked_method.assert_called_with("/hr/v3/fp/milestones/milestone/submissions") 18 | 19 | 20 | @patch.object(upwork.Client, "post") 21 | def test_create(mocked_method): 22 | milestones.Api(upwork.Client).create({"a": "b"}) 23 | mocked_method.assert_called_with("/hr/v3/fp/milestones", {"a": "b"}) 24 | 25 | 26 | @patch.object(upwork.Client, "put") 27 | def test_edit(mocked_method): 28 | milestones.Api(upwork.Client).edit("milestone", {"a": "b"}) 29 | mocked_method.assert_called_with("/hr/v3/fp/milestones/milestone", {"a": "b"}) 30 | 31 | 32 | @patch.object(upwork.Client, "put") 33 | def test_activate(mocked_method): 34 | milestones.Api(upwork.Client).activate("milestone", {"a": "b"}) 35 | mocked_method.assert_called_with( 36 | "/hr/v3/fp/milestones/milestone/activate", {"a": "b"} 37 | ) 38 | 39 | 40 | @patch.object(upwork.Client, "put") 41 | def test_approve(mocked_method): 42 | milestones.Api(upwork.Client).approve("milestone", {"a": "b"}) 43 | mocked_method.assert_called_with( 44 | "/hr/v3/fp/milestones/milestone/approve", {"a": "b"} 45 | ) 46 | 47 | 48 | @patch.object(upwork.Client, "delete") 49 | def test_delete(mocked_method): 50 | milestones.Api(upwork.Client).delete("milestone") 51 | mocked_method.assert_called_with("/hr/v3/fp/milestones/milestone") 52 | -------------------------------------------------------------------------------- /tests/routers/hr/test_hr_roles.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.hr import roles 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_all(mocked_method): 8 | roles.Api(upwork.Client).get_all() 9 | mocked_method.assert_called_with("/hr/v2/userroles") 10 | 11 | 12 | @patch.object(upwork.Client, "get") 13 | def test_get_by_specific_user(mocked_method): 14 | roles.Api(upwork.Client).get_by_specific_user("reference") 15 | mocked_method.assert_called_with("/hr/v2/userroles/reference") 16 | -------------------------------------------------------------------------------- /tests/routers/hr/test_hr_submissions.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.hr import submissions 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "post") 7 | def test_request_approval(mocked_method): 8 | submissions.Api(upwork.Client).request_approval({"a": "b"}) 9 | mocked_method.assert_called_with("/hr/v3/fp/submissions", {"a": "b"}) 10 | 11 | 12 | @patch.object(upwork.Client, "put") 13 | def test_approve(mocked_method): 14 | submissions.Api(upwork.Client).approve("submission", {"a": "b"}) 15 | mocked_method.assert_called_with( 16 | "/hr/v3/fp/submissions/submission/approve", {"a": "b"} 17 | ) 18 | 19 | 20 | @patch.object(upwork.Client, "put") 21 | def test_reject(mocked_method): 22 | submissions.Api(upwork.Client).reject("submission", {"a": "b"}) 23 | mocked_method.assert_called_with( 24 | "/hr/v3/fp/submissions/submission/reject", {"a": "b"} 25 | ) 26 | -------------------------------------------------------------------------------- /tests/routers/jobs/test_jobs_profile.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.jobs import profile 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_specific(mocked_method): 8 | profile.Api(upwork.Client).get_specific("key") 9 | mocked_method.assert_called_with("/profiles/v1/jobs/key") 10 | -------------------------------------------------------------------------------- /tests/routers/jobs/test_jobs_search.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.jobs import search 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_find(mocked_method): 8 | search.Api(upwork.Client).find({"a": "b"}) 9 | mocked_method.assert_called_with("/profiles/v2/search/jobs", {"a": "b"}) 10 | -------------------------------------------------------------------------------- /tests/routers/organization/test_organization_companies.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.organization import companies 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_list(mocked_method): 8 | companies.Api(upwork.Client).get_list() 9 | mocked_method.assert_called_with("/hr/v2/companies") 10 | 11 | 12 | @patch.object(upwork.Client, "get") 13 | def test_get_specific(mocked_method): 14 | companies.Api(upwork.Client).get_specific("reference") 15 | mocked_method.assert_called_with("/hr/v2/companies/reference") 16 | 17 | 18 | @patch.object(upwork.Client, "get") 19 | def test_get_teams(mocked_method): 20 | companies.Api(upwork.Client).get_teams("reference") 21 | mocked_method.assert_called_with("/hr/v2/companies/reference/teams") 22 | 23 | 24 | @patch.object(upwork.Client, "get") 25 | def test_users(mocked_method): 26 | companies.Api(upwork.Client).get_users("reference") 27 | mocked_method.assert_called_with("/hr/v2/companies/reference/users") 28 | -------------------------------------------------------------------------------- /tests/routers/organization/test_organization_teams.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.organization import teams 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_list(mocked_method): 8 | teams.Api(upwork.Client).get_list() 9 | mocked_method.assert_called_with("/hr/v2/teams") 10 | 11 | 12 | @patch.object(upwork.Client, "get") 13 | def test_get_users_in_team(mocked_method): 14 | teams.Api(upwork.Client).get_users_in_team("reference") 15 | mocked_method.assert_called_with("/hr/v2/teams/reference/users") 16 | -------------------------------------------------------------------------------- /tests/routers/organization/test_organization_users.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.organization import users 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_my_info(mocked_method): 8 | users.Api(upwork.Client).get_my_info() 9 | mocked_method.assert_called_with("/hr/v2/users/me") 10 | 11 | 12 | @patch.object(upwork.Client, "get") 13 | def test_get_specific(mocked_method): 14 | users.Api(upwork.Client).get_specific("reference") 15 | mocked_method.assert_called_with("/hr/v2/users/reference") 16 | -------------------------------------------------------------------------------- /tests/routers/reports/finance/test_reports_finance_accounts.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.reports.finance import accounts 3 | from unittest.mock import patch 4 | 5 | 6 | def test_entry_point(): 7 | assert accounts.Gds.entry_point == "gds" 8 | 9 | 10 | @patch.object(upwork.Client, "get") 11 | def test_get_owned(mocked_method): 12 | accounts.Gds(upwork.Client).get_owned("freelancer", {"a": "b"}) 13 | mocked_method.assert_called_with( 14 | "/finreports/v2/financial_account_owner/freelancer", {"a": "b"} 15 | ) 16 | 17 | 18 | @patch.object(upwork.Client, "get") 19 | def test_get_specific(mocked_method): 20 | accounts.Gds(upwork.Client).get_specific("entity", {"a": "b"}) 21 | mocked_method.assert_called_with( 22 | "/finreports/v2/financial_accounts/entity", {"a": "b"} 23 | ) 24 | -------------------------------------------------------------------------------- /tests/routers/reports/finance/test_reports_finance_billings.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.reports.finance import billings 3 | from unittest.mock import patch 4 | 5 | 6 | def test_entry_point(): 7 | assert billings.Gds.entry_point == "gds" 8 | 9 | 10 | @patch.object(upwork.Client, "get") 11 | def test_get_by_freelancer(mocked_method): 12 | billings.Gds(upwork.Client).get_by_freelancer("freelancer", {"a": "b"}) 13 | mocked_method.assert_called_with( 14 | "/finreports/v2/providers/freelancer/billings", {"a": "b"} 15 | ) 16 | 17 | 18 | @patch.object(upwork.Client, "get") 19 | def test_get_by_freelancers_team(mocked_method): 20 | billings.Gds(upwork.Client).get_by_freelancers_team("team", {"a": "b"}) 21 | mocked_method.assert_called_with( 22 | "/finreports/v2/provider_teams/team/billings", {"a": "b"} 23 | ) 24 | 25 | 26 | @patch.object(upwork.Client, "get") 27 | def test_get_by_freelancers_company(mocked_method): 28 | billings.Gds(upwork.Client).get_by_freelancers_company("company", {"a": "b"}) 29 | mocked_method.assert_called_with( 30 | "/finreports/v2/provider_companies/company/billings", {"a": "b"} 31 | ) 32 | 33 | 34 | @patch.object(upwork.Client, "get") 35 | def test_get_by_buyers_team(mocked_method): 36 | billings.Gds(upwork.Client).get_by_buyers_team("team", {"a": "b"}) 37 | mocked_method.assert_called_with( 38 | "/finreports/v2/buyer_teams/team/billings", {"a": "b"} 39 | ) 40 | 41 | 42 | @patch.object(upwork.Client, "get") 43 | def test_get_by_buyers_company(mocked_method): 44 | billings.Gds(upwork.Client).get_by_buyers_company("company", {"a": "b"}) 45 | mocked_method.assert_called_with( 46 | "/finreports/v2/buyer_companies/company/billings", {"a": "b"} 47 | ) 48 | -------------------------------------------------------------------------------- /tests/routers/reports/finance/test_reports_finance_earnings.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.reports.finance import earnings 3 | from unittest.mock import patch 4 | 5 | 6 | def test_entry_point(): 7 | assert earnings.Gds.entry_point == "gds" 8 | 9 | 10 | @patch.object(upwork.Client, "get") 11 | def test_get_by_freelancer(mocked_method): 12 | earnings.Gds(upwork.Client).get_by_freelancer("freelancer", {"a": "b"}) 13 | mocked_method.assert_called_with( 14 | "/finreports/v2/providers/freelancer/earnings", {"a": "b"} 15 | ) 16 | 17 | 18 | @patch.object(upwork.Client, "get") 19 | def test_get_by_freelancers_team(mocked_method): 20 | earnings.Gds(upwork.Client).get_by_freelancers_team("team", {"a": "b"}) 21 | mocked_method.assert_called_with( 22 | "/finreports/v2/provider_teams/team/earnings", {"a": "b"} 23 | ) 24 | 25 | 26 | @patch.object(upwork.Client, "get") 27 | def test_get_by_freelancers_company(mocked_method): 28 | earnings.Gds(upwork.Client).get_by_freelancers_company("company", {"a": "b"}) 29 | mocked_method.assert_called_with( 30 | "/finreports/v2/provider_companies/company/earnings", {"a": "b"} 31 | ) 32 | 33 | 34 | @patch.object(upwork.Client, "get") 35 | def test_get_by_buyers_team(mocked_method): 36 | earnings.Gds(upwork.Client).get_by_buyers_team("team", {"a": "b"}) 37 | mocked_method.assert_called_with( 38 | "/finreports/v2/buyer_teams/team/earnings", {"a": "b"} 39 | ) 40 | 41 | 42 | @patch.object(upwork.Client, "get") 43 | def test_get_by_buyers_company(mocked_method): 44 | earnings.Gds(upwork.Client).get_by_buyers_company("company", {"a": "b"}) 45 | mocked_method.assert_called_with( 46 | "/finreports/v2/buyer_companies/company/earnings", {"a": "b"} 47 | ) 48 | -------------------------------------------------------------------------------- /tests/routers/reports/test_reports_time.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers.reports import time 3 | from unittest.mock import patch 4 | 5 | 6 | def test_entry_point(): 7 | assert time.Gds.entry_point == "gds" 8 | 9 | 10 | @patch.object(upwork.Client, "get") 11 | def test_get_by_team_full(mocked_method): 12 | time.Gds(upwork.Client).get_by_team_full("company", "team", {"a": "b"}) 13 | mocked_method.assert_called_with( 14 | "/timereports/v1/companies/company/teams/team", {"a": "b"} 15 | ) 16 | 17 | 18 | @patch.object(upwork.Client, "get") 19 | def test_get_by_team_limited(mocked_method): 20 | time.Gds(upwork.Client).get_by_team_limited("company", "team", {"a": "b"}) 21 | mocked_method.assert_called_with( 22 | "/timereports/v1/companies/company/teams/team/hours", {"a": "b"} 23 | ) 24 | 25 | 26 | @patch.object(upwork.Client, "get") 27 | def test_get_by_agency(mocked_method): 28 | time.Gds(upwork.Client).get_by_agency("company", "agency", {"a": "b"}) 29 | mocked_method.assert_called_with( 30 | "/timereports/v1/companies/company/agencies/agency", {"a": "b"} 31 | ) 32 | 33 | 34 | @patch.object(upwork.Client, "get") 35 | def test_get_by_company(mocked_method): 36 | time.Gds(upwork.Client).get_by_company("company", {"a": "b"}) 37 | mocked_method.assert_called_with("/timereports/v1/companies/company", {"a": "b"}) 38 | 39 | 40 | @patch.object(upwork.Client, "get") 41 | def test_get_by_freelancer_limited(mocked_method): 42 | time.Gds(upwork.Client).get_by_freelancer_limited("freelancer", {"a": "b"}) 43 | mocked_method.assert_called_with( 44 | "/timereports/v1/providers/freelancer/hours", {"a": "b"} 45 | ) 46 | 47 | 48 | @patch.object(upwork.Client, "get") 49 | def test_get_by_freelancer_full(mocked_method): 50 | time.Gds(upwork.Client).get_by_freelancer_full("freelancer", {"a": "b"}) 51 | mocked_method.assert_called_with("/timereports/v1/providers/freelancer", {"a": "b"}) 52 | -------------------------------------------------------------------------------- /tests/routers/test_auth.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers import auth 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_user_info(mocked_method): 8 | auth.Api(upwork.Client).get_user_info() 9 | mocked_method.assert_called_with("/auth/v1/info") 10 | -------------------------------------------------------------------------------- /tests/routers/test_messages.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers import messages 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_rooms(mocked_method): 8 | messages.Api(upwork.Client).get_rooms("company") 9 | mocked_method.assert_called_with("/messages/v3/company/rooms", {}) 10 | 11 | 12 | @patch.object(upwork.Client, "get") 13 | def test_get_room_details(mocked_method): 14 | messages.Api(upwork.Client).get_room_details("company", "room_id") 15 | mocked_method.assert_called_with("/messages/v3/company/rooms/room_id", {}) 16 | 17 | 18 | @patch.object(upwork.Client, "get") 19 | def test_get_room_messages(mocked_method): 20 | messages.Api(upwork.Client).get_room_messages("company", "room_id") 21 | mocked_method.assert_called_with("/messages/v3/company/rooms/room_id/stories", {}) 22 | 23 | 24 | @patch.object(upwork.Client, "get") 25 | def test_get_room_by_offer(mocked_method): 26 | messages.Api(upwork.Client).get_room_by_offer("company", "offer_id") 27 | mocked_method.assert_called_with("/messages/v3/company/rooms/offers/offer_id", {}) 28 | 29 | 30 | @patch.object(upwork.Client, "get") 31 | def test_get_room_by_application(mocked_method): 32 | messages.Api(upwork.Client).get_room_by_application("company", "application_id") 33 | mocked_method.assert_called_with( 34 | "/messages/v3/company/rooms/applications/application_id", {} 35 | ) 36 | 37 | 38 | @patch.object(upwork.Client, "get") 39 | def test_get_room_by_contract(mocked_method): 40 | messages.Api(upwork.Client).get_room_by_contract("company", "contract_id") 41 | mocked_method.assert_called_with( 42 | "/messages/v3/company/rooms/contracts/contract_id", {} 43 | ) 44 | 45 | 46 | @patch.object(upwork.Client, "post") 47 | def test_create_room(mocked_method): 48 | messages.Api(upwork.Client).create_room("company") 49 | mocked_method.assert_called_with("/messages/v3/company/rooms", {}) 50 | 51 | 52 | @patch.object(upwork.Client, "post") 53 | def test_send_message_to_room(mocked_method): 54 | messages.Api(upwork.Client).send_message_to_room("company", "room_id") 55 | mocked_method.assert_called_with("/messages/v3/company/rooms/room_id/stories", {}) 56 | 57 | 58 | @patch.object(upwork.Client, "post") 59 | def test_send_message_to_rooms(mocked_method): 60 | messages.Api(upwork.Client).send_message_to_rooms("company") 61 | mocked_method.assert_called_with("/messages/v3/company/stories/batch", {}) 62 | 63 | 64 | @patch.object(upwork.Client, "put") 65 | def test_get_update_room_settings(mocked_method): 66 | messages.Api(upwork.Client).update_room_settings("company", "room_id", "username") 67 | mocked_method.assert_called_with( 68 | "/messages/v3/company/rooms/room_id/users/username", {} 69 | ) 70 | 71 | 72 | @patch.object(upwork.Client, "put") 73 | def test_get_update_room_metadata(mocked_method): 74 | messages.Api(upwork.Client).update_room_metadata("company", "room_id") 75 | mocked_method.assert_called_with("/messages/v3/company/rooms/room_id", {}) 76 | -------------------------------------------------------------------------------- /tests/routers/test_metadata.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers import metadata 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_categories_v2(mocked_method): 8 | metadata.Api(upwork.Client).get_categories_v2() 9 | mocked_method.assert_called_with("/profiles/v2/metadata/categories") 10 | 11 | 12 | @patch.object(upwork.Client, "get") 13 | def test_get_skills(mocked_method): 14 | metadata.Api(upwork.Client).get_skills() 15 | mocked_method.assert_called_with("/profiles/v1/metadata/skills") 16 | 17 | 18 | @patch.object(upwork.Client, "get") 19 | def test_get_skills_v2(mocked_method): 20 | metadata.Api(upwork.Client).get_skills_v2({"a": "b"}) 21 | mocked_method.assert_called_with("/profiles/v2/metadata/skills", {"a": "b"}) 22 | 23 | 24 | @patch.object(upwork.Client, "get") 25 | def test_get_specialties(mocked_method): 26 | metadata.Api(upwork.Client).get_specialties() 27 | mocked_method.assert_called_with("/profiles/v1/metadata/specialties") 28 | 29 | 30 | @patch.object(upwork.Client, "get") 31 | def test_get_regions(mocked_method): 32 | metadata.Api(upwork.Client).get_regions() 33 | mocked_method.assert_called_with("/profiles/v1/metadata/regions") 34 | 35 | 36 | @patch.object(upwork.Client, "get") 37 | def test_get_tests(mocked_method): 38 | metadata.Api(upwork.Client).get_tests() 39 | mocked_method.assert_called_with("/profiles/v1/metadata/tests") 40 | 41 | 42 | @patch.object(upwork.Client, "get") 43 | def test_get_reasons(mocked_method): 44 | metadata.Api(upwork.Client).get_reasons({"a": "b"}) 45 | mocked_method.assert_called_with("/profiles/v1/metadata/reasons", {"a": "b"}) 46 | -------------------------------------------------------------------------------- /tests/routers/test_payments.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers import payments 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "post") 7 | def test_submit_bonus(mocked_method): 8 | payments.Api(upwork.Client).submit_bonus(1234, {"a": "b"}) 9 | mocked_method.assert_called_with("/hr/v2/teams/1234/adjustments", {"a": "b"}) 10 | -------------------------------------------------------------------------------- /tests/routers/test_snapshots.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers import snapshots 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_by_contract(mocked_method): 8 | snapshots.Api(upwork.Client).get_by_contract("1234", "1234") 9 | mocked_method.assert_called_with("/team/v3/snapshots/contracts/1234/1234") 10 | 11 | 12 | @patch.object(upwork.Client, "put") 13 | def test_update_by_contract(mocked_method): 14 | snapshots.Api(upwork.Client).update_by_contract("1234", "1234", {"a": "b"}) 15 | mocked_method.assert_called_with( 16 | "/team/v3/snapshots/contracts/1234/1234", {"a": "b"} 17 | ) 18 | 19 | 20 | @patch.object(upwork.Client, "delete") 21 | def test_delete_by_contract(mocked_method): 22 | snapshots.Api(upwork.Client).delete_by_contract("1234", "1234") 23 | mocked_method.assert_called_with("/team/v3/snapshots/contracts/1234/1234") 24 | -------------------------------------------------------------------------------- /tests/routers/test_workdays.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers import workdays 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_by_company(mocked_method): 8 | workdays.Api(upwork.Client).get_by_company("company", "from", "till", {}) 9 | mocked_method.assert_called_with( 10 | "/team/v3/workdays/companies/company/from,till", {} 11 | ) 12 | 13 | 14 | @patch.object(upwork.Client, "get") 15 | def test_get_by_contract(mocked_method): 16 | workdays.Api(upwork.Client).get_by_contract("company", "from", "till", {}) 17 | mocked_method.assert_called_with( 18 | "/team/v3/workdays/contracts/company/from,till", {} 19 | ) 20 | -------------------------------------------------------------------------------- /tests/routers/test_workiary.py: -------------------------------------------------------------------------------- 1 | import upwork 2 | from upwork.routers import workdiary 3 | from unittest.mock import patch 4 | 5 | 6 | @patch.object(upwork.Client, "get") 7 | def test_get_workdiary(mocked_method): 8 | workdiary.Api(upwork.Client).get_workdiary("company", "date", {}) 9 | mocked_method.assert_called_with("/team/v3/workdiaries/companies/company/date", {}) 10 | 11 | 12 | @patch.object(upwork.Client, "get") 13 | def test_get_by_contract(mocked_method): 14 | workdiary.Api(upwork.Client).get_by_contract("company", "date", {}) 15 | mocked_method.assert_called_with("/team/v3/workdiaries/contracts/company/date", {}) 16 | -------------------------------------------------------------------------------- /tests/test_client.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import unittest 3 | from upwork import config 4 | from upwork import client 5 | from unittest.mock import patch, Mock 6 | 7 | 8 | class TestClient(unittest.TestCase): 9 | @patch.object( 10 | requests, 11 | "post", 12 | return_value=Mock( 13 | status_code=200, content=b"oauth_token=token&oauth_token_secret=secret" 14 | ), 15 | ) 16 | def test_get_request_token(self, mocked_post): 17 | cfg = config.Config( 18 | { 19 | "consumer_key": "keyxxxxxxxxxxxxxxxxxxxx", 20 | "consumer_secret": "secretxxxxxxxxxx", 21 | } 22 | ) 23 | cl = client.Client(cfg) 24 | cl.get_request_token() 25 | 26 | assert cl.request_token == "token" 27 | assert cl.request_token_secret == "secret" 28 | 29 | @patch.object(requests, "post", side_effect=Exception("error")) 30 | def test_get_request_token_failed_post(self, mocked_post): 31 | cfg = config.Config( 32 | { 33 | "consumer_key": "keyxxxxxxxxxxxxxxxxxxxx", 34 | "consumer_secret": "secretxxxxxxxxxx", 35 | } 36 | ) 37 | cl = client.Client(cfg) 38 | with self.assertRaises(Exception): 39 | cl.get_request_token() 40 | 41 | @patch.object( 42 | requests, 43 | "post", 44 | return_value=Mock( 45 | status_code=200, content=b"oauth_token=token&oauth_token_secret=secret" 46 | ), 47 | ) 48 | def test_get_access_token(self, mocked_post): 49 | cfg = config.Config( 50 | { 51 | "consumer_key": "keyxxxxxxxxxxxxxxxxxxxx", 52 | "consumer_secret": "secretxxxxxxxxxx", 53 | } 54 | ) 55 | cl = client.Client(cfg) 56 | cl.request_token = "request_token" 57 | cl.request_token_secret = "request_secret" 58 | cl.get_access_token("verifier") 59 | 60 | assert cl.config.access_token == "token" 61 | assert cl.config.access_token_secret == "secret" 62 | 63 | def test_get_access_token_not_ready(self): 64 | cl = client.Client(object) 65 | 66 | with self.assertRaises(Exception): 67 | cl.get_access_token("verifier") 68 | 69 | @patch.object(requests, "post", side_effect=Exception("error")) 70 | def test_get_access_token_failed_post(self, mocked_post): 71 | cfg = config.Config( 72 | { 73 | "consumer_key": "keyxxxxxxxxxxxxxxxxxxxx", 74 | "consumer_secret": "secretxxxxxxxxxx", 75 | } 76 | ) 77 | cl = client.Client(cfg) 78 | cl.request_token = "request_token" 79 | cl.request_token_secret = "request_secret" 80 | 81 | with self.assertRaises(Exception): 82 | cl.get_access_token("verifier") 83 | 84 | @patch.object( 85 | requests, "get", return_value=Mock(status_code=200, json=lambda: {"a": "b"}) 86 | ) 87 | @patch.object( 88 | requests, "post", return_value=Mock(status_code=200, json=lambda: {"a": "b"}) 89 | ) 90 | @patch.object( 91 | requests, "put", return_value=Mock(status_code=200, json=lambda: {"a": "b"}) 92 | ) 93 | @patch.object( 94 | requests, "delete", return_value=Mock(status_code=200, json=lambda: {"a": "b"}) 95 | ) 96 | def test_send_request(self, mocked_get, mocked_post, mocked_put, mocked_delete): 97 | cfg = config.Config( 98 | { 99 | "consumer_key": "keyxxxxxxxxxxxxxxxxxxxx", 100 | "consumer_secret": "secretxxxxxxxxxx", 101 | "access_token": "tokenxxxxxxxxxxxxxxxxxxxx", 102 | "access_token_secret": "tokensecretxxxxx", 103 | } 104 | ) 105 | cl = client.Client(cfg) 106 | cl.requests = requests 107 | assert cl.get("/test/uri", {}) == {"a": "b"} 108 | assert cl.post("/test/uri", {}) == {"a": "b"} 109 | assert cl.put("/test/uri", {}) == {"a": "b"} 110 | assert cl.delete("/test/uri", {}) == {"a": "b"} 111 | 112 | with self.assertRaises(ValueError): 113 | cl.send_request("/test/uri", "method", {}) 114 | 115 | def test_get_authorization_url(self): 116 | cl = client.Client(object) 117 | cl.request_token = "token" 118 | 119 | assert ( 120 | cl.get_authorization_url("https://callback") 121 | == "https://www.upwork.com/services/api/auth?oauth_token=token&oauth_callback=https%3A%2F%2Fcallback" 122 | ) 123 | assert ( 124 | cl.get_authorization_url() 125 | == "https://www.upwork.com/services/api/auth?oauth_token=token" 126 | ) 127 | 128 | def test_full_url(self): 129 | assert client.full_url("/test/uri") == "https://www.upwork.com/api/test/uri" 130 | assert ( 131 | client.full_url("/test/uri", "gds") == "https://www.upwork.com/gds/test/uri" 132 | ) 133 | 134 | def test_get_uri_with_format(self): 135 | assert client.get_uri_with_format("/test/uri", "api") == "/test/uri.json" 136 | assert client.get_uri_with_format("/test/uri", "gds") == "/test/uri" 137 | -------------------------------------------------------------------------------- /tests/test_config.py: -------------------------------------------------------------------------------- 1 | from upwork import config 2 | 3 | 4 | def test_config_initialization(): 5 | cfg = config.Config( 6 | { 7 | "consumer_key": "keyxxxxxxxxxxxxxxxxxxxx", 8 | "consumer_secret": "secretxxxxxxxxxx", 9 | "access_token": "tokenxxxxxxxxxxxxxxxxxxxx", 10 | "access_token_secret": "tokensecretxxxxx", 11 | } 12 | ) 13 | 14 | assert cfg.consumer_key == "keyxxxxxxxxxxxxxxxxxxxx" 15 | assert cfg.consumer_secret == "secretxxxxxxxxxx" 16 | assert cfg.access_token == "tokenxxxxxxxxxxxxxxxxxxxx" 17 | assert cfg.access_token_secret == "tokensecretxxxxx" 18 | -------------------------------------------------------------------------------- /tests/test_upwork.py: -------------------------------------------------------------------------------- 1 | from upwork import upwork 2 | 3 | 4 | def test_upwork(): 5 | assert upwork is not None 6 | -------------------------------------------------------------------------------- /upwork/__init__.py: -------------------------------------------------------------------------------- 1 | """Top-level package for python-upwork.""" 2 | 3 | from upwork.config import Config 4 | from upwork.client import Client 5 | from . import routers 6 | 7 | __author__ = """Maksym Novozhylov""" 8 | __email__ = "mnovozhilov@upwork.com" 9 | __version__ = "2.1.0" 10 | 11 | __all__ = ("Config", "Client", "routers") 12 | -------------------------------------------------------------------------------- /upwork/client.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | import requests 15 | from . import upwork 16 | from requests.adapters import HTTPAdapter 17 | from requests.packages.urllib3.util.retry import Retry 18 | from requests_oauthlib import OAuth1 # type: ignore 19 | from urllib.parse import parse_qsl, urlencode 20 | 21 | 22 | class Client(object): 23 | """API client for OAuth1 authorization 24 | 25 | *Parameters:* 26 | :config: An instance of upwork.Config class, which contains the configuration keys and tokens 27 | """ 28 | 29 | __data_format = "json" 30 | __overload_var = "http_method" 31 | 32 | __uri_auth = "/services/api/auth" 33 | __uri_rtoken = "/auth/v1/oauth/token/request" 34 | __uri_atoken = "/auth/v1/oauth/token/access" 35 | 36 | epoint = upwork.DEFAULT_EPOINT 37 | 38 | def __init__(self, config): 39 | self.config = config 40 | 41 | self.requests = requests.Session() 42 | self.requests.mount('https://', HTTPAdapter(max_retries=Retry(total=0))) 43 | 44 | def get_request_token(self): 45 | """Get request token""" 46 | oauth = OAuth1(self.config.consumer_key, self.config.consumer_secret) 47 | request_token_url = full_url(self.__uri_rtoken, upwork.DEFAULT_EPOINT) 48 | 49 | try: 50 | r = requests.post(url=request_token_url, auth=oauth, verify=self.config.verify_ssl) 51 | except Exception as e: 52 | raise e 53 | 54 | rtoken_response = dict(parse_qsl(r.content.decode("utf8"))) 55 | self.request_token = rtoken_response.get("oauth_token") 56 | self.request_token_secret = rtoken_response.get("oauth_token_secret") 57 | 58 | return self.request_token, self.request_token_secret 59 | 60 | def get_authorization_url(self, callback_url=None): 61 | """Get authorization URL 62 | 63 | :param callback_url: (Default value = None) 64 | 65 | """ 66 | oauth_token = ( 67 | getattr(self, "request_token", None) or self.get_request_token()[0] 68 | ) 69 | 70 | if callback_url: 71 | params = urlencode( 72 | {"oauth_token": oauth_token, "oauth_callback": callback_url} 73 | ) 74 | else: 75 | params = urlencode({"oauth_token": oauth_token}) 76 | 77 | return "{0}{1}?{2}".format(upwork.BASE_HOST, self.__uri_auth, params) 78 | 79 | def get_access_token(self, verifier): 80 | """Returns access token and access token secret 81 | 82 | :param verifier: 83 | 84 | """ 85 | try: 86 | request_token = self.request_token 87 | request_token_secret = self.request_token_secret 88 | except AttributeError as e: 89 | raise Exception( 90 | "Request token pair not found. You need to call get_authorization_url" 91 | ) 92 | 93 | oauth = OAuth1( 94 | self.config.consumer_key, 95 | client_secret=self.config.consumer_secret, 96 | resource_owner_key=self.request_token, 97 | resource_owner_secret=self.request_token_secret, 98 | verifier=verifier, 99 | ) 100 | 101 | access_token_url = full_url(self.__uri_atoken, upwork.DEFAULT_EPOINT) 102 | 103 | try: 104 | r = requests.post(url=access_token_url, auth=oauth, verify=self.config.verify_ssl) 105 | except Exception as e: 106 | raise e 107 | 108 | atoken_response = dict(parse_qsl(r.content.decode("utf8"))) 109 | self.config.access_token = atoken_response.get("oauth_token") 110 | self.config.access_token_secret = atoken_response.get("oauth_token_secret") 111 | 112 | return self.config.access_token, self.config.access_token_secret 113 | 114 | def get(self, uri, params=None): 115 | """Execute GET request 116 | 117 | :param uri: 118 | :param params: (Default value = None) 119 | 120 | """ 121 | return self.send_request(uri, "get", params) 122 | 123 | def post(self, uri, params=None): 124 | """Execute POST request 125 | 126 | :param uri: 127 | :param params: (Default value = None) 128 | 129 | """ 130 | return self.send_request(uri, "post", params) 131 | 132 | def put(self, uri, params=None): 133 | """Execute PUT request 134 | 135 | :param uri: 136 | :param params: (Default value = None) 137 | 138 | """ 139 | return self.send_request(uri, "put", params) 140 | 141 | def delete(self, uri, params=None): 142 | """Execute DELETE request 143 | 144 | :param uri: 145 | :param params: (Default value = None) 146 | 147 | """ 148 | return self.send_request(uri, "delete", params) 149 | 150 | def send_request(self, uri, method="get", params={}): 151 | """Send request 152 | 153 | :param uri: 154 | :param method: (Default value = 'get') 155 | :param params: (Default value = {}) 156 | 157 | """ 158 | # delete does not support passing the parameters 159 | if method == "delete": 160 | params[self.__overload_var] = method 161 | 162 | oauth = OAuth1( 163 | self.config.consumer_key, 164 | client_secret=self.config.consumer_secret, 165 | resource_owner_key=self.config.access_token, 166 | resource_owner_secret=self.config.access_token_secret, 167 | signature_type="query", 168 | ) 169 | 170 | url = full_url(get_uri_with_format(uri, self.epoint), self.epoint) 171 | 172 | if method == "get": 173 | r = self.requests.get(url, params=params, auth=oauth, verify=self.config.verify_ssl) 174 | elif method == "put": 175 | headers = {"Content-type": "application/json"} 176 | r = self.requests.put(url, json=params, headers=headers, auth=oauth, verify=self.config.verify_ssl) 177 | elif method in {"post", "delete"}: 178 | headers = {"Content-type": "application/json"} 179 | r = self.requests.post(url, json=params, headers=headers, auth=oauth, verify=self.config.verify_ssl) 180 | else: 181 | raise ValueError( 182 | 'Do not know how to handle http method "{0}"'.format(method) 183 | ) 184 | 185 | return r.json() 186 | 187 | 188 | """ 189 | 190 | """ 191 | 192 | 193 | def full_url(uri, epoint=None): 194 | """Get full URL 195 | 196 | :param uri: 197 | :param epoint: (Default value = None) 198 | 199 | """ 200 | if not epoint: 201 | epoint = upwork.DEFAULT_EPOINT 202 | return "{0}/{1}{2}".format(upwork.BASE_HOST, epoint, uri) 203 | 204 | 205 | def get_uri_with_format(uri, epoint): 206 | """Get URI with format ending 207 | 208 | :param uri: 209 | :param epoint: 210 | 211 | """ 212 | if epoint == upwork.DEFAULT_EPOINT: 213 | uri += ".json" 214 | return uri 215 | -------------------------------------------------------------------------------- /upwork/config.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Config: 16 | """Configuration container""" 17 | 18 | verify_ssl = True 19 | 20 | def __init__(self, config): 21 | self.consumer_key, self.consumer_secret = ( 22 | config["consumer_key"], 23 | config["consumer_secret"], 24 | ) 25 | 26 | if "access_token" in config: 27 | self.access_token = config["access_token"] 28 | 29 | if "access_token_secret" in config: 30 | self.access_token_secret = config["access_token_secret"] 31 | 32 | if "verify_ssl" in config: 33 | self.verify_ssl = config["verify_ssl"] 34 | -------------------------------------------------------------------------------- /upwork/routers/__init__.py: -------------------------------------------------------------------------------- 1 | """routers""" 2 | from . import activities, auth, freelancers, hr, jobs 3 | from . import messages, metadata, organization, payments 4 | from . import reports, snapshots, workdays, workdiary 5 | 6 | __all__ = ( 7 | "activities", 8 | "auth", 9 | "freelancers", 10 | "hr", 11 | "jobs", 12 | "messages", 13 | "metadata", 14 | "organization", 15 | "payments", 16 | "reports", 17 | "snapshots", 18 | "workdays", 19 | "workdiary" 20 | ) 21 | -------------------------------------------------------------------------------- /upwork/routers/activities/__init__.py: -------------------------------------------------------------------------------- 1 | """routers""" 2 | -------------------------------------------------------------------------------- /upwork/routers/activities/engagement.py: -------------------------------------------------------------------------------- 1 | class Api: 2 | """ """ 3 | 4 | client = None 5 | 6 | def __init__(self, client): 7 | self.client = client 8 | 9 | def get_specific(self, engagement_ref): 10 | """List activities for specific engagement 11 | 12 | :param engagement_ref: String 13 | 14 | """ 15 | return self.client.get("/tasks/v2/tasks/contracts/{0}".format(engagement_ref)) 16 | 17 | def assign(self, company, team, engagement, params): 18 | """Assign engagements to the list of activities 19 | 20 | Parameters: 21 | :param company: 22 | :param team: 23 | :param engagement: 24 | :param params: 25 | 26 | """ 27 | return self.client.put( 28 | "/otask/v1/tasks/companies/{0}/teams/{1}/engagements/{2}/tasks".format( 29 | company, team, engagement 30 | ), 31 | params, 32 | ) 33 | 34 | def assign_to_engagement(self, engagement_ref, params): 35 | """Assign to specific engagement the list of activities 36 | 37 | Parameters: 38 | :param engagement_ref: 39 | :param params: 40 | 41 | """ 42 | return self.client.put( 43 | "/tasks/v2/tasks/contracts/{0}".format(engagement_ref), params 44 | ) 45 | -------------------------------------------------------------------------------- /upwork/routers/activities/team.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_list(self, company, team): 24 | """List all oTask/Activity records within a team 25 | 26 | :param company: String 27 | :param team: String 28 | 29 | """ 30 | return self.__get_by_type(company, team) 31 | 32 | def get_specific_list(self, company, team, code): 33 | """List all oTask/Activity records within a Company by specified code(s) 34 | 35 | :param company: String 36 | :param team: String 37 | :param code: String 38 | 39 | """ 40 | return self.__get_by_type(company, team, code) 41 | 42 | def add_activity(self, company, team, params): 43 | """Create an oTask/Activity record within a team 44 | 45 | Parameters: 46 | :param company: 47 | :param team: 48 | :param params: 49 | 50 | """ 51 | return self.client.post( 52 | "/otask/v1/tasks/companies/{0}/teams/{1}/tasks".format(company, team), 53 | params, 54 | ) 55 | 56 | def update_activities(self, company, team, code, params): 57 | """Update specific oTask/Activity record within a team 58 | 59 | Parameters: 60 | :param company: 61 | :param team: 62 | :param code: 63 | :param params: 64 | 65 | """ 66 | return self.client.put( 67 | "/otask/v1/tasks/companies/{0}/teams/{1}/tasks/{2}".format( 68 | company, team, code 69 | ), 70 | params, 71 | ) 72 | 73 | def archive_activities(self, company, team, code): 74 | """Archive specific oTask/Activity record within a team 75 | 76 | :param company: String 77 | :param team: String 78 | :param code: String 79 | 80 | """ 81 | return self.client.put( 82 | "/otask/v1/tasks/companies/{0}/teams/{1}/archive/{2}".format( 83 | company, team, code 84 | ) 85 | ) 86 | 87 | def unarchive_activities(self, company, team, code): 88 | """Unarchive specific oTask/Activity record within a team 89 | 90 | :param company: String 91 | :param team: String 92 | :param code: String 93 | 94 | """ 95 | return self.client.put( 96 | "/otask/v1/tasks/companies/{0}/teams/{1}/unarchive/{2}".format( 97 | company, team, code 98 | ) 99 | ) 100 | 101 | def update_batch(self, company, params): 102 | """Update a group of oTask/Activity records within a company 103 | 104 | Parameters: 105 | :param company: 106 | :param params: 107 | 108 | """ 109 | return self.client.put( 110 | "/otask/v1/tasks/companies/{0}/tasks/batch".format(company), params 111 | ) 112 | 113 | def __get_by_type(self, company, team, code=None): 114 | url = "" 115 | if code is not None: 116 | url = "/" + code 117 | 118 | return self.client.get( 119 | "/otask/v1/tasks/companies/{0}/teams/{1}/tasks{2}".format( 120 | company, team, url 121 | ) 122 | ) 123 | -------------------------------------------------------------------------------- /upwork/routers/auth.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_user_info(self): 24 | """Get info of authenticated user""" 25 | return self.client.get("/auth/v1/info") 26 | -------------------------------------------------------------------------------- /upwork/routers/freelancers/__init__.py: -------------------------------------------------------------------------------- 1 | """routers""" 2 | from . import profile, search 3 | 4 | __all__ = ("profile", "search") 5 | -------------------------------------------------------------------------------- /upwork/routers/freelancers/profile.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_specific(self, key): 24 | """Get specific profile 25 | 26 | :param key: String 27 | 28 | """ 29 | return self.client.get("/profiles/v1/providers/{0}".format(key)) 30 | 31 | def get_specific_brief(self, key): 32 | """Get brief info on specific profile 33 | 34 | :param key: String 35 | 36 | """ 37 | return self.client.get("/profiles/v1/providers/{0}/brief".format(key)) 38 | -------------------------------------------------------------------------------- /upwork/routers/freelancers/search.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def find(self, params): 24 | """Search profiles 25 | 26 | Parameters: 27 | 28 | :param params: 29 | 30 | """ 31 | return self.client.get("/profiles/v2/search/providers", params) 32 | -------------------------------------------------------------------------------- /upwork/routers/hr/__init__.py: -------------------------------------------------------------------------------- 1 | """routers""" 2 | from . import clients, contracts, engagements, freelancers 3 | from . import interviews, jobs, milestones, roles, submissions 4 | 5 | __all__ = ( 6 | "clients", 7 | "contracts", 8 | "engagements", 9 | "freelancers", 10 | "interviews", 11 | "jobs", 12 | "milestones", 13 | "roles", 14 | "submissions" 15 | ) 16 | -------------------------------------------------------------------------------- /upwork/routers/hr/clients/__init__.py: -------------------------------------------------------------------------------- 1 | """routers""" 2 | -------------------------------------------------------------------------------- /upwork/routers/hr/clients/applications.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_list(self, params): 24 | """Get list of applications 25 | 26 | Parameters: 27 | 28 | :param params: 29 | 30 | """ 31 | return self.client.get("/hr/v4/clients/applications", params) 32 | 33 | def get_specific(self, reference, params): 34 | """Get specific application 35 | 36 | Parameters: 37 | 38 | :param reference: 39 | :param params: 40 | 41 | """ 42 | return self.client.get( 43 | "/hr/v4/clients/applications/{0}".format(reference), params 44 | ) 45 | -------------------------------------------------------------------------------- /upwork/routers/hr/clients/offers.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_list(self, params): 24 | """Get list of offers 25 | 26 | Parameters: 27 | 28 | :param params: 29 | 30 | """ 31 | return self.client.get("/offers/v1/clients/offers", params) 32 | 33 | def get_specific(self, reference, params): 34 | """Get specific offer 35 | 36 | Parameters: 37 | 38 | :param reference: 39 | :param params: 40 | 41 | """ 42 | return self.client.get( 43 | "/offers/v1/clients/offers/{0}".format(reference), params 44 | ) 45 | 46 | def make_offer(self, params): 47 | """Make an Offer 48 | 49 | Parameters: 50 | 51 | :param params: 52 | 53 | """ 54 | return self.client.post("/offers/v1/clients/offers", params) 55 | -------------------------------------------------------------------------------- /upwork/routers/hr/contracts.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def suspend_contract(self, reference, params): 24 | """Suspend Contract 25 | 26 | Parameters: 27 | 28 | :param reference: 29 | :param params: 30 | 31 | """ 32 | return self.client.put("/hr/v2/contracts/{0}/suspend".format(reference), params) 33 | 34 | def restart_contract(self, reference, params): 35 | """Restart Contract 36 | 37 | Parameters: 38 | 39 | :param reference: 40 | :param params: 41 | 42 | """ 43 | return self.client.put("/hr/v2/contracts/{0}/restart".format(reference), params) 44 | 45 | def end_contract(self, reference, params): 46 | """End Contract 47 | 48 | Parameters: 49 | 50 | :param reference: 51 | :param params: 52 | 53 | """ 54 | return self.client.delete("/hr/v2/contracts/{0}".format(reference), params) 55 | -------------------------------------------------------------------------------- /upwork/routers/hr/engagements.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_list(self, params): 24 | """Get list of engagements 25 | 26 | Parameters: 27 | 28 | :param params: 29 | 30 | """ 31 | return self.client.get("/hr/v2/engagements", params) 32 | 33 | def get_specific(self, reference): 34 | """Get specific engagement 35 | 36 | :param reference: String 37 | 38 | """ 39 | return self.client.get("/hr/v2/engagements/{0}".format(reference)) 40 | -------------------------------------------------------------------------------- /upwork/routers/hr/freelancers/__init__.py: -------------------------------------------------------------------------------- 1 | """routers""" 2 | from . import applications, offers 3 | 4 | __all__ = ("applications", "offers") 5 | -------------------------------------------------------------------------------- /upwork/routers/hr/freelancers/applications.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_list(self, params={}): 24 | """Get list of applications 25 | 26 | Parameters: 27 | 28 | :param params: (Default value = {}) 29 | 30 | """ 31 | return self.client.get("/hr/v4/contractors/applications", params) 32 | 33 | def get_specific(self, reference): 34 | """Get specific application 35 | 36 | :param reference: String 37 | 38 | """ 39 | return self.client.get("/hr/v4/contractors/applications/{0}".format(reference)) 40 | -------------------------------------------------------------------------------- /upwork/routers/hr/freelancers/offers.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_list(self, params={}): 24 | """Get list of offers 25 | 26 | Parameters: 27 | 28 | :param params: (Default value = {}) 29 | 30 | """ 31 | return self.client.get("/offers/v1/contractors/offers", params) 32 | 33 | def get_specific(self, reference): 34 | """Get specific offer 35 | 36 | :param reference: String 37 | 38 | """ 39 | return self.client.get("/offers/v1/contractors/offers/{0}".format(reference)) 40 | 41 | def actions(self, reference, params): 42 | """Make an Offer 43 | 44 | Parameters: 45 | 46 | :param reference: 47 | :param params: 48 | 49 | """ 50 | return self.client.post( 51 | "/offers/v1/contractors/actions/{0}".format(reference), params 52 | ) 53 | -------------------------------------------------------------------------------- /upwork/routers/hr/interviews.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def invite(self, job_key, params): 24 | """Invite to Interview 25 | 26 | Parameters: 27 | 28 | :param job_key: 29 | :param params: 30 | 31 | """ 32 | return self.client.post("/hr/v1/jobs/{0}/candidates".format(job_key), params) 33 | -------------------------------------------------------------------------------- /upwork/routers/hr/jobs.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_list(self, params): 24 | """Get list of jobs 25 | 26 | Parameters: 27 | 28 | :param params: 29 | 30 | """ 31 | return self.client.get("/hr/v2/jobs", params) 32 | 33 | def get_specific(self, key): 34 | """Get specific job by key 35 | 36 | :param key: String 37 | 38 | """ 39 | return self.client.get("/hr/v2/jobs/{0}".format(key)) 40 | 41 | def post_job(self, params): 42 | """Post a new job 43 | 44 | Parameters: 45 | 46 | :param params: 47 | 48 | """ 49 | return self.client.post("/hr/v2/jobs", params) 50 | 51 | def edit_job(self, key, params): 52 | """Edit existent job 53 | 54 | Parameters: 55 | 56 | :param key: 57 | :param params: 58 | 59 | """ 60 | self.client.put("/hr/v2/jobs/{0}".format(key), params) 61 | 62 | def delete_job(self, key, params): 63 | """Delete existent job 64 | 65 | Parameters: 66 | 67 | :param key: 68 | :param params: 69 | 70 | """ 71 | self.client.delete("/hr/v2/jobs/{0}".format(key), params) 72 | -------------------------------------------------------------------------------- /upwork/routers/hr/milestones.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_active_milestone(self, contract_id): 24 | """Get active Milestone for specific Contract 25 | 26 | :param contract_id: String 27 | 28 | """ 29 | return self.client.get( 30 | "/hr/v3/fp/milestones/statuses/active/contracts/{0}".format(contract_id) 31 | ) 32 | 33 | def get_submissions(self, milestone_id): 34 | """Get active Milestone for specific Contract 35 | 36 | :param milestone_id: String 37 | 38 | """ 39 | return self.client.get( 40 | "/hr/v3/fp/milestones/{0}/submissions".format(milestone_id) 41 | ) 42 | 43 | def create(self, params): 44 | """Create a new Milestone 45 | 46 | Parameters: 47 | 48 | :param params: 49 | 50 | """ 51 | return self.client.post("/hr/v3/fp/milestones", params) 52 | 53 | def edit(self, milestone_id, params): 54 | """Edit an existing Milestone 55 | 56 | Parameters: 57 | 58 | :param milestone_id: 59 | :param params: 60 | 61 | """ 62 | return self.client.put("/hr/v3/fp/milestones/{0}".format(milestone_id), params) 63 | 64 | def activate(self, milestone_id, params): 65 | """Activate an existing Milestone 66 | 67 | Parameters: 68 | 69 | :param milestone_id: 70 | :param params: 71 | 72 | """ 73 | return self.client.put( 74 | "/hr/v3/fp/milestones/{0}/activate".format(milestone_id), params 75 | ) 76 | 77 | def approve(self, milestone_id, params): 78 | """Approve an existing Milestone 79 | 80 | Parameters: 81 | 82 | :param milestone_id: 83 | :param params: 84 | 85 | """ 86 | return self.client.put( 87 | "/hr/v3/fp/milestones/{0}/approve".format(milestone_id), params 88 | ) 89 | 90 | def delete(self, milestone_id): 91 | """Delete an existing Milestone 92 | 93 | :param milestone_id: String 94 | 95 | """ 96 | return self.client.delete("/hr/v3/fp/milestones/{0}".format(milestone_id)) 97 | -------------------------------------------------------------------------------- /upwork/routers/hr/roles.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_all(self): 24 | """Get user roles""" 25 | return self.client.get("/hr/v2/userroles") 26 | 27 | def get_by_specific_user(self, user_reference): 28 | """Get by specific user 29 | 30 | :param reference: String 31 | :param user_reference: 32 | 33 | """ 34 | return self.client.get("/hr/v2/userroles/{0}".format(user_reference)) 35 | -------------------------------------------------------------------------------- /upwork/routers/hr/submissions.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def request_approval(self, params): 24 | """Freelancer submits work for the client to approve 25 | 26 | Parameters: 27 | 28 | :param params: 29 | 30 | """ 31 | return self.client.post("/hr/v3/fp/submissions", params) 32 | 33 | def approve(self, submission_id, params): 34 | """Approve an existing Submission 35 | 36 | Parameters: 37 | 38 | :param submission_id: 39 | :param params: 40 | 41 | """ 42 | return self.client.put( 43 | "/hr/v3/fp/submissions/{0}/approve".format(submission_id), params 44 | ) 45 | 46 | def reject(self, submission_id, params): 47 | """Reject an existing Submission 48 | 49 | Parameters: 50 | 51 | :param submission_id: 52 | :param params: 53 | 54 | """ 55 | return self.client.put( 56 | "/hr/v3/fp/submissions/{0}/reject".format(submission_id), params 57 | ) 58 | -------------------------------------------------------------------------------- /upwork/routers/jobs/__init__.py: -------------------------------------------------------------------------------- 1 | """routers""" 2 | from . import profile, search 3 | 4 | __all__ = ("profile", "search") 5 | -------------------------------------------------------------------------------- /upwork/routers/jobs/profile.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_specific(self, key): 24 | """Get specific profile 25 | 26 | :param key: String 27 | 28 | """ 29 | return self.client.get("/profiles/v1/jobs/{0}".format(key)) 30 | -------------------------------------------------------------------------------- /upwork/routers/jobs/search.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def find(self, params): 24 | """Search profiles 25 | 26 | Parameters: 27 | 28 | :param params: 29 | 30 | """ 31 | return self.client.get("/profiles/v2/search/jobs", params) 32 | -------------------------------------------------------------------------------- /upwork/routers/messages.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_rooms(self, company, params={}): 24 | """Retrieve rooms information 25 | 26 | Parameters: 27 | :param company: 28 | :param params: (Default value = {}) 29 | 30 | """ 31 | return self.client.get("/messages/v3/{0}/rooms".format(company), params) 32 | 33 | def get_room_details(self, company, room_id, params={}): 34 | """Get a specific room information 35 | 36 | Parameters: 37 | :param company: 38 | :param room_id: 39 | :param params: (Default value = {}) 40 | 41 | """ 42 | return self.client.get( 43 | "/messages/v3/{0}/rooms/{1}".format(company, room_id), params 44 | ) 45 | 46 | def get_room_messages(self, company, room_id, params={}): 47 | """Get messages from a specific room 48 | 49 | Parameters: 50 | :param company: 51 | :param room_id: 52 | :param params: (Default value = {}) 53 | 54 | """ 55 | return self.client.get( 56 | "/messages/v3/{0}/rooms/{1}/stories".format(company, room_id), params 57 | ) 58 | 59 | def get_room_by_offer(self, company, offer_id, params={}): 60 | """Get a specific room by offer ID 61 | 62 | Parameters: 63 | :param company: 64 | :param offer_id: 65 | :param params: (Default value = {}) 66 | 67 | """ 68 | return self.client.get( 69 | "/messages/v3/{0}/rooms/offers/{1}".format(company, offer_id), params 70 | ) 71 | 72 | def get_room_by_application(self, company, application_id, params={}): 73 | """Get a specific room by application ID 74 | 75 | Parameters: 76 | :param company: 77 | :param application_id: 78 | :param params: (Default value = {}) 79 | 80 | """ 81 | return self.client.get( 82 | "/messages/v3/{0}/rooms/applications/{1}".format(company, application_id), 83 | params, 84 | ) 85 | 86 | def get_room_by_contract(self, company, contract_id, params={}): 87 | """Get a specific room by contract ID 88 | 89 | Parameters: 90 | :param company: 91 | :param contract_id: 92 | :param params: (Default value = {}) 93 | 94 | """ 95 | return self.client.get( 96 | "/messages/v3/{0}/rooms/contracts/{1}".format(company, contract_id), params 97 | ) 98 | 99 | def create_room(self, company, params={}): 100 | """Create a new room 101 | 102 | Parameters: 103 | :param company: 104 | :param params: (Default value = {}) 105 | 106 | """ 107 | return self.client.post("/messages/v3/{0}/rooms".format(company), params) 108 | 109 | def send_message_to_room(self, company, room_id, params={}): 110 | """Send a message to a room 111 | 112 | Parameters: 113 | :param company: 114 | :param room_id: 115 | :param params: (Default value = {}) 116 | 117 | """ 118 | return self.client.post( 119 | "/messages/v3/{0}/rooms/{1}/stories".format(company, room_id), params 120 | ) 121 | 122 | def send_message_to_rooms(self, company, params={}): 123 | """Send a message to a batch of rooms 124 | 125 | Parameters: 126 | :param company: 127 | :param params: (Default value = {}) 128 | 129 | """ 130 | return self.client.post( 131 | "/messages/v3/{0}/stories/batch".format(company), params 132 | ) 133 | 134 | def update_room_settings(self, company, room_id, username, params={}): 135 | """Update a room settings 136 | 137 | Parameters: 138 | :param company: 139 | :param room_id: 140 | :param username: 141 | :param params: (Default value = {}) 142 | 143 | """ 144 | return self.client.put( 145 | "/messages/v3/{0}/rooms/{1}/users/{2}".format(company, room_id, username), 146 | params, 147 | ) 148 | 149 | def update_room_metadata(self, company, room_id, params={}): 150 | """Update the metadata of a room 151 | 152 | Parameters: 153 | :param company: 154 | :param room_id: 155 | :param params: (Default value = {}) 156 | 157 | """ 158 | return self.client.put( 159 | "/messages/v3/{0}/rooms/{1}".format(company, room_id), params 160 | ) 161 | -------------------------------------------------------------------------------- /upwork/routers/metadata.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_categories_v2(self): 24 | """Get categories (V2)""" 25 | return self.client.get("/profiles/v2/metadata/categories") 26 | 27 | def get_skills(self): 28 | """Get skills""" 29 | return self.client.get("/profiles/v1/metadata/skills") 30 | 31 | def get_skills_v2(self, params): 32 | """Get skills (V2) 33 | 34 | :param params: 35 | 36 | """ 37 | return self.client.get("/profiles/v2/metadata/skills", params) 38 | 39 | def get_specialties(self): 40 | """Get specialties""" 41 | return self.client.get("/profiles/v1/metadata/specialties") 42 | 43 | def get_regions(self): 44 | """Get regions""" 45 | return self.client.get("/profiles/v1/metadata/regions") 46 | 47 | def get_tests(self): 48 | """Get tests""" 49 | return self.client.get("/profiles/v1/metadata/tests") 50 | 51 | def get_reasons(self, params): 52 | """Get reasons 53 | 54 | :param params: 55 | 56 | """ 57 | return self.client.get("/profiles/v1/metadata/reasons", params) 58 | -------------------------------------------------------------------------------- /upwork/routers/organization/__init__.py: -------------------------------------------------------------------------------- 1 | """routers""" 2 | from . import companies, teams, users 3 | 4 | __all__ = ("companies", "teams", "users") 5 | -------------------------------------------------------------------------------- /upwork/routers/organization/companies.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_list(self): 24 | """Get Companies Info""" 25 | return self.client.get("/hr/v2/companies") 26 | 27 | def get_specific(self, company_reference): 28 | """Get Specific Company 29 | 30 | :param company_reference: String 31 | 32 | """ 33 | return self.client.get("/hr/v2/companies/{0}".format(company_reference)) 34 | 35 | def get_teams(self, company_reference): 36 | """Get Teams in Company 37 | 38 | :param company_reference: String 39 | 40 | """ 41 | return self.client.get("/hr/v2/companies/{0}/teams".format(company_reference)) 42 | 43 | def get_users(self, company_reference): 44 | """Get Users in Company 45 | 46 | :param company_reference: String 47 | 48 | """ 49 | return self.client.get("/hr/v2/companies/{0}/users".format(company_reference)) 50 | -------------------------------------------------------------------------------- /upwork/routers/organization/teams.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_list(self): 24 | """Get Teams""" 25 | return self.client.get("/hr/v2/teams") 26 | 27 | def get_users_in_team(self, team_reference): 28 | """Get Users in Team 29 | 30 | :param team_reference: String 31 | 32 | """ 33 | return self.client.get("/hr/v2/teams/{0}/users".format(team_reference)) 34 | -------------------------------------------------------------------------------- /upwork/routers/organization/users.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_my_info(self): 24 | """Get Auth user info""" 25 | return self.client.get("/hr/v2/users/me") 26 | 27 | def get_specific(self, user_reference): 28 | """Get Specific User Info 29 | 30 | :param user_reference: String 31 | 32 | """ 33 | return self.client.get("/hr/v2/users/{0}".format(user_reference)) 34 | -------------------------------------------------------------------------------- /upwork/routers/payments.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def submit_bonus(self, team_reference, params): 24 | """Submit bonus 25 | 26 | :param team_reference: String 27 | :param params: 28 | 29 | """ 30 | return self.client.post( 31 | "/hr/v2/teams/{0}/adjustments".format(team_reference), params 32 | ) 33 | -------------------------------------------------------------------------------- /upwork/routers/reports/__init__.py: -------------------------------------------------------------------------------- 1 | """routers""" 2 | from . import finance, time 3 | 4 | __all__ = ("finance", "time") 5 | -------------------------------------------------------------------------------- /upwork/routers/reports/finance/__init__.py: -------------------------------------------------------------------------------- 1 | """routers""" 2 | from . import accounts, billings, earnings 3 | 4 | __all__ = ("accounts", "billings", "earnings") 5 | -------------------------------------------------------------------------------- /upwork/routers/reports/finance/accounts.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Gds: 16 | """ """ 17 | 18 | client = None 19 | entry_point = "gds" 20 | 21 | def __init__(self, client): 22 | self.client = client 23 | self.client.epoint = self.entry_point 24 | 25 | def get_owned(self, freelancer_reference, params): 26 | """Generate Financial Reports for an owned Account 27 | 28 | Arguments: 29 | 30 | :param freelancer_reference: param params: 31 | :param params: 32 | 33 | """ 34 | return self.client.get( 35 | "/finreports/v2/financial_account_owner/{0}".format(freelancer_reference), 36 | params, 37 | ) 38 | 39 | def get_specific(self, entity_reference, params): 40 | """Generate Financial Reports for a Specific Account 41 | 42 | Arguments: 43 | 44 | :param entity_reference: param params: 45 | :param params: 46 | 47 | """ 48 | return self.client.get( 49 | "/finreports/v2/financial_accounts/{0}".format(entity_reference), params 50 | ) 51 | -------------------------------------------------------------------------------- /upwork/routers/reports/finance/billings.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Gds: 16 | """ """ 17 | 18 | client = None 19 | entry_point = "gds" 20 | 21 | def __init__(self, client): 22 | self.client = client 23 | self.client.epoint = self.entry_point 24 | 25 | def get_by_freelancer(self, freelancer_reference, params): 26 | """Generate Billing Reports for a Specific Freelancer 27 | 28 | Parameters: 29 | 30 | :param freelancer_reference: 31 | :param params: 32 | 33 | """ 34 | return self.client.get( 35 | "/finreports/v2/providers/{0}/billings".format(freelancer_reference), params 36 | ) 37 | 38 | def get_by_freelancers_team(self, freelancer_team_reference, params): 39 | """Generate Billing Reports for a Specific Freelancer's Team 40 | 41 | Parameters: 42 | 43 | :param freelancer_team_reference: 44 | :param params: 45 | 46 | """ 47 | return self.client.get( 48 | "/finreports/v2/provider_teams/{0}/billings".format( 49 | freelancer_team_reference 50 | ), 51 | params, 52 | ) 53 | 54 | def get_by_freelancers_company(self, freelancer_company_reference, params): 55 | """Generate Billing Reports for a Specific Freelancer's Company 56 | 57 | Parameters: 58 | 59 | :param freelancer_company_reference: 60 | :param params: 61 | 62 | """ 63 | return self.client.get( 64 | "/finreports/v2/provider_companies/{0}/billings".format( 65 | freelancer_company_reference 66 | ), 67 | params, 68 | ) 69 | 70 | def get_by_buyers_team(self, buyer_team_reference, params): 71 | """Generate Billing Reports for a Specific Buyer's Team 72 | 73 | Parameters: 74 | 75 | :param buyer_team_reference: 76 | :param params: 77 | 78 | """ 79 | return self.client.get( 80 | "/finreports/v2/buyer_teams/{0}/billings".format(buyer_team_reference), 81 | params, 82 | ) 83 | 84 | def get_by_buyers_company(self, buyer_company_reference, params): 85 | """Generate Billing Reports for a Specific Buyer's Company 86 | 87 | Parameters: 88 | 89 | :param buyer_company_reference: 90 | :param params: 91 | 92 | """ 93 | return self.client.get( 94 | "/finreports/v2/buyer_companies/{0}/billings".format( 95 | buyer_company_reference 96 | ), 97 | params, 98 | ) 99 | -------------------------------------------------------------------------------- /upwork/routers/reports/finance/earnings.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Gds: 16 | """ """ 17 | 18 | client = None 19 | entry_point = "gds" 20 | 21 | def __init__(self, client): 22 | self.client = client 23 | self.client.epoint = self.entry_point 24 | 25 | def get_by_freelancer(self, freelancer_reference, params): 26 | """Generate Earning Reports for a Specific Freelancer 27 | 28 | Parameters: 29 | 30 | :param freelancer_reference: 31 | :param params: 32 | 33 | """ 34 | return self.client.get( 35 | "/finreports/v2/providers/{0}/earnings".format(freelancer_reference), params 36 | ) 37 | 38 | def get_by_freelancers_team(self, freelancer_team_reference, params): 39 | """Generate Earning Reports for a Specific Freelancer's Team 40 | 41 | Parameters: 42 | 43 | :param freelancer_team_reference: 44 | :param params: 45 | 46 | """ 47 | return self.client.get( 48 | "/finreports/v2/provider_teams/{0}/earnings".format( 49 | freelancer_team_reference 50 | ), 51 | params, 52 | ) 53 | 54 | def get_by_freelancers_company(self, freelancer_company_reference, params): 55 | """Generate Earning Reports for a Specific Freelancer's Company 56 | 57 | Parameters: 58 | 59 | :param freelancer_company_reference: 60 | :param params: 61 | 62 | """ 63 | return self.client.get( 64 | "/finreports/v2/provider_companies/{0}/earnings".format( 65 | freelancer_company_reference 66 | ), 67 | params, 68 | ) 69 | 70 | def get_by_buyers_team(self, buyer_team_reference, params): 71 | """Generate Earning Reports for a Specific Buyer's Team 72 | 73 | Parameters: 74 | 75 | :param buyer_team_reference: 76 | :param params: 77 | 78 | """ 79 | return self.client.get( 80 | "/finreports/v2/buyer_teams/{0}/earnings".format(buyer_team_reference), 81 | params, 82 | ) 83 | 84 | def get_by_buyers_company(self, buyer_company_reference, params): 85 | """Generate Earning Reports for a Specific Buyer's Company 86 | 87 | Parameters: 88 | 89 | :param buyer_company_reference: 90 | :param params: 91 | 92 | """ 93 | return self.client.get( 94 | "/finreports/v2/buyer_companies/{0}/earnings".format( 95 | buyer_company_reference 96 | ), 97 | params, 98 | ) 99 | -------------------------------------------------------------------------------- /upwork/routers/reports/time.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Gds: 16 | """ """ 17 | 18 | client = None 19 | entry_point = "gds" 20 | 21 | def __init__(self, client): 22 | self.client = client 23 | self.client.epoint = self.entry_point 24 | 25 | def get_by_team_full(self, company, team, params): 26 | """Generate Time Reports for a Specific Team (with financial info) 27 | 28 | Parameters: 29 | 30 | :param company: 31 | :param team: 32 | :param params: 33 | 34 | """ 35 | return self.__get_by_type(company, team, None, params, False) 36 | 37 | def get_by_team_limited(self, company, team, params): 38 | """Generate Time Reports for a Specific Team (hide financial info) 39 | 40 | Parameters: 41 | 42 | :param company: 43 | :param team: 44 | :param params: 45 | 46 | """ 47 | return self.__get_by_type(company, team, None, params, True) 48 | 49 | def get_by_agency(self, company, agency, params): 50 | """Generating Agency Specific Reports 51 | 52 | Parameters: 53 | 54 | :param company: 55 | :param agency: 56 | :param params: 57 | 58 | """ 59 | return self.__get_by_type(company, None, agency, params, False) 60 | 61 | def get_by_company(self, company, params): 62 | """Generating Company Wide Reports 63 | 64 | Parameters: 65 | 66 | :param company: 67 | :param params: 68 | 69 | """ 70 | return self.__get_by_type(company, None, None, params, False) 71 | 72 | def get_by_freelancer_limited(self, freelancer_id, params): 73 | """Generating Freelancer's Specific Reports (hide financial info) 74 | 75 | Parameters: 76 | 77 | :param freelancer_id: 78 | :param params: 79 | 80 | """ 81 | return self.client.get( 82 | "/timereports/v1/providers/{0}/hours".format(freelancer_id), params 83 | ) 84 | 85 | def get_by_freelancer_full(self, freelancer_id, params): 86 | """Generating Freelancer's Specific Reports (with financial info) 87 | 88 | Parameters: 89 | 90 | :param freelancer_id: 91 | :param params: 92 | 93 | """ 94 | return self.client.get( 95 | "/timereports/v1/providers/{0}".format(freelancer_id), params 96 | ) 97 | 98 | def __get_by_type(self, company, team, agency, params, hide_fin_data): 99 | url = "" 100 | if team is not None: 101 | url = "/teams/{0}".format(team) 102 | if hide_fin_data: 103 | url = url + "/hours" 104 | elif agency is not None: 105 | url = "/agencies/{0}".format(agency) 106 | 107 | return self.client.get( 108 | "/timereports/v1/companies/{0}{1}".format(company, url), params 109 | ) 110 | -------------------------------------------------------------------------------- /upwork/routers/snapshots.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_by_contract(self, contract, ts): 24 | """Get snapshot info by specific contract 25 | 26 | :param contract: String 27 | :param ts: String 28 | 29 | """ 30 | return self.client.get( 31 | "/team/v3/snapshots/contracts/{0}/{1}".format(contract, ts) 32 | ) 33 | 34 | def update_by_contract(self, contract, ts, params): 35 | """Update snapshot by specific contract 36 | 37 | Parameters: 38 | :param contract: String 39 | :param ts: String 40 | :param params: 41 | 42 | """ 43 | return self.client.put( 44 | "/team/v3/snapshots/contracts/{0}/{1}".format(contract, ts), params 45 | ) 46 | 47 | def delete_by_contract(self, contract, ts): 48 | """Delete snapshot by specific contract 49 | 50 | :param contract: String 51 | :param ts: String 52 | 53 | """ 54 | return self.client.delete( 55 | "/team/v3/snapshots/contracts/{0}/{1}".format(contract, ts) 56 | ) 57 | -------------------------------------------------------------------------------- /upwork/routers/workdays.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_by_company(self, company, from_date, till_date, params={}): 24 | """Get Workdays by Company 25 | 26 | Parameters: 27 | :param company: 28 | :param from_date: 29 | :param till_date: 30 | :param params: (Default value = {}) 31 | 32 | """ 33 | return self.client.get( 34 | "/team/v3/workdays/companies/{0}/{1},{2}".format( 35 | company, from_date, till_date 36 | ), 37 | params, 38 | ) 39 | 40 | def get_by_contract(self, contract, from_date, till_date, params={}): 41 | """Get Workdays by Contract 42 | 43 | Parameters: 44 | :param contract: 45 | :param from_date: 46 | :param till_date: 47 | :param params: (Default value = {}) 48 | 49 | """ 50 | return self.client.get( 51 | "/team/v3/workdays/contracts/{0}/{1},{2}".format( 52 | contract, from_date, till_date 53 | ), 54 | params, 55 | ) 56 | -------------------------------------------------------------------------------- /upwork/routers/workdiary.py: -------------------------------------------------------------------------------- 1 | # Licensed under the Upwork's API Terms of Use; 2 | # you may not use this file except in compliance with the Terms. 3 | # 4 | # Unless required by applicable law or agreed to in writing, software 5 | # distributed under the License is distributed on an "AS IS" BASIS, 6 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | # See the License for the specific language governing permissions and 8 | # limitations under the License. 9 | # 10 | # Author:: Maksym Novozhylov (mnovozhilov@upwork.com) 11 | # Copyright:: Copyright 2020(c) Upwork.com 12 | # License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html 13 | 14 | 15 | class Api: 16 | """ """ 17 | 18 | client = None 19 | 20 | def __init__(self, client): 21 | self.client = client 22 | 23 | def get_workdiary(self, company, date, params={}): 24 | """Get Workdiary by Company 25 | 26 | Parameters: 27 | :param company: 28 | :param date: 29 | :param params: (Default value = {}) 30 | 31 | """ 32 | return self.client.get( 33 | "/team/v3/workdiaries/companies/{0}/{1}".format(company, date), params 34 | ) 35 | 36 | def get_by_contract(self, contract, date, params={}): 37 | """Get Work Diary by Contract 38 | 39 | Parameters: 40 | :param contract: 41 | :param date: 42 | :param params: (Default value = {}) 43 | 44 | """ 45 | return self.client.get( 46 | "/team/v3/workdiaries/contracts/{0}/{1}".format(contract, date), params 47 | ) 48 | -------------------------------------------------------------------------------- /upwork/upwork.py: -------------------------------------------------------------------------------- 1 | """Main module.""" 2 | 3 | BASE_HOST = "https://www.upwork.com" 4 | DEFAULT_EPOINT = "api" 5 | --------------------------------------------------------------------------------