Skip to content
This repository was archived by the owner on Jun 11, 2024. It is now read-only.

Commit d8c43ca

Browse files
committed
change default api to https
lazy load model attributes
1 parent 62445e3 commit d8c43ca

4 files changed

Lines changed: 25 additions & 2 deletions

File tree

atomx/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
__author__ = 'Spot Media Solutions Sdn. Bhd.'
1717
__copyright__ = 'Copyright 2015 Spot Media Solutions Sdn. Bhd.'
1818

19-
API_ENDPOINT = 'http://api.atomx.com/{}/'.format(API_VERSION)
19+
API_ENDPOINT = 'https://api.atomx.com/{}/'.format(API_VERSION)
2020

2121

2222
class Atomx(object):

atomx/models.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ def __init__(self, session=None, **attributes):
1313
super(AtomxModel, self).__setattr__('_dirty', set()) # list of changed attributes
1414

1515
def __getattr__(self, item):
16+
from .utils import get_attribute_model_name
17+
model_name = get_attribute_model_name(item)
18+
attr = self._attributes.get(item)
19+
# if requested attribute item is a valid model name and and int or
20+
# a list of integers, just delete the attribute so it gets
21+
# fetched from the api
22+
if model_name and (isinstance(attr, int) or
23+
isinstance(attr, list) and len(attr) > 0 and
24+
isinstance(attr[0], int)):
25+
del self._attributes[item]
26+
1627
# if item not in model and session exists,
1728
# try to load model attribute from server if possible
1829
if not item.startswith('_') and item not in self._attributes and self.session:

atomx/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import re
12
from . import models
23

4+
35
def get_model_name(name):
46
"""Checks that :param:`name` is a valid model.
57
Converts plural `name` to capitalized singular form and '-' or '_' separation to camelCase.
@@ -34,3 +36,13 @@ def get_model_name(name):
3436
if model_name in dir(models):
3537
return model_name
3638
return False
39+
40+
41+
def get_attribute_model_name(attribute):
42+
"""Checks if an attribute is a valid model like :func:`get_model_name`
43+
but also strips '_filter', '_include', '_exclude'
44+
45+
:param str attribute: attribute name to convert
46+
:return: name of the model or False
47+
"""
48+
return get_model_name(re.sub('(_filter|_include|_exclude)$', '', attribute))

tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@pytest.fixture(scope="session")
55
def atomx():
66
from .atomx import Atomx
7-
return Atomx('daniel@atomx.com', 'password')
7+
return Atomx('daniel@atomx.com', 'password', 'http://127.0.0.1:6543/v1/')
88

99

1010
def test_limit(atomx):

0 commit comments

Comments
 (0)