Skip to content

Commit

Permalink
api_key support for COUNTER 5.
Browse files Browse the repository at this point in the history
fix #96
  • Loading branch information
Wooble committed Nov 5, 2019
1 parent d38c171 commit 343befe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pycounter/sushi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
import time
import uuid

import warnings

from lxml import etree
from lxml import objectify
Expand Down Expand Up @@ -145,6 +145,11 @@ def get_report(*args, **kwargs):
else:
gssr = get_sushi_stats_raw
rtf = raw_to_full
if "api_key" in kwargs:
warnings.warn(
pycounter.exceptions.SushiWarning("api_key only supported in COUNTER 5")
)
kwargs.pop("api_key", None)

no_delay = kwargs.pop("no_delay", False)
delay_amount = 0 if no_delay else 60
Expand Down
6 changes: 6 additions & 0 deletions pycounter/sushi5.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def get_sushi_stats_raw(
sushi_dump=False,
verify=True,
url=None,
api_key=None,
**kwargs
):
"""Get SUSHI stats for a given site in dict (decoded from JSON) format.
Expand All @@ -182,6 +183,9 @@ def get_sushi_stats_raw(
:param url: str: URL to endpoint for this provider
:param api_key: str: API key for SUSHI provider (not used by all vendors; see
vendor instructions to determine if this is needed)
"""
_check_params(kwargs, release)
if url is None and wsdl_url: # pragma: no cover
Expand All @@ -199,6 +203,8 @@ def get_sushi_stats_raw(
"end_date": end_date,
"requestor_id": requestor_id,
}
if api_key:
req_params["api_key"] = api_key

response = requests.get(
"{url}/reports/{report}".format(**url_params),
Expand Down
5 changes: 4 additions & 1 deletion pycounter/sushiclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
@click.option("--requestor_id", "-i", help="Requestor ID")
@click.option("--requestor_email", help="Email address of requestor")
@click.option("--requestor_name", help="Internationally recognized organization name")
@click.option("--customer_reference", "-c", help="Customer reference")
@click.option("--customer_name", help="Internationally recognized organization name")
@click.option("--customer_reference", "-c", help="Customer reference")
@click.option("--api_key", help="API key (COUNTER 5 only)")
@click.option(
"--format",
"-f",
Expand Down Expand Up @@ -66,6 +67,7 @@ def main(
requestor_name,
customer_name,
customer_reference,
api_key,
format_,
output_file,
dump,
Expand Down Expand Up @@ -100,6 +102,7 @@ def main(
sushi_dump=dump,
no_delay=no_delay,
verify=not no_ssl_verify,
api_key=api_key,
)
if "%s" in output_file:
output_file = output_file % format_
Expand Down

0 comments on commit 343befe

Please sign in to comment.