This repository was archived by the owner on Jun 11, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11atomx api README
22================
33
4- This module let's you easlily
4+ Simple interface for the atomx rest api.
5+
6+ Example Usage:
7+ --------------
8+
9+ .. code-block :: python
10+
11+ from atomx import Atomx
12+
13+ api = Atomx(' daniel@atomx.com' , ' password' )
14+ creatives = api.get(' Creatives' , limit = 10 )
15+
16+ for creative in creatives:
17+ print (' Creative ID: {c.id} , state: {c.state} ,'
18+ ' name: {c.name} , title: {c.title} ' .format(c = creative))
19+
20+ creative = creatives[0 ]
21+ creative.title = ' shiny new title'
22+ creative.save()
523
624
725 Installation
Original file line number Diff line number Diff line change 33import requests
44from .version import API_VERSION , VERSION
55from . import models
6+ from .utils import get_model_name
67from .exceptions import (
78 APIError ,
89 ModelNotFoundError ,
@@ -48,7 +49,8 @@ def search(self, query):
4849 return r .json ()['search' ]
4950
5051 def get (self , model , ** kwargs ):
51- if model not in dir (models ):
52+ model = get_model_name (model )
53+ if not model :
5254 raise ModelNotFoundError ()
5355 r = self .session .get (self .api_endpoint + model , params = kwargs )
5456 if not r .ok :
Original file line number Diff line number Diff line change 1+ from . import models
2+
3+ def get_model_name (name ):
4+ """Checks that :param:`name` is a valid model.
5+ Converts plural `name` to capitalized singular form and '-' or '_' separation to camelCase.
6+ Returns the name of the model if found, False otherwise.
7+ E.g.
8+
9+ >>> check_model_name("countries")
10+ "Country"
11+ >>> check_model_name("ADVERTISERS")
12+ "Advertiser"
13+ >>> check_model_name("conversion-pixels")
14+ "ConversionPixel"
15+ >>> check_model_name("operating_system")
16+ "OperatingSystem"
17+ >>> check_model_name("InvalidModel")
18+ False
19+
20+ :param str name: model name to convert
21+ :return: name of the model or False
22+ """
23+ if '-' in name :
24+ model_name = '' .join (m .capitalize () for m in name .split ('-' ))
25+ elif '_' in name :
26+ model_name = '' .join (m .capitalize () for m in name .split ('_' ))
27+ else :
28+ model_name = name .capitalize ()
29+
30+ if model_name .endswith ('ies' ): # change e.g. Countries to Countr*y*
31+ model_name = model_name [:- 3 ]+ 'y'
32+ else :
33+ model_name = model_name .rstrip ('s' )
34+ if model_name in dir (models ):
35+ return model_name
36+ return False
You can’t perform that action at this time.
0 commit comments