-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat(lookup): Add Zucchetti Infinity API in lookup sample scripts #374
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few changes should be required.
token_response = requests.post(token_url, auth=auth, data=token_body) | ||
if token_response.status_code != 200: | ||
raise Exception('Failed to get token from ' + token_url + ' with status code ' + str(token_response.status_code)) | ||
token = token_response.json()['access_token'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is duplicated: already done on next line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if 'company' in contact and contact['company'] != '': | ||
result["company"] = contact['company'] | ||
if 'name' in contact and contact["name"] != '': | ||
names.add(contact["name"]) | ||
if len(names) == 1: | ||
result["name"] = names.pop() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is can be greatly simplified:
result["company"] = contact.get("company", "")
result["name"] = contact.get("name", "")
Since names.pop() returns a random element, it does not make sense at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result["company"] = contact.get("company", "") is not the same because i don't wan't to overwrite a possible good result with an empty string
pop returns the only element (if len(names) == 1) if there are more than one is good that it remains empty because is the case that number have more contacts with different names, like if there is "Giacomo" and "Stefano" both with company "Nethesis" and same number, it returns {"company":"Nethesis" , "name":""}
NethServer/dev#7287