PKv:OY.bluejay/__init__.py"""The BlueJay Client A thin client around the BlueJay interface. Currently supports: - SNS - Stdout (via Logging) """ __version__ = "0.1.3" from . import backend, client, event Client = client.Client __all__ = ("Client",) PKv:Oabluejay/client.pyfrom .backend.command import SendEvent from .backend.interface import IBackend from .interface import IEvent class Client: def __init__(self, backend: IBackend): self.backend = backend def send(self, event: IEvent) -> None: event_name = event.event_name message = event.as_dict() self.send_raw(event_name=event_name, message=message) def send_raw(self, event_name: str, message: dict) -> None: self.backend.send(SendEvent(payload=message, event_name=event_name)) PKv:OI c))bluejay/event.pyimport datetime from typing import Dict, List, Union import attr from typing_extensions import TypedDict __all__ = ("AppReceived", "MatchOccurred", "ProductSelected") @attr.s(slots=True) class AppReceived: event_name = "application_received" app_id = attr.ib(type=str) occurred_on = attr.ib(type=datetime.datetime) def as_dict(self) -> dict: return attr.asdict(self) MatchItem = TypedDict( "MatchItem", { "score": Union[None, int], "breakdown": Dict[str, Union[None, int]], "criteria": Dict[str, Dict[str, int]], "product_id": str, "product_name": str, "product_lender_name": str, }, ) @attr.s(slots=True) class MatchOccurred: event_name = "match_occurred" app_id = attr.ib(type=str) occurred_on = attr.ib(type=datetime.datetime) input = attr.ib(type=Dict) matches = attr.ib(type=List[MatchItem]) def as_dict(self) -> dict: return attr.asdict(self) @attr.s(slots=True) class ProductSelected: event_name = "product_selected" app_id = attr.ib(type=str) occurred_on = attr.ib(type=datetime.datetime) product_id = attr.ib(type=str) product_name = attr.ib(type=str) product_lender_name = attr.ib(type=str) def as_dict(self) -> dict: return attr.asdict(self) PKv:Obluejay/interface.pyfrom typing_extensions import Protocol class IEvent(Protocol): event_name = "" # type: str def as_dict(self) -> dict: ... PKv:O]llbluejay/backend/__init__.pyfrom .logging import LoggingBackend from .sns import SNSBackend __all__ = ("LoggingBackend", "SNSBackend") PKv:OV}bluejay/backend/command.pyimport attr @attr.s(slots=True) class SendEvent: payload = attr.ib(type=dict) event_name = attr.ib(type=str) @attr.s(slots=True) class SendResponse: success = attr.ib(type=bool) PKv:O bluejay/backend/encode.pyimport datetime from json import JSONEncoder as BuiltinJSONEncoder from typing import Any from uuid import UUID def datetime_to_rfc3339(dt: datetime.datetime) -> str: # This is actually rfc3339 compliant return dt.isoformat("T") class JSONEncoder(BuiltinJSONEncoder): def default(self, o: Any) -> Any: if isinstance(o, datetime.datetime): return datetime_to_rfc3339(o) elif isinstance(o, UUID): return str(o) else: return super().default(o) PKv:OQbluejay/backend/interface.pyfrom typing import TypeVar from typing_extensions import Protocol from .command import SendEvent, SendResponse T = TypeVar("T") class IBackend(Protocol): def send(self, message: SendEvent) -> SendResponse: ... PKv:O3=bluejay/backend/logging.pyimport logging from .command import SendEvent, SendResponse from .encode import JSONEncoder LOG = logging.getLogger(__name__) class LoggingBackend: def __init__(self, logger=LOG): self.logger = logger def send(self, message: SendEvent) -> SendResponse: self.logger.info( JSONEncoder().encode( {"event": message.event_name, "payload": message.payload} ) ) return SendResponse(success=True) PKv:O4~yybluejay/backend/sns.pyfrom .command import SendEvent, SendResponse from .encode import JSONEncoder class SNSBackend: def __init__(self, client, topic_arn: str): self.client = client self.topic_arn = topic_arn @classmethod def build(cls, topic_arn: str) -> "SNSBackend": try: import boto3 # type: ignore except ImportError: raise NotImplemented("Boto3 is required to use the SNS Backend") client = boto3.client("sns") return cls(client, topic_arn) def send(self, message: SendEvent) -> SendResponse: self.client.publish( TopicArn=self.topic_arn, MessageStructure="json", Subject=message.event_name, Message=JSONEncoder().encode( {"default": JSONEncoder().encode(message.payload)} ), ) return SendResponse(success=True) PKv:O־::.fundingoptions_bluejay-0.1.3.dist-info/LICENSEThe MIT License (MIT) Copyright (c) 2019 Funding Options Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PKv:OPO,fundingoptions_bluejay-0.1.3.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,szd&Y)r$[)T&UrPKv:O;/fundingoptions_bluejay-0.1.3.dist-info/METADATAXms6_Q?HH%N9]vKd\H II@+N߳ R}0I`w.FyK/'ViSMųi2uSژcMVE~mS%}$7MYJNVAliURMjo643 2?'Y}3U9pk~nlةl"*.«l뚺6sZhx1;IOΔˬfɩ<ܶ"y1 ͮJN ^k=b:7e][sr~sqmO~de99$r{D>+Q--#$3Jjeh_!:9mL,|w|ۭvou%BB,JHNVq0(u唽G^ P;No$7BF 2U'qtw7QFVeWͪnK{\*^Vp,B:ka4I˥_'&b wnedMbЕyPf H~K"~Of\b&kF~C†ǬVS6%?Y/?`3|xSLT?%f#{[1L Ūe8  Q0k.K̴ $.B׍P$ˋ˥(< 9Ī k8Yb4VqEɤ3-u"Nn5x E@K){od g[~R. EZ4,+p8Lx P*HW.Q9ߎ8Z$fJrư2<?—$1j[YzQ5Ha"(t` )ͨ#Lɮb#N{Y φO<<3L0 u.UڿTf7:'/֌8OYs]o"疟)()7ا]lf"g9^Q} $MJOԗKKL$ K7sc am 9E!*F Ы(?ޭ/q ӕo"_˝ TL3S Ta'vFwEW6UWt);``UAH#A(Ȁ(Y@A`*cupc1ʟQ~˦ql}`-p Ѐȵ_T=TWA{M]-گٖu2y.7t9lQ}>zM'a^C *Zr\tw㽲OT?y 0k '2)CAVtH70^h0K 9 uj rMN%K,@}pA^@'eUsh0Ę"r'hLd*<, Lg668"kMA",a,!kZNw6Bx ˸$@tzB݇ߪ˂K#İNN71,ߚS,sfU00Ƥ6B7J.sGO èۧJOB*|>>l ;F\;qw3;Xh;fkC{&u^]~f@tSƆ4m j/? Y8qɷ]PIW:y$ }HtQfMH=IA~OCB4B-MMBmd#m?f u`u8TկWog$#dmCnƹiD4\~¡IGWC͹TX?PKv:ONu-fundingoptions_bluejay-0.1.3.dist-info/RECORDɒZ}= T3^( †Ìz#ߟfF!)G ]43vTfO#!]mT,ݮH`jNk$A*y qVؚ- ^o(vT ܤWC=ZRJ@c~TTi'' 7T>i$/ئQtj4{tl.Jم v,ݠSo+ A_ ӭgͭv2Pز&./0Hq=1M]0~*=uڊRJp;F$wyML h֑ԛhǥ}, |fĆDW[z$y &dbcTQW!S6;+{nޚ,+`"y\!ä˔9"4CDS]s ^݋I,-SXq= "Y&966IG=ts _8}g\t=Zah|ރV7$hnp{\'k1ߍl|׊wp.e[/VCepw{m}MYg+̶}AGXLF8 >.2%eĥkdaws,Y2 |PKv:OY.bluejay/__init__.pyPKv:Oabluejay/client.pyPKv:OI c))Lbluejay/event.pyPKv:Obluejay/interface.pyPKv:O]llc bluejay/backend/__init__.pyPKv:OV} bluejay/backend/command.pyPKv:O  bluejay/backend/encode.pyPKv:OQ> bluejay/backend/interface.pyPKv:O3=[bluejay/backend/logging.pyPKv:O4~yymbluejay/backend/sns.pyPKv:O־::.fundingoptions_bluejay-0.1.3.dist-info/LICENSEPKv:OPO,fundingoptions_bluejay-0.1.3.dist-info/WHEELPKv:O;/:fundingoptions_bluejay-0.1.3.dist-info/METADATAPKv:ONu-"fundingoptions_bluejay-0.1.3.dist-info/RECORDPK$