Skip to content
This repository has been archived by the owner on Jul 19, 2020. It is now read-only.

Commit

Permalink
Develop/main (#15)
Browse files Browse the repository at this point in the history
migrate to **v2.1.1**:
* remove `USE_NONE_SAFE_VALUES` env var usage
  • Loading branch information
hell03end authored Jun 24, 2018
1 parent 300d5c5 commit 1295e3a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 23 deletions.
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ Usage
import ruz
schedule = ruz.person_lessons("[email protected]")
Module configuration performs throw setting environment variables:
* `HSE_RUZ_ENABLE_LOGGING` - to enable verbose logging (`@log`)
* `HSE_RUZ_API_URL` - url to RUZ API, possible values (not all endpoints supported for 2, 3):
1. `http://92.242.58.221/ruzservice.svc` - default
2. `http://92.242.58.221/ruzservice.svc/v2`
3. `https://www.hse.ru/api`
* `CHECK_EMAIL_ONLINE` - to enable online email verification (throw API call)


Contributing
------------
Expand Down
2 changes: 1 addition & 1 deletion ruz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
type_of_auditoriums)

__author__ = "Dmitriy Pchelkin | hell03end"
__version__ = (2, 1, 0)
__version__ = (2, 1, 1)
10 changes: 4 additions & 6 deletions ruz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ruz.schema import API_ENDPOINTS, API_URL, REQUEST_SCHEMA

CHECK_EMAIL_ONLINE = bool(os.environ.get("CHECK_EMAIL_ONLINE", False))
USE_NONE_SAFE_VALUES = bool(os.environ.get("USE_NONE_SAFE_VALUES", True))

HSE_EMAIL_REGEX = re.compile(r"^[a-z0-9\._-]{3,}@(edu\.)?hse\.ru$")


Expand Down Expand Up @@ -167,25 +167,23 @@ def make_url(endpoint: str, **params) -> str:
@log
def get(endpoint: str,
encoding: str="utf-8",
return_none_safe: bool=USE_NONE_SAFE_VALUES,
**params) -> (list, dict, None):
"""
Return requested data in JSON
Return requested data in JSON (empty list on fallback)
Check request has correct schema.
:param endpoint - endpoint for request.
:param encoding - encoding for received data.
:param return_none_safe - return empty list on fallback.
:param params - requested params
"""
if not is_valid_schema(endpoint, **params):
return [] if return_none_safe else None
return []

url = make_url(endpoint, **params)
try:
response = request.urlopen(url)
return json.loads(response.read().decode(encoding))
except (error.HTTPError, error.URLError) as err:
logging.debug("Can't get '%s'.\n%s", url, err)
return [] if return_none_safe else None
return []
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
setup(
name="hse_ruz",
packages=packages,
version="2.1.0",
version="2.1.1",
description="Python wrapper for HSE RUZ API",
long_description=open(os.path.join(os.path.dirname(__file__),
"README.rst")).read(),
Expand All @@ -24,8 +24,8 @@
# "Development Status :: 1 - Planning",
# "Development Status :: 2 - Pre-Alpha",
# "Development Status :: 3 - Alpha",
"Development Status :: 4 - Beta",
# "Development Status :: 5 - Production/Stable",
# "Development Status :: 4 - Beta",
"Development Status :: 5 - Production/Stable",
# "Development Status :: 6 - Mature",
# "Development Status :: 7 - Inactive",
"Environment :: Console",
Expand Down
17 changes: 4 additions & 13 deletions tests/test_RUZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,16 @@ def test_is_valid_schema():
def test_get():
for endpoint in API_ENDPOINTS.keys():
if endpoint == "schedule":
none_safe = ruz.utils.get(
response = ruz.utils.get(
endpoint,
email=INTRUSTED_EMAILS['other'],
return_none_safe=True,
check_email_online=False
)
usual = ruz.utils.get(
endpoint,
email=INTRUSTED_EMAILS['other'],
return_none_safe=False,
check_email_online=False
)
else:
none_safe = ruz.utils.get(endpoint, tmp=123, return_none_safe=True)
usual = ruz.utils.get(endpoint, tmp=123, return_none_safe=False)
assert not none_safe
assert isinstance(none_safe, list)
assert not usual
assert usual is None
response = ruz.utils.get(endpoint, tmp=123, return_none_safe=True)
assert not response
assert isinstance(response, list)


def test_schedules():
Expand Down

0 comments on commit 1295e3a

Please sign in to comment.