Skip to content
Closed

tee #15

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
# execution artefacts
*.pyc
.coverage
.DS_Store

# dist artefacts
build/
.idea
dist/
build/
cloudconvert.egg-info/
*.egg

# dev artefacts
.idea
test.py
*.egg
17 changes: 8 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
language: python
python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- '3.7'
- '3.6'
- '3.5'
- '2.7'

install:
- pip install .
- pip install -r requirements-dev.txt
script: nosetests
sudo: false
- pip install -r requirements.txt

script: python tests/unit/testTask.py || python tests/unit/testJob.py || python tests/unit/testWebhookSignature.py
21 changes: 21 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The License (MIT)

Copyright (c) 2020 Josias Montag <josias@montag.info>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
131 changes: 131 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
## cloudconvert-python

This is the official Python SDK v2 for the [CloudConvert](https://cloudconvert.com/api/v2) _API v2_.
For API v1, please use [v1 branch](https://github.com/cloudconvert/cloudconvert-python/tree/v1) of this repository.


[![Build Status](https://travis-ci.org/cloudconvert/cloudconvert-python.svg?branch=master)](https://travis-ci.org/cloudconvert/cloudconvert-python)
## Installation

```
pip install cloudconvert
```

## Creating API Client

```
import cloudconvert

cloudconvert.configure(api_key = 'API_KEY', sandbox = False)
```

Or set the environment variable `CLOUDCONVERT_API_KEY` and use:

```
import cloudconvert

cloudconvert.default()
```

## Creating Jobs

```js
import cloudconvert

cloudconvert.configure(api_key = 'API_KEY')

cloudconvert.Job.create(payload={
"tasks": {
'import-my-file': {
'operation': 'import/url',
'url': 'https://my-url'
},
'convert-my-file': {
'operation': 'convert',
'input': 'import-my-file',
'output_format': 'pdf',
'some_other_option': 'value'
},
'export-my-file': {
'operation': 'export/url',
'input': 'convert-my-file'
}
}
})

```

## Downloading Files

CloudConvert can generate public URLs for using `export/url` tasks. You can use these URLs to download output files.

```js
exported_url_task_id = "84e872fc-d823-4363-baab-eade2e05ee54"
res = cloudconvert.Task.wait(id=exported_url_task_id) # Wait for job completion
file = res.get("result").get("files")[0]
res = cloudconvert.download(filename=file['filename'], url=file['url'])
print(res)
```

## Uploading Files

Uploads to CloudConvert are done via `import/upload` tasks (see the [docs](https://cloudconvert.com/api/v2/import#import-upload-tasks)). This SDK offers a convenient upload method:

```js
job = cloudconvert.Job.create(payload={
'tasks': {
'upload-my-file': {
'operation': 'import/upload'
}
}
})

upload_task_id = job['tasks'][0]['id']

upload_task = cloudconvert.Task.find(id=upload_task_id)
res = cloudconvert.Task.upload(file_name='path/to/sample.pdf', task=upload_task)

res = cloudconvert.Task.find(id=upload_task_id)
```
## Webhook Signing

The node SDK allows to verify webhook requests received from CloudConvert.

```js
payloadString = '...'; # The JSON string from the raw request body.
signature = '...'; # The value of the "CloudConvert-Signature" header.
signingSecret = '...'; # You can find it in your webhook settings.

isValid = cloudconvert.Webhook.verify(payloadString, signature, signingSecret); # returns true or false
```

## Unit Tests

```
# Run Task tests
$ python tests/unit/testTask.py

# Run Job tests
$ python tests/unit/testJob.py

# Run Webhook tests
$ python tests/unit/testWebhookSignature.py

```


## Integration Tests
```
# Run Integration test for task
$ python tests/integration/testTasks.py

# Run Integration test for Job
$ python tests/integration/testJobs.py

```


## Resources

* [API v2 Documentation](https://cloudconvert.com/api/v2)
* [CloudConvert Blog](https://cloudconvert.com/blog)
96 changes: 0 additions & 96 deletions README.rst

This file was deleted.

25 changes: 20 additions & 5 deletions cloudconvert/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
from .api import Api
from .api import Process
from .exceptions import (
APIError, HTTPError, BadRequest, ConversionFailed, TemporaryUnavailable, InvalidResponse, InvalidParameterException
)
from cloudconvert.cloudconvertrestclient import *
from cloudconvert.task import Task
from cloudconvert.job import Job
from cloudconvert.webhook import Webhook

def configure(**config):
"""
Configure the REST Client With Latest API Key and Mode
:return:
"""
set_config(**config)


def default():
"""
Configure the REST Client With Default API Key and Mode
:return:
"""
default_client()

Loading