-
Notifications
You must be signed in to change notification settings - Fork 36
Mae/business name #90
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import os | ||
|
|
||
| from smartystreets_python_sdk import BasicAuthCredentials, ClientBuilder | ||
| from smartystreets_python_sdk.us_enrichment import BusinessLookup | ||
|
|
||
|
|
||
| def run(): | ||
| auth_id = os.environ['SMARTY_AUTH_ID'] | ||
| auth_token = os.environ['SMARTY_AUTH_TOKEN'] | ||
|
|
||
| credentials = BasicAuthCredentials(auth_id, auth_token) | ||
| client = ClientBuilder(credentials).build_us_enrichment_api_client() | ||
|
|
||
| lookup = BusinessLookup() | ||
| lookup.business_name = "delta air" | ||
| lookup.city = "atlanta" | ||
|
|
||
| try: | ||
| summary_results = client.send_business_lookup(lookup) | ||
| except Exception as err: | ||
| print(err) | ||
| return | ||
|
|
||
| if not summary_results: | ||
| print("No response returned for business name {}".format(lookup.business_name)) | ||
| return | ||
|
|
||
| summary = summary_results[0] | ||
| if not summary.businesses: | ||
| print("Business name {} has no business tenants".format(lookup.business_name)) | ||
| return | ||
|
|
||
| print("Matching businesses for business_name '{}':".format(lookup.business_name)) | ||
| for biz in summary.businesses: | ||
| print(" - {} (ID: {})".format(biz.company_name, biz.business_id)) | ||
|
|
||
| first = summary.businesses[0] | ||
| print("\nFetching details for business: {} (ID: {})".format(first.company_name, first.business_id)) | ||
|
|
||
| try: | ||
| detail_result = client.send_business_detail_lookup(first.business_id) | ||
| except Exception as err: | ||
| print(err) | ||
| return | ||
|
|
||
| if detail_result is None: | ||
| print("\nNo detail result returned") | ||
| return | ||
|
|
||
| print("\nDetail result:") | ||
| print_result(detail_result) | ||
|
|
||
|
|
||
| def print_result(obj): | ||
| for key, value in vars(obj).items(): | ||
| if value is None: | ||
| continue | ||
| if key == 'attributes': | ||
| print_result(value) | ||
| continue | ||
| print("{}: {}".format(key, value)) | ||
| print() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| run() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,8 +107,9 @@ def send_lookup(client: Client, lookup, response_class=Response): | |
| _is_blank(getattr(lookup, 'smartykey', None)) | ||
| and _is_blank(getattr(lookup, 'street', None)) | ||
| and _is_blank(getattr(lookup, 'freeform', None)) | ||
| and _is_blank(getattr(lookup, 'business_name', None)) | ||
| ): | ||
| raise SmartyException("Lookup requires one of 'smartykey', 'street', or 'freeform' to be set") | ||
| raise SmartyException("Lookup requires one of 'smartykey', 'street', 'freeform', or 'business_name' to be set") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you make a change according to my Lookup comment, I would change this too to either be smarty_key or businessName |
||
|
|
||
| request = build_request(lookup) | ||
| raw = _dispatch(client, request, lookup) | ||
|
|
@@ -158,7 +159,7 @@ def _url_components(lookup): | |
|
|
||
| def _address_parameters(lookup): | ||
| params = {} | ||
| for key in ('freeform', 'street', 'city', 'state', 'zipcode', 'features'): | ||
| for key in ('freeform', 'business_name', 'street', 'city', 'state', 'zipcode', 'features'): | ||
| value = getattr(lookup, key, None) | ||
| if value: | ||
| params[key] = value | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,13 +28,14 @@ def add_exclude_attribute(self, attribute): | |
|
|
||
|
|
||
| class Lookup(LookupBase): | ||
| def __init__(self, smartykey=None, dataset=None, dataSubset=None, features=None, freeform=None, street=None, city=None, state=None, zipcode=None): | ||
| def __init__(self, smartykey=None, dataset=None, dataSubset=None, features=None, freeform=None, business_name=None, street=None, city=None, state=None, zipcode=None): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not 100% sure how customers are using the Python SDK, but we should probably move string businessName = null to the end of the constructor, in the case that someone was doing this previously:
In this case, 123 main st was originally the street parameter, but now it is the businessName parameter. It's an edge case, but I would do this instead:
|
||
| super().__init__() | ||
| self.smartykey = smartykey | ||
| self.dataset = dataset | ||
| self.dataSubset = dataSubset | ||
| self.features = features | ||
| self.freeform = freeform | ||
| self.business_name = business_name | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't have to change this because I don't think there's a right answer in this repo, but in this file, two word variables are either camel case case (dataSubset) or lowercase (smartykey). In other lookup files, they do follow snake case. So anyways I just had to point that out. |
||
| self.street = street | ||
| self.city = city | ||
| self.state = state | ||
|
|
||
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.
Need to update the Makefile to include this file