-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update provider discovery to fix binaries
- Loading branch information
1 parent
ecc6308
commit eb52308
Showing
16 changed files
with
91 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import colorlog | ||
from balance_check import config | ||
from balance_check.utils.logging import configure_logger | ||
from typing import Mapping | ||
from balance_check.version import __version__ | ||
|
||
logger = colorlog.getLogger() | ||
configure_logger(logger) | ||
|
||
from balance_check.provider import BalanceCheckProvider | ||
from balance_check.providers import * | ||
|
||
# Instantiate each provider module and populate the available providers | ||
providers: Mapping[str, BalanceCheckProvider] = { | ||
cls.__name__.lower(): cls() for cls in BalanceCheckProvider.__subclasses__() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from cerberus import Validator | ||
from balance_check import logger | ||
|
||
|
||
class BalanceCheckProvider: | ||
def __init__(self): | ||
self.schema = None | ||
|
||
def validate(self, args): | ||
if self.schema: | ||
validator = Validator(self.schema) | ||
if not validator.validate(args): | ||
msg = "Invalid card data provided:\n" | ||
|
||
for field, errors in validator.errors.items(): | ||
msg += "- {}:".format(field) | ||
|
||
if len(errors) == 1: | ||
msg += " {}\n".format(errors[0]) | ||
elif len(errors) > 1: | ||
msg += "\n" | ||
for error in errors: | ||
msg += " - {}\n".format(error) | ||
|
||
logger.error(msg) | ||
return False | ||
|
||
return True | ||
|
||
def check_balance(self, **kwargs): | ||
raise NotImplementedError("Implement in subclass") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,12 @@ | ||
import os | ||
from pkgutil import iter_modules | ||
from importlib import import_module | ||
from typing import Mapping | ||
from cerberus import Validator | ||
from balance_check import logger | ||
|
||
|
||
class BalanceCheckProvider: | ||
def __init__(self): | ||
self.schema = None | ||
|
||
def validate(self, args): | ||
if self.schema: | ||
validator = Validator(self.schema) | ||
if not validator.validate(args): | ||
msg = "Invalid card data provided:\n" | ||
|
||
for field, errors in validator.errors.items(): | ||
msg += "- {}:".format(field) | ||
|
||
if len(errors) == 1: | ||
msg += " {}\n".format(errors[0]) | ||
elif len(errors) > 1: | ||
msg += "\n" | ||
for error in errors: | ||
msg += " - {}\n".format(error) | ||
|
||
logger.error(msg) | ||
return False | ||
|
||
return True | ||
|
||
def check_balance(self, **kwargs): | ||
raise NotImplementedError("Implement in subclass") | ||
|
||
|
||
# Import all provider modules | ||
for _, name, _ in iter_modules([os.path.dirname(__file__)]): | ||
import_module("." + name, __package__) | ||
|
||
# Instantiate each provider module and populate the available providers | ||
providers: Mapping[str, BalanceCheckProvider] = { | ||
cls.__name__.lower(): cls() for cls in BalanceCheckProvider.__subclasses__() | ||
} | ||
__all__ = [ | ||
"bestbuy", | ||
"blackhawk", | ||
"gamestop", | ||
"guitarcenter", | ||
"happy", | ||
"homedepot", | ||
"nike", | ||
"onevanilla", | ||
"prepaidgiftbalance", | ||
"spafinder", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters