Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Commits
be9c65b7
Commit
be9c65b7
authored
6 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
issue
#56
WIP - More clean syntax to call REST wrappers packages
Thanks to python __call__ magic method !
parent
2929764d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
duniterpy/api/client.py
+14
-3
14 additions, 3 deletions
duniterpy/api/client.py
examples/request_data.py
+4
-4
4 additions, 4 deletions
examples/request_data.py
with
18 additions
and
7 deletions
duniterpy/api/client.py
+
14
−
3
View file @
be9c65b7
# Authors:
# Authors:
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
# Inso <insomniak.fr at gmail.com>
# Inso <insomniak.fr at gmail.com>
from
typing
import
Callable
import
json
import
json
import
logging
import
logging
import
aiohttp
import
aiohttp
import
jsonschema
import
jsonschema
from
.errors
import
DuniterError
from
.errors
import
DuniterError
from
duniterpy.api.endpoint
import
endpoint
import
duniterpy.api.endpoint
as
endpoint
logger
=
logging
.
getLogger
(
"
duniter
"
)
logger
=
logging
.
getLogger
(
"
duniter
"
)
...
@@ -180,7 +180,7 @@ class Client:
...
@@ -180,7 +180,7 @@ class Client:
:param proxy: Proxy server as hostname:port
:param proxy: Proxy server as hostname:port
"""
"""
# Endpoint Protocol detection
# Endpoint Protocol detection
self
.
endpoint
=
endpoint
(
_endpoint
)
self
.
endpoint
=
endpoint
.
endpoint
(
_endpoint
)
# if no user session...
# if no user session...
if
session
is
None
:
if
session
is
None
:
...
@@ -219,3 +219,14 @@ class Client:
...
@@ -219,3 +219,14 @@ class Client:
"""
"""
await
self
.
session
.
close
()
await
self
.
session
.
close
()
async
def
__call__
(
self
,
_function
:
Callable
,
*
args
:
any
,
**
kwargs
:
any
)
->
any
:
"""
Call the _function given with the args given
So we can have use many packages wrapping a REST API
:param _function: The function to call
:param args: The parameters
:param kwargs: The key/value parameters
:return:
"""
return
await
_function
(
self
,
*
args
,
**
kwargs
)
This diff is collapsed.
Click to expand it.
examples/request_data.py
+
4
−
4
View file @
be9c65b7
...
@@ -24,19 +24,19 @@ async def main():
...
@@ -24,19 +24,19 @@ async def main():
print
(
response
)
print
(
response
)
# Get the node summary infos by dedicated method (with json schema validation)
# Get the node summary infos by dedicated method (with json schema validation)
response
=
await
bma
.
node
.
summary
(
client
)
response
=
await
client
(
bma
.
node
.
summary
)
print
(
response
)
print
(
response
)
# Get the money parameters located in the first block
# Get the money parameters located in the first block
response
=
await
bma
.
blockchain
.
parameters
(
client
)
response
=
await
client
(
bma
.
blockchain
.
parameters
)
print
(
response
)
print
(
response
)
# Get the current block
# Get the current block
response
=
await
bma
.
blockchain
.
current
(
client
)
response
=
await
client
(
bma
.
blockchain
.
current
)
print
(
response
)
print
(
response
)
# Get the block number 10
# Get the block number 10
response
=
await
bma
.
blockchain
.
block
(
client
,
10
)
response
=
await
client
(
bma
.
blockchain
.
block
,
10
)
print
(
response
)
print
(
response
)
# Close client aiohttp session
# Close client aiohttp session
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment