← 输入框|github.com|刷新
Skip to content

feat: add odp rest api manager - #398

Merged
Matjaz Pirnovar (Mat001) merged 9 commits into
masterfrom
mpirnovar/odp_rest_api_manager
Aug 12, 2022
Merged

Matjaz Pirnovar (Mat001) merged 9 commits into
masterfrom
mpirnovar/odp_rest_api_manager

Conversation

@Mat001

Copy link
Copy Markdown
Contributor

Summary

  • Added rest api code for odp. Sending events to ODP platform.
  • added class OdpEvent
  • added a helper function for creating and mocking a fake server response
  • added unit tests
  • fixed typo in enums
  • minor fixes to odp graphql manager tests
  • See acceptance criteria in the ticket below.

Test plan

  • unit tests
  • FSC tests

Issues

Comment thread optimizely/odp/odp_event.py Resolved
Comment thread tests/helpers_for_tests.py Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good so far! I like that you reused the mock response, that's a good idea. Just a couple changes

Comment thread optimizely/odp/odp_event.py Resolved
Comment thread tests/helpers_for_tests.py Resolved

@jaeopt Jae Kim (jaeopt) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. A couple of small changes suggested.

@Mat001

Copy link
Copy Markdown
Contributor Author

Jae Kim (@jaeopt) Andy Leap (@andrewleap-optimizely) I hope exception for invalid URL is handled ok. Request.Exception's class InvalidURL is not comprehensive at all. For example it doesn't catch https://api.zaius..com or XXhttps://api.zaius.com. For cases like these two I had to add other exceptions. If better idea how to guard against an invalid url lmk

I'm not super clear how swift does it, it seems it checks for exactly that url string?
guard let url = URL(string: "\(apiHost)/v3/events") else {
let canRetry = false
completionHandler(.odpEventFailed("Invalid url", canRetry))
return
}

@andrewleap-optimizely

Copy link
Copy Markdown
Contributor

I'm not super clear how swift does it, it seems it checks for exactly that url string? guard let url = URL(string: "\(apiHost)/v3/events") else { let canRetry = false completionHandler(.odpEventFailed("Invalid url", canRetry)) return }

We can accomplish something similar using urllib.parse.urlparse

@jaeopt

Copy link
Copy Markdown
Contributor

Jae Kim (@jaeopt) Andy Leap (@andrewleap-optimizely) I hope exception for invalid URL is handled ok. Request.Exception's class InvalidURL is not comprehensive at all. For example it doesn't catch https://api.zaius..com or XXhttps://api.zaius.com. For cases like these two I had to add other exceptions. If better idea how to guard against an invalid url lmk

I'm not super clear how swift does it, it seems it checks for exactly that url string? guard let url = URL(string: "\(apiHost)/v3/events") else { let canRetry = false completionHandler(.odpEventFailed("Invalid url", canRetry)) return }

Matjaz Pirnovar (@Mat001) I understand that RequestException will catch these all.
I don't think we need this fine level of error handling, since this is not expected to happen (apiHost we control).
Can be cleaned up if needed. Swift checks url only for lang level requirement for optional filtering.

@Mat001

Copy link
Copy Markdown
Contributor Author

Jae Kim (@jaeopt) Andy Leap (@andrewleap-optimizely) ok. I refactored. I got rid of the specific URL parsing exceptions and made it such that generic RequestEception catches invalid URL errors (may not include urlparse errors), but it guard against quite a few. And since we control the URL I wouldn't worry about this one, if that's ok

@jaeopt Jae Kim (jaeopt) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM with a clarification

can_retry = False
# retry on network errors
should_retry = True
except RequestException as err:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think so, but can you confirm that this catches all other exceptions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@Mat001
Matjaz Pirnovar (Mat001) merged commit 998dbc7 into master Aug 12, 2022
@Mat001
Matjaz Pirnovar (Mat001) deleted the mpirnovar/odp_rest_api_manager branch August 12, 2022 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants