Skip to content

Commit a01be34

Browse files
Merge pull request #10 from contentstack/v1.1.0
V1.1.0
2 parents 5c60d6c + c1c90e5 commit a01be34

16 files changed

+244
-185
lines changed

.github/workflows/pythonpackage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: Python package
55

66
on:
77
push:
8-
branches: [ master, 1.0.0 ]
8+
branches: [ master, v1.1.0 ]
99
pull_request:
10-
branches: [ master, 1.0.0 ]
10+
branches: [ master, v1.1.0 ]
1111

1212
jobs:
1313
build:

CHANGELOG.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# CHANGELOG
2+
3+
Date: 10-Aug-2020 - include_reference issue fixed
4+
5+
## _v1.1.0_
6+
7+
EntryQueryable
8+
9+
- updated include_reference function.
10+
11+
-----------------------------
12+
13+
Date: 17-Jun-2020 - initial release
14+
15+
## _v1.0.0_
16+
17+
Stack
18+
19+
- Initialisation of stack has been modified
20+
- External config support moved to stack initialisation optional paramters
21+
- Added support for whereIn(String key) and whereNotIn(String key) methods in Query
22+
23+
Assets
24+
25+
- Changes incorporated in Asset class.
26+
27+
Entry
28+
29+
- Changes incorporated in the entry class.
30+
31+
Query
32+
33+
- Changes incorporated in the Query class.
34+
35+
-----------------------------
36+
37+
Date: 18-Nov-2019 - beta release
38+
39+
## _v0.1.0_
40+
41+
November-18, 2019 -beta release
42+
43+
Initial release for the contentstack-python-sdk for Content Delivery API
44+
45+
-----------------------------

CHANGELOGS.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

INSTALL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ To install the package simply run the below command on your terminal:
44
python setup.py install
55

66
Don't forget to file bugs and let me know about them.
7-
Also, don't hasitate to ask for new features. Happy coding.
7+
Also, don't hesitate to ask for new features. Happy coding.

changelog.rst

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,38 @@
22
CHANGELOG
33
=========
44

5-
*Date: 17-Jun-2020 - initial release*
5+
Date: 10-Aug-2020 - include_reference issue fixed
66

7-
**v1.0.0**
7+
*v1.1.0*
88
============
99

10-
- **Stack**
11-
- Initialisation of stack has been modified
12-
- External config support moved to stack initialisation optional paramters
13-
- Added support for whereIn(String key) and whereNotIn(String key) methods in Query
10+
EntryQueryable
11+
- updated include_reference function.
1412

15-
- **Asset**
13+
============
14+
15+
Date: 17-Jun-2020 - initial release
16+
17+
*v1.0.0*
18+
============
19+
20+
Stack
21+
- Initialization of the stack has been modified
22+
- External config support moved to stack initialization optional parameters
23+
24+
Asset
1625
- changes incorporated in Asset class.
1726

18-
- **Entry**
27+
Entry
1928
- changes incorporated in the entry class.
2029

21-
- **Query**
30+
Query
2231
- Changes incorporated in the Query class.
2332

24-
2533
-----------------------------
2634

27-
*Date: 18-Nov-2019 - beta release*
35+
Date: 18-Nov-2019 - beta release
2836

29-
**v0.0.1**
37+
*v0.0.1*
3038
============
3139
- Beta release for the contentstack-python SDK for Content Delivery API

contentstack/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
"""
2+
The __init__.py files are required to make Python treat the directories as containing
3+
packages; this is done to prevent directories with a common name, such as string,
4+
from unintentionally hiding valid modules that occur later on the module search path
5+
6+
Used: Safety checks your installed dependencies for known security vulnerabilities
7+
file __init__.py contains package information like
8+
__author__, __status__, __version__, __endpoint__ and __email__
9+
10+
"""
111
from .entry import Entry
212
from .asset import Asset
313
from .contenttype import ContentType
@@ -6,8 +16,9 @@
616
from .utility import Utils
717
# from contentstack import *
818

19+
__title__ = 'contentstack-python'
920
__author__ = 'Contentstack'
1021
__status__ = 'debug'
11-
__version__ = '1.0.0'
22+
__version__ = '1.1.0'
1223
__endpoint__ = 'cdn.contentstack.io'
13-
__email__ = 'mshaileshr@gmail.com'
24+
__email__ = 'shailesh.mishra@contentstack.com'

contentstack/contenttype.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# Your code has been rated at 10.00/10 by pylint
1010

1111
from urllib import parse
12+
1213
from contentstack.entry import Entry
1314
from contentstack.query import Query
1415

@@ -44,7 +45,7 @@ def entry(self, entry_uid: str):
4445
"""
4546
if self.__content_type_uid is None:
4647
raise PermissionError('Please provide valid content_type_uid')
47-
elif entry_uid is None:
48+
if entry_uid is None:
4849
raise PermissionError('Please provide valid entry uid')
4950
entry = Entry(self.http_instance, self.__content_type_uid, entry_uid=entry_uid)
5051
return entry

contentstack/entryqueryable.py

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
1-
import enum
2-
3-
4-
class Include(enum.Enum):
5-
"""
6-
Include is enum that Provides Options to perform operation to query the result.
7-
8-
Available Options for QueryOperation are below.
9-
DEFAULT, ONLY, EXCEPT
10-
11-
Arguments:
12-
enum {Include} -- Type of IncludeReference
13-
"""
14-
EXCEPT = 'except'
15-
ONLY = 'only'
16-
DEFAULT = ''
1+
"""
2+
EntryQueryable class contains common functions
3+
that is used as parents class for the query and entry classes
4+
"""
175

186

197
class EntryQueryable:
208
"""
219
This class is base class for the Entry and Query class that shares common functions
2210
"""
11+
2312
def __init__(self):
2413
self.entry_queryable_param = {}
2514

@@ -53,7 +42,7 @@ def locale(self, locale: str):
5342
self.entry_queryable_param['locale'] = locale
5443
return self
5544

56-
def only(self, field_uid):
45+
def only(self, field_uid: str):
5746
"""
5847
Specifies an array of only keys in BASE object that would be included in the response.
5948
It refers to the top-level fields of the schema
@@ -62,57 +51,61 @@ def only(self, field_uid):
6251
self -- so you can chain this call.
6352
"""
6453
if field_uid is not None:
65-
self.entry_queryable_param['only[BASE][]'] = field_uid
66-
return self
54+
if isinstance(field_uid, str):
55+
self.entry_queryable_param['only[BASE][]'] = field_uid
56+
else:
57+
raise KeyError("Invalid field_uid provided")
58+
return self
6759

68-
def excepts(self, field_uid):
60+
def excepts(self, field_uid: str):
6961
"""
7062
Specifies list of field_uid that would be excluded from the response.
7163
It refers to the top-level fields of the schema
7264
:param field_uid: to be excluded from the response.
7365
:return: self -- so you can chain this call.
7466
"""
7567
if field_uid is not None:
76-
self.entry_queryable_param['except[BASE][]'] = field_uid
77-
return self
68+
if isinstance(field_uid, str):
69+
self.entry_queryable_param['except[BASE][]'] = field_uid
70+
else:
71+
raise KeyError("Invalid field_uid provided")
72+
return self
7873

79-
def include_reference(self, include_reference_type: Include, reference_field_uid: str, field_uid=None):
74+
def include_reference(self, field_uid):
8075
"""
8176
**Include Reference:**
8277
When you fetch an entry of a content type that has a reference field,
8378
by default, the content of the referred entry is not fetched.
8479
It only fetches the UID of the referred entry, along with the content of
8580
the specified entry.
8681
82+
Note: The maximum reference depth limit to which a multiple content type
83+
referencing Reference field works is three levels deep
84+
8785
Arguments:
88-
reference_field_uid {str} -- Key who has reference to some other class object.
8986
Array of the only reference keys to be included in response
90-
include_type {Include} -- Provides three options, none, only and except
91-
i.e accepts list of field_uid
92-
field_uid {list} -- list of field_uid on which include operation to perform
87+
field_uid {str or list of str} -- [str/list of str] of field_uid on
88+
which include operation to perform
9389
9490
Returns:
9591
self -- So you can chain this call.
92+
93+
>>> import contentstack
94+
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
95+
>>> entry = stack.content_type('content_type')
96+
>>> entry("entry_uid").include_reference(["categories", "brand"])
97+
>>> result = entry.fetch()
9698
"""
97-
container = {}
98-
if reference_field_uid is None:
99-
raise KeyError("reference_field_uid can't be None")
100-
if include_reference_type.name == 'DEFAULT':
101-
self.entry_queryable_param["include[]"] = reference_field_uid
102-
else:
103-
container[reference_field_uid] = field_uid
104-
self.entry_queryable_param["include[]"] = {include_reference_type.value: container}
99+
if field_uid is not None and isinstance(field_uid, (str, list)):
100+
self.entry_queryable_param["include[]"] = field_uid
105101
return self
106102

107103
def include_content_type(self):
108104
"""
109105
This method also includes the ContentType in the entry
110106
:return: self: so you can chain this call.
111-
112107
-------------------------------
113-
114108
[Example: for Entry]
115-
116109
>>> import contentstack
117110
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
118111
>>> content_type = stack.content_type('content_type_uid')

contentstack/https_connection.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
"""
2-
# -*- coding: utf-8 -*-
3-
requests.api
4-
~~~~~~~~~~~~
5-
62
This module implements the Requests API.
73
"""
84

95
# ************* Module https_connection.py **************
106
# Your code has been rated at 10.00/10 by pylint
117

12-
from json import JSONDecodeError
13-
import json
14-
import urllib.parse as urlparse
158
import platform
9+
from json import JSONDecodeError
10+
1611
import requests
1712
from requests.exceptions import Timeout, HTTPError
13+
1814
import contentstack
1915

2016

@@ -36,14 +32,13 @@ def user_agents():
3632
header = {'sdk': dict(name=contentstack.__package__, version=contentstack.__version__),
3733
'os': get_os_platform,
3834
'Content-Type': 'application/json'}
39-
package = "contentstack-python, - {}".format(contentstack.__version__)
35+
package = "contentstack-python/{}".format(contentstack.__version__)
4036
return {'User-Agent': str(header), "X-User-Agent": package}
4137

4238

43-
# R0903: Too few public methods (1/2) (too-few-public-methods)
44-
# "pylint doesn't know what's best" - use your own judgement but as a rule.
45-
class HTTPSConnection:
39+
class HTTPSConnection: # R0903: Too few public methods
4640
"""Make Https Request to fetch the result as per requested url"""
41+
4742
def __init__(self, endpoint, headers):
4843
if None not in (endpoint, headers):
4944
self.payload = None
@@ -59,8 +54,7 @@ def get(self, url):
5954
"""
6055
try:
6156
self.headers.update(user_agents())
62-
response = requests.get(url, verify=True,
63-
timeout=self.default_timeout, headers=self.headers)
57+
response = requests.get(url, verify=True, headers=self.headers)
6458
response.encoding = 'utf-8'
6559
return response.json()
6660
except Timeout:
@@ -75,11 +69,3 @@ def get(self, url):
7569
def update_connection_timeout(self, timeout: int):
7670
"""Facilitate to update timeout for the https request"""
7771
self.default_timeout = timeout
78-
79-
def get_complete_url(self, base_url: str, params:dict):
80-
if 'query' in params:
81-
params["query"] = json.dumps(params["query"])
82-
query = urlparse.urlencode(params)
83-
url = '{}&{}'.format(base_url, query)
84-
return url
85-

0 commit comments

Comments
 (0)