Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed anti-pattern, formating and typo #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions examples/python3/tripletex.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def create_session_token(self):
r = requests.put(f'{self.base_url}/token/session/:create', params=params)
if (r.status_code == 200):
return self.map(r)
else:
print(r.status_code, r.text, r.reason)

raise Exception(r.status_code, r.text, r.reason)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is getting converted in to throwing an exception the exception type it throws should be as accurate as practically possible.
If none of the types here fit then either a new custom exception type should be made by extending Exception or use RuntimeError.

There is a very informative answer on StackOverflow regarding this here


def authenticate(self, session_token):
return HTTPBasicAuth('0', session_token)
Expand Down Expand Up @@ -70,7 +70,7 @@ def get_countries(self, ids='', sorting='', fields=''):
def get_country_by_id(self, country_id, fields=''):
params = {'fields': fields}
r = requests.get(f'{self.base_url}/country/{country_id}', params=params, auth=self.auth)
return self.map(r)
return self.map(r)

# project
def get_projects(self, fields=''):
Expand Down Expand Up @@ -99,15 +99,14 @@ def get_order_line_by_id(self, id, fields=''):

# product
def get_product_by_id(self, id, fields=''):
params = {'fields': fields}
params = {'fields': fields}
r = requests.get(f'{self.base_url}/product/{id}', params=params, auth=self.auth)
return self.map(r)

def create_product(self, payload):
r = requests.post(f'{self.base_url}/product', data=json.dumps(payload), auth=self.auth, headers=self.headers)
r = requests.post(f'{self.base_url}/product', data=json.dumps(payload), auth=self.auth, headers=self.headers)
return self.map(r)



# customer
def create_customer(self, payload):
r = requests.post(f'{self.base_url}/customer', data=json.dumps(payload), auth=self.auth, headers=self.headers)
Expand All @@ -128,7 +127,7 @@ def get_departments(self, fields=''):
params = {'fields': fields}
r = requests.get(f'{self.base_url}/department', params=params, auth=self.auth)
return self.map(r)

def create_department(self, payload):
r = requests.post(f'{self.base_url}/department', data=json.dumps(payload), auth=self.auth, headers=self.headers)
return self.map(r)
Expand All @@ -140,6 +139,6 @@ def get_department_by_id(self, id, fields=''):

# helpers
@staticmethod
def map(responce):
data = json.dumps(responce.json())
return json.loads(data, object_hook=lambda d: SimpleNamespace(**d))
def map(response):
data = json.dumps(response.json())
return json.loads(data, object_hook=lambda d: SimpleNamespace(**d))