From 5638b087a59d71d8a1cef317bc7bdff403a803ac Mon Sep 17 00:00:00 2001 From: cipres Date: Thu, 9 Jun 2022 15:01:19 +0200 Subject: [PATCH] Add interface for the remote pinning API revbump to 0.8.0a3 --- ipfshttpclient/client/__init__.py | 4 +- ipfshttpclient/client/pinremote.py | 81 ++++++++++++++++++++++++++++++ ipfshttpclient/version.py | 2 +- 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 ipfshttpclient/client/pinremote.py diff --git a/ipfshttpclient/client/__init__.py b/ipfshttpclient/client/__init__.py index ec9e525f..caa8fe5d 100644 --- a/ipfshttpclient/client/__init__.py +++ b/ipfshttpclient/client/__init__.py @@ -36,6 +36,7 @@ from . import name from . import object from . import pin +from . import pinremote from . import pubsub from . import repo #TODO: `from . import stats` @@ -186,6 +187,7 @@ def close(self): # Call this when you're done name = base.SectionProperty(name.Section) object = base.SectionProperty(object.Section) pin = base.SectionProperty(pin.Section) + pinremote = base.SectionProperty(pinremote.Section) pubsub = base.SectionProperty(pubsub.Section) repo = base.SectionProperty(repo.Section) swarm = base.SectionProperty(swarm.Section) @@ -330,4 +332,4 @@ def get_json(self, cid, **kwargs): object Deserialized IPFS JSON object value """ - return self.cat(cid, decoder='json', **kwargs) \ No newline at end of file + return self.cat(cid, decoder='json', **kwargs) diff --git a/ipfshttpclient/client/pinremote.py b/ipfshttpclient/client/pinremote.py new file mode 100644 index 00000000..a69034c9 --- /dev/null +++ b/ipfshttpclient/client/pinremote.py @@ -0,0 +1,81 @@ +from . import base + + +class Section(base.SectionBase): + def service_add(self, service: str, endpoint: str, + key: str, + **kwargs: base.CommonArgs): + args = (service, endpoint, key) + return self._client.request('/pin/remote/service/add', + args, **kwargs) + + @base.returns_single_item(base.ResponseBase) + def service_ls(self, stat: bool = False, **kwargs: base.CommonArgs): + kwargs.setdefault('opts', {'stat': stat}) + + return self._client.request('/pin/remote/service/ls', (), + decoder='json', **kwargs) + + def service_rm(self, service: str, **kwargs: base.CommonArgs): + args = (service,) + return self._client.request('/pin/remote/service/rm', args, **kwargs) + + @base.returns_single_item(base.ResponseBase) + def add(self, service: str, path: base.cid_t, + name: str = None, background = False, + **kwargs: base.CommonArgs): + opts = { + 'service': service, + 'arg': path, + 'background': background + } + if name: + opts['name'] = name + + kwargs.setdefault('opts', opts) + + return self._client.request('/pin/remote/add', (), + decoder='json', **kwargs) + + @base.returns_multiple_items(base.ResponseBase) + def ls(self, service: str, + name: str = None, cid: list = [], + status: list = ['pinned'], + **kwargs: base.CommonArgs): + opts = { + 'service': service, + 'status': status + } + + if len(cid) > 0: + opts['cid'] = cid + + if name: + opts['name'] = name + + kwargs.setdefault('opts', opts) + + return self._client.request('/pin/remote/ls', (), + decoder='json', **kwargs) + + def rm(self, service: str, + name: str = None, cid: list = [], + status: list = ['pinned'], + force: bool = False, + **kwargs: base.CommonArgs): + opts = { + 'service': service, + 'cid': cid, + 'status': status, + 'force': force + } + + if len(cid) > 0: + opts['cid'] = cid + + if name is not None: + opts['name'] = name + + kwargs.setdefault('opts', opts) + + return self._client.request('/pin/remote/rm', (), **kwargs) diff --git a/ipfshttpclient/version.py b/ipfshttpclient/version.py index aa3dcb97..5497ae04 100644 --- a/ipfshttpclient/version.py +++ b/ipfshttpclient/version.py @@ -8,4 +8,4 @@ # `0.4.1` and so on. When IPFS `0.5.0` is released, the first client version # to support it will also be released as `0.5.0`. -__version__ = "0.8.0a2" +__version__ = "0.8.0a3"