Skip to content

Commit a2991ff

Browse files
authored
Merge pull request #14 from KhushbooMer/fix-ai-comment
added changes for a_i to ai
2 parents 7f3b980 + 5a08849 commit a2991ff

12 files changed

Lines changed: 698 additions & 213 deletions

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ imagekit_url = imagekit.url({
9999
"path": "/default-image.jpg",
100100
"url_endpoint": "https://ik.imagekit.io/your_imagekit_id/endpoint/",
101101
"transformation": [{
102-
"height": "300",
103-
"width": "400",
102+
"height": "300",
103+
"width": "400",
104104
"raw": "ar-4-3,q-40"
105105
}],
106106
})
@@ -313,10 +313,10 @@ extensions = [
313313
'add_shadow': True,
314314
'bg_color': 'pink'
315315
}
316-
},
316+
},
317317
{
318318
'name': 'google-auto-tagging',
319-
'minConfidence': 80,
319+
'minConfidence': 80,
320320
'maxTags': 10
321321
}
322322
]
@@ -332,7 +332,7 @@ options = UploadFileRequestOptions(
332332
extensions=extensions,
333333
webhook_url='https://webhook.site/c78d617f-33bc-40d9-9e61-608999721e2e',
334334
overwrite_file=True,
335-
overwrite_a_i_tags=False,
335+
overwrite_ai_tags=False,
336336
overwrite_tags=False,
337337
overwrite_custom_metadata=True,
338338
custom_metadata={'testss': 12},
@@ -445,7 +445,7 @@ the [API documentation here](https://docs.imagekit.io/api-reference/media-api/ge
445445

446446
```python
447447
result = imagekit.get_file_version_details(
448-
file_id='file_id',
448+
file_id='file_id',
449449
version_id='version_id'
450450
)
451451

@@ -475,21 +475,21 @@ from imagekitio.models.UpdateFileRequestOptions import UpdateFileRequestOptions
475475

476476
extensions = [
477477
{
478-
'name': 'remove-bg',
478+
'name': 'remove-bg',
479479
'options': {
480480
'add_shadow': True,
481481
'bg_color': 'red'
482482
}
483-
},
483+
},
484484
{
485485
'name': 'google-auto-tagging',
486-
'minConfidence': 80,
486+
'minConfidence': 80,
487487
'maxTags': 10
488488
}
489489
]
490490

491491
options = UpdateFileRequestOptions(
492-
remove_a_i_tags=['remove-ai-tag-1', 'remove-ai-tag-2'],
492+
remove_ai_tags=['remove-ai-tag-1', 'remove-ai-tag-2'],
493493
webhook_url='url',
494494
extensions=extensions,
495495
tags=['tag-1', 'tag-2'],
@@ -556,12 +556,12 @@ print(result.successfully_updated_file_ids[0])
556556

557557
**8. Remove AI tags**
558558

559-
Accepts a list of `file_ids` and `a_i_tags` as a parameter to remove AI tags. All parameters specified in
559+
Accepts a list of `file_ids` and `ai_tags` as a parameter to remove AI tags. All parameters specified in
560560
the [API documentation here](https://docs.imagekit.io/api-reference/media-api/remove-aitags-bulk) can be passed to
561561
the `.remove_ai_tags()` functions to get the results.
562562

563563
```python
564-
result = imagekit.remove_ai_tags(file_ids=['file-id-1', 'file-id-2'], a_i_tags=['remove-ai-tag-1', 'remove-ai-tag-2'])
564+
result = imagekit.remove_ai_tags(file_ids=['file-id-1', 'file-id-2'], ai_tags=['remove-ai-tag-1', 'remove-ai-tag-2'])
565565

566566
# Final Result
567567
print(result)
@@ -1237,7 +1237,7 @@ except UnknownException, e:
12371237

12381238
### Tests
12391239

1240-
Tests are powered by [Tox](https://tox.wiki/en/latest/).
1240+
Tests are powered by [Tox](https://tox.wiki/en/latest/).
12411241

12421242
```bash
12431243
$ git clone https://github.com/imagekit-developer/imagekit-python && cd imagekit-python
@@ -1270,7 +1270,7 @@ imagekit = ImageKit(
12701270
url_endpoint = 'your url_endpoint'
12711271
)
12721272
```
1273-
1273+
12741274
To install dependencies that are in the `python/requirements.txt` file can fire this command to install them:
12751275

12761276
```shell
@@ -1281,13 +1281,13 @@ Now run `python/sample.py`. If you are using CLI Tool (Terminal/Command prompt),
12811281

12821282
```shell
12831283
# if not installed already
1284-
pip install imagekitio
1284+
pip install imagekitio
12851285

12861286
# if installing local sdk
1287-
pip install -e <path_to_local_sdk>
1287+
pip install -e <path_to_local_sdk>
12881288

12891289
# to run sample.py file
1290-
python3 python/sample.py
1290+
python3 python/sample.py
12911291
```
12921292

12931293
## Support

imagekitio/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ def remove_tags(self, file_ids, tags) -> TagsResult:
109109
"""Remove tags by file ids and tags"""
110110
return self.file.manage_tags(file_ids, tags, "removeTags")
111111

112-
def remove_ai_tags(self, file_ids, a_i_tags) -> TagsResult:
112+
def remove_ai_tags(self, file_ids, ai_tags) -> TagsResult:
113113
"""Remove AI tags by file ids and AI tags"""
114-
return self.file.remove_ai_tags(file_ids, a_i_tags)
114+
return self.file.remove_ai_tags(file_ids, ai_tags)
115115

116116
def delete_file(self, file_id: str = None) -> ResponseMetadataResult:
117117
"""Delete file by file_id"""

imagekitio/constants/files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"extensions",
2525
"webhook_url",
2626
"overwrite_file",
27-
"overwrite_a_i_tags",
27+
"overwrite_ai_tags",
2828
"overwrite_tags",
2929
"overwrite_custom_metadata",
3030
"custom_metadata",

imagekitio/file.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,16 @@ def upload(
9595
raise ValueError("Invalid upload options")
9696
if isinstance(file, str) or isinstance(file, bytes):
9797
files.update({"file": (None, file)})
98+
if 'overwriteAiTags' in options:
99+
options['overwriteAITags'] = options['overwriteAiTags']
100+
del options['overwriteAiTags']
98101
all_fields = {**files, **options}
99102
multipart_data = MultipartEncoder(
100103
fields=all_fields, boundary="--randomBoundary---------------------"
101104
)
102105
headers.update({"Content-Type": multipart_data.content_type})
103106
resp = self.request.request(
104-
"Post", url=url, data=multipart_data, headers=headers
107+
"Post", url=url, data=multipart_data.read(), headers=headers
105108
)
106109
if resp.status_code == 200:
107110
response = convert_to_response_object(resp, UploadFileResult)
@@ -115,6 +118,10 @@ def list(self, options: ListAndSearchFileRequestOptions = None) -> ListFileResul
115118
:return: ListFileResult
116119
"""
117120
if options is not None:
121+
if 'tags' in options.__dict__ and isinstance(options.tags, list):
122+
val = ", ".join(options.tags)
123+
if val:
124+
options.tags = val
118125
formatted_options = request_formatter(options.__dict__)
119126
if not self.is_valid_list_options(formatted_options):
120127
raise ValueError("Invalid option for list_files")
@@ -215,8 +222,15 @@ def update_file_details(
215222
url = "{}/v1/files/{}/details/".format(URL.API_BASE_URL, file_id)
216223
headers = {"Content-Type": "application/json"}
217224
headers.update(self.request.get_auth_headers())
225+
formatted_options = request_formatter(options.__dict__)
226+
if 'removeAiTags' in formatted_options:
227+
remove_ai_tags_dict = {'removeAITags': formatted_options['removeAiTags']}
228+
del formatted_options['removeAiTags']
229+
request_data = {**remove_ai_tags_dict, **formatted_options}
230+
else:
231+
request_data = formatted_options
218232
data = (
219-
dumps(request_formatter(options.__dict__))
233+
dumps(request_data)
220234
if options is not None
221235
else dict()
222236
)
@@ -250,15 +264,15 @@ def manage_tags(self, file_ids, tags, action) -> TagsResult:
250264
else:
251265
general_api_throw_exception(resp)
252266

253-
def remove_ai_tags(self, file_ids, a_i_tags) -> TagsResult:
267+
def remove_ai_tags(self, file_ids, ai_tags) -> TagsResult:
254268
"""Remove AI tags of files
255269
:param file_ids: array of file ids
256-
:param a_i_tags: array of AI tags
270+
:param ai_tags: array of AI tags
257271
"""
258272
url = "{}/v1/files/removeAITags".format(URL.API_BASE_URL)
259273
headers = {"Content-Type": "application/json"}
260274
headers.update(self.request.get_auth_headers())
261-
data = dumps({"fileIds": file_ids, "AITags": a_i_tags})
275+
data = dumps({"fileIds": file_ids, "AITags": ai_tags})
262276
resp = self.request.request(method="Post", url=url, headers=headers, data=data)
263277
if resp.status_code == 200:
264278
response = convert_to_response_object(resp, TagsResult)

imagekitio/models/ListAndSearchFileRequestOptions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import array
2+
3+
14
class ListAndSearchFileRequestOptions:
25
def __init__(
36
self,
@@ -8,7 +11,7 @@ def __init__(
811
file_type: str = None,
912
limit: int = None,
1013
skip: int = None,
11-
tags: str = None,
14+
tags=None,
1215
):
1316
if type is not None:
1417
self.type = type

imagekitio/models/UpdateFileRequestOptions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
class UpdateFileRequestOptions:
66
def __init__(
77
self,
8-
remove_a_i_tags: List[str] = None,
8+
remove_ai_tags: List[str] = None,
99
webhook_url: str = None,
1010
extensions: json = None,
1111
tags: List[str] = None,
1212
custom_coordinates: str = None,
1313
custom_metadata: json = None,
1414
):
15-
if remove_a_i_tags is not None:
16-
self.remove_a_i_tags = remove_a_i_tags
15+
if remove_ai_tags is not None:
16+
self.remove_ai_tags = remove_ai_tags
1717
if webhook_url is not None:
1818
self.webhook_url = webhook_url
1919
if extensions is not None:

imagekitio/models/UploadFileRequestOptions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(
1414
extensions: json = None,
1515
webhook_url: str = None,
1616
overwrite_file: bool = None,
17-
overwrite_a_i_tags: bool = None,
17+
overwrite_ai_tags: bool = None,
1818
overwrite_tags: bool = None,
1919
overwrite_custom_metadata: bool = None,
2020
custom_metadata: json = None,
@@ -37,8 +37,8 @@ def __init__(
3737
self.webhook_url = webhook_url
3838
if overwrite_file is not None:
3939
self.overwrite_file = overwrite_file
40-
if overwrite_a_i_tags is not None:
41-
self.overwrite_a_i_tags = overwrite_a_i_tags
40+
if overwrite_ai_tags is not None:
41+
self.overwrite_ai_tags = overwrite_ai_tags
4242
if overwrite_tags is not None:
4343
self.overwrite_tags = overwrite_tags
4444
if overwrite_custom_metadata is not None:

tests/helpers.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import base64
2+
import json
23
import re
34
import unittest
45
from unittest.mock import patch
@@ -32,6 +33,16 @@ def setUp(self, mock_file, mock_req):
3233
skip=0,
3334
tags="Tag-1, Tag-2, Tag-3",
3435
)
36+
self.opt = ListAndSearchFileRequestOptions(
37+
type="file",
38+
sort="ASC_CREATED",
39+
path="/",
40+
search_query="created_at >= '2d' OR size < '2mb' OR format='png'",
41+
file_type="all",
42+
limit=1,
43+
skip=0,
44+
tags=["Tag-1", "Tag-2", "Tag-3"],
45+
)
3546
self.client = ImageKit(
3647
public_key="fake122",
3748
private_key=ClientTestCase.private_key,
@@ -50,11 +61,3 @@ def get_auth_headers_for_test():
5061
(ClientTestCase.private_key + ":").encode()
5162
).decode("utf-8")
5263
return {"Authorization": "Basic {}".format(encoded_private_key)}
53-
54-
55-
def make_string_to_single_line(multiline_string):
56-
return (
57-
re.sub(r"\s(?=\s)", "", re.sub(r"\s", " ", multiline_string))
58-
.replace("{ ", "{")
59-
.replace(" }", "}")
60-
)

0 commit comments

Comments
 (0)