• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-cli / 6508017815

13 Oct 2023 12:09PM UTC coverage: 83.849% (-0.4%) from 84.269%
6508017815

Pull #277

github

web-flow
Merge f49030687 into 688bc1673
Pull Request #277: Remove relaying

867 of 1034 relevant lines covered (83.85%)

3.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/safe_cli/api/base_api.py
1
from abc import ABC
4✔
2
from typing import Dict, Optional
4✔
3
from urllib.parse import urljoin
4✔
4

5
import requests
4✔
6

7
from gnosis.eth.ethereum_client import EthereumClient, EthereumNetwork
4✔
8

9

10
class BaseAPIException(Exception):
4✔
11
    pass
4✔
12

13

14
class BaseAPI(ABC):
4✔
15
    URL_BY_NETWORK: Dict[EthereumNetwork, str] = {}
4✔
16

17
    def __init__(self, ethereum_client: EthereumClient, network: EthereumNetwork):
4✔
18
        self.ethereum_client = ethereum_client
4✔
19
        self.network = network
4✔
20
        self.base_url = self.URL_BY_NETWORK[network]
4✔
21

22
    @classmethod
4✔
23
    def from_ethereum_client(
4✔
24
        cls, ethereum_client: EthereumClient
4✔
25
    ) -> Optional["BaseAPI"]:
4✔
26
        ethereum_network = ethereum_client.get_network()
4✔
27
        if ethereum_network in cls.URL_BY_NETWORK:
4✔
28
            return cls(ethereum_client, ethereum_network)
4✔
29

30
    def _get_request(self, url: str) -> requests.Response:
4✔
31
        full_url = urljoin(self.base_url, url)
4✔
32
        return requests.get(full_url)
4✔
33

34
    def _post_request(self, url: str, payload: Dict) -> requests.Response:
4✔
35
        full_url = urljoin(self.base_url, url)
36
        return requests.post(
37
            full_url, json=payload, headers={"Content-type": "application/json"}
38
        )
39

40
    def _delete_request(self, url: str, payload: Dict) -> requests.Response:
4✔
41
        full_url = urljoin(self.base_url, url)
42
        return requests.delete(
43
            full_url, json=payload, headers={"Content-type": "application/json"}
44
        )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc