diff --git a/.gitignore b/.gitignore index 86c4ef1..d02bbfb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .idea **/.pytest_cache - +**/__pycache__ *.lock diff --git a/CHANGELOG.md b/CHANGELOG.md index c48956d..15e1d5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v0.0.5 + +## Fixed +- fix api call by support the modern server api ([commit](https://github.com/LNOpenMetrics/py-lnmetrics.api/commit/d3a285334d6a903a0da6fcb816b0664d1942243b)). @vincenzopalazzo 22-02-2023 + + # v0.0.4 ## Added diff --git a/changelog.json b/changelog.json index 0d1845f..734659a 100644 --- a/changelog.json +++ b/changelog.json @@ -1,10 +1,10 @@ { "package_name": "py-lnmetrics.api", - "version": "v0.0.4", + "version": "v0.0.5", "api": { "name": "github", "repository": "LNOpenMetrics/py-lnmetrics.api", - "branch": "main" + "branch": "macros/api" }, "generation_method": { "name": "metadata", diff --git a/lnmetrics_api/lnmetrics_client.py b/lnmetrics_api/lnmetrics_client.py index 9d44017..da66c21 100644 --- a/lnmetrics_api/lnmetrics_client.py +++ b/lnmetrics_api/lnmetrics_client.py @@ -5,6 +5,7 @@ author: https://github.com/vincenzopalazzo """ import logging +from typing import Dict, Optional, Union from gql import gql, Client from gql.transport.aiohttp import AIOHTTPTransport @@ -28,7 +29,7 @@ def __init__( execute_timeout=timeout, ) - def call(self, query, variables: dict = None) -> dict: + def call(self, query, variables: Optional[Dict] = None) -> Dict: """Generic method to make a query to the Graphql Server""" return self.client.execute(query, variable_values=variables) @@ -56,8 +57,17 @@ def get_nodes(self, network: str) -> dict: resp = self.call(query, variables=variables) return LNMetricsClient.__unwrap_error("getNodes", resp) + def cast_to_int_or_none(self, value: Optional[int]) -> Optional[int]: + if value is None: + return value + return int(value) + def get_metric_one( - self, network: str, node_id: str, first: int = None, last: int = None + self, + network: str, + node_id: str, + first: Optional[int] = None, + last: Optional[int] = None, ) -> dict: """Get the metrics collected during the time between [first and last] @@ -69,10 +79,10 @@ def get_metric_one( """ query = gql(GET_METRIC_ONE) variables = { - # "network": network, + "network": network, "node_id": node_id, - "first": int(first), - "last": int(last), + "first": self.cast_to_int_or_none(first), + "last": self.cast_to_int_or_none(last), } resp = self.call(query, variables=variables) return LNMetricsClient.__unwrap_error("metricOne", resp) diff --git a/lnmetrics_api/queries/queries.py b/lnmetrics_api/queries/queries.py index 517ea9e..3e5e2ad 100644 --- a/lnmetrics_api/queries/queries.py +++ b/lnmetrics_api/queries/queries.py @@ -57,8 +57,8 @@ """ GET_METRIC_ONE = """ -query MetricOne($node_id: String!, $first: Int!, $last: Int!){ - metricOne(node_id: $node_id, first: $first, last: $last) { +query MetricOne($network: String!, $node_id: String!, $first: Int!, $last: Int!){ + metricOne(network: $network, node_id: $node_id, first: $first, last: $last) { page_info { start end diff --git a/pyproject.toml b/pyproject.toml index 630e6d5..6b9a986 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "lnmetrics.api" -version = "0.0.3" +version = "0.0.5" description = "Python implementation of the lnmetrics API to query the lnmetrics services" authors = ["Vincenzo Palazzo "] @@ -12,7 +12,7 @@ requests-toolbelt = "^0.9.1" requests = "^2.27.1" [tool.poetry.dev-dependencies] -pytest = "^5.2" +pytest = "^7.2.1" black = "^22.1.0" typed-ast = "^1.5.2"