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

New library design #53

Merged
merged 16 commits into from
Sep 3, 2021
Merged

New library design #53

merged 16 commits into from
Sep 3, 2021

Conversation

chadell
Copy link
Collaborator

@chadell chadell commented Aug 28, 2021

TODO

  • Simplify data to only one class with several conversion methods
  • Take into account that an email can contain multiple notifications (no only Ical), due to multiple payloads
  • Check for DRY
  • Add init data for Gmail API -> NO NEEDED, we can leverage on Gmail API message directly as it requires multiple calls to dowload attachements, etc., and the parsed don't handle connections, so what we will do is to use the raw option to download the message as a regular email an RFC 2822
  • Refactor testing
  • Document changes in changelog and readme

The main idea behind this refactor is to make the library more "autonomous" to get all the information that it needs to create notifications. The main change is that, before, a notifications was parsed only by ONE parser each time, now we could combine multiple parsers to get all the information needed.

The workflow would look like:

  1. Init the Provider (if no provider type, a standard Icalendar one is offered by default).
from circuit_maintenance_parser import init_provider
ntt_provider = init_provider("ntt")
  1. Init the Data to be parsed
raw_data = b"""BEGIN:VCALENDAR
VERSION:2.0
...
END:VCALENDAR
"""
from circuit_maintenance_parser import init_data_raw

data_to_process =init_data_raw("ical", raw_data)

In this case we are using the simples init, but an init_from_email could be used to call the library using a standard Email representation. This way, the library is not closely tangled with a specific data source, and can be reused in multiple use cases, but at the same time offers all the data structure processing, so the library user don't need to take care of.

  1. Process the Data using the Provider processor (that is composed by multiple combined parsers)
parsed_notifications = ntt_provider.process_notifications(data_to_process)

print(parsed_notifications[0].to_json())
{
  "account": "137.035999173",
  "circuits": [
    {
      "circuit_id": "acme-widgets-as-a-service",
      "impact": "NO-IMPACT"
    },
...
}

@chadell chadell force-pushed the new-design branch 2 times, most recently from 98aa452 to c7a4cf5 Compare August 30, 2021 17:21
circuit_maintenance_parser/__init__.py Show resolved Hide resolved
circuit_maintenance_parser/data.py Outdated Show resolved Hide resolved


class NotificationData(BaseModel, extra=Extra.forbid):
"""Base class for Notificaiton Data types."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this docstring please be detailed a bit more? Maybe with examples of what is meant by "notification data", how this can store one or several DataParts, etc.?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure, this PR is not finished (documentation, tests, etc.). I will take this into account after the initial review of the design

circuit_maintenance_parser/data.py Outdated Show resolved Hide resolved
circuit_maintenance_parser/data.py Outdated Show resolved Hide resolved
circuit_maintenance_parser/processor.py Outdated Show resolved Hide resolved
circuit_maintenance_parser/processor.py Outdated Show resolved Hide resolved
circuit_maintenance_parser/processor.py Outdated Show resolved Hide resolved
circuit_maintenance_parser/processor.py Outdated Show resolved Hide resolved
circuit_maintenance_parser/provider.py Outdated Show resolved Hide resolved
try:
maintenances_data.append(Maintenance(**self.combined_maintenance_data))
except ValidationError as exc:
raise ProviderError("Not enough information available to create a Maintenance notification.") from exc
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I suggested ProviderError in a previous review comment, but actually, should this be ProcessorError now?

README.md Show resolved Hide resolved
circuit_maintenance_parser/data.py Outdated Show resolved Hide resolved
tests/unit/test_processors.py Outdated Show resolved Hide resolved
@chadell chadell changed the title [WIP] New library design New library design Sep 1, 2021
@chadell chadell marked this pull request as ready for review September 1, 2021 16:11
circuit_maintenance_parser/parser.py Show resolved Hide resolved
@@ -74,52 +52,45 @@ class ICal(Parser):
Reference: https://tools.ietf.org/html/draft-gunter-calext-maintenance-notifications-00
"""

_data_type = "text/calendar"
_data_types = ["text/calendar", "ical", "icalendar"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps I missed it, but is it documented what each element of _data_types represents?

@@ -152,35 +120,29 @@ def process(self) -> Iterable[Maintenance]:
class Html(Parser):
"""Html parser."""

_data_type = "text/html"
_data_types = ["text/html", "html"]
Copy link
Contributor

Choose a reason for hiding this comment

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

is it documented what each element of _data_types represents?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They are just arbitrary data types that you expect to match... so following your point, we could either document it or maybe create some ENUM that could help understanding them

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. I'm sure documenting would suffice. No need to change type.

glennmatthews
glennmatthews previously approved these changes Sep 2, 2021
Copy link
Contributor

@glennmatthews glennmatthews left a comment

Choose a reason for hiding this comment

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

Honestly it's a bit hard to follow with all the refactoring and reorganization of code but I think this appears reasonable. Let's get it merged so that we can start actually trying out some new parsers with the combined data.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
pke11y
pke11y previously approved these changes Sep 2, 2021
@chadell chadell dismissed stale reviews from pke11y and glennmatthews via 2303ade September 3, 2021 05:01
@chadell chadell merged commit 2e6b623 into develop Sep 3, 2021
@chadell chadell deleted the new-design branch September 3, 2021 06:32
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