1- import inspect
2- import pkgutil
3- from importlib import import_module
4- from pathlib import Path
5-
61from client .connection import Connection
7- from client .exceptions import ArkParameterException
8- from client .resource import Resource
2+ from client .api .api_nodes import ApiNodes
3+ from client .api .blockchain import Blockchain
4+ from client .api .blocks import Blocks
5+ from client .api .commits import Commits
6+ from client .api .delegates import Delegates
7+ from client .api .node import Node
8+ from client .api .peers import Peers
9+ from client .api .rounds import Rounds
10+ from client .api .transactions import Transactions
11+ from client .api .votes import Votes
12+ from client .api .wallets import Wallets
913
1014class ArkClient (object ):
1115
@@ -16,22 +20,91 @@ def __init__(self, hostname):
1620 on whatever url they want.
1721 """
1822 self .connection = Connection (hostname )
19- self ._import_api ()
2023
21- def _import_api (self ):
24+ @property
25+ def api_nodes (self ):
26+ """
27+ :return: Nodes API
28+ :rtype: client.api.api_nodes.ApiNodes
29+ """
30+ return ApiNodes (self .connection )
31+
32+ @property
33+ def blockchain (self ):
34+ """
35+ :return: Blockchain API
36+ :rtype: client.api.blockchain.Blockchain
37+ """
38+ return Blockchain (self .connection )
39+
40+ @property
41+ def blocks (self ):
42+ """
43+ :return: Blocks API
44+ :rtype: client.api.blocks.Blocks
45+ """
46+ return Blocks (self .connection )
47+
48+ @property
49+ def commits (self ):
50+ """
51+ :return: Commits API
52+ :rtype: client.api.commits.Commits
53+ """
54+ return Commits (self .connection )
55+
56+ @property
57+ def delegates (self ):
58+ """
59+ :return: Delegates API
60+ :rtype: client.api.delegates.Delegates
61+ """
62+ return Delegates (self .connection )
63+
64+ @property
65+ def node (self ):
66+ """
67+ :return: Node API
68+ :rtype: client.api.node.Node
69+ """
70+ return Node (self .connection )
71+
72+ @property
73+ def peers (self ):
2274 """
23- Dynamically imports API endpoints.
75+ :return: Peers API
76+ :rtype: client.api.peers.Peers
2477 """
25- modules = pkgutil .iter_modules ([str (Path (__file__ ).parent / 'api' )])
26- for _ , name , _ in modules :
27- module = import_module ('client.api.{}' .format (name ))
28- for attr in dir (module ):
29- # If attr name is `Resource`, skip it as it's a class and also has a
30- # subclass of Resource
31- if attr == 'Resource' :
32- continue
78+ return Peers (self .connection )
3379
34- attribute = getattr (module , attr )
35- if inspect .isclass (attribute ) and issubclass (attribute , Resource ):
36- # Set module class as a property on the client
37- setattr (self , name , attribute (self .connection ))
80+ @property
81+ def rounds (self ):
82+ """
83+ :return: Rounds API
84+ :rtype: client.api.rounds.Rounds
85+ """
86+ return Rounds (self .connection )
87+
88+ @property
89+ def transactions (self ):
90+ """
91+ :return: Transactions API
92+ :rtype: client.api.transactions.Transactions
93+ """
94+ return Transactions (self .connection )
95+
96+ @property
97+ def votes (self ):
98+ """
99+ :return: Votes API
100+ :rtype: client.api.votes.Votes
101+ """
102+ return Votes (self .connection )
103+
104+ @property
105+ def wallets (self ):
106+ """
107+ :return: Wallets API
108+ :rtype: client.api.wallets.Wallets
109+ """
110+ return Wallets (self .connection )
0 commit comments