Skip to content

Commit

Permalink
Merge pull request #5 from LNOpenMetrics/macros/api
Browse files Browse the repository at this point in the history
api: suppot the modern API
  • Loading branch information
vincenzopalazzo authored Feb 22, 2023
2 parents 2b7195d + de38b8e commit a426acb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.idea
**/.pytest_cache

**/__pycache__
*.lock
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions changelog.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 15 additions & 5 deletions lnmetrics_api/lnmetrics_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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]
Expand All @@ -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)
4 changes: 2 additions & 2 deletions lnmetrics_api/queries/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]

Expand All @@ -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"

Expand Down

0 comments on commit a426acb

Please sign in to comment.