Skip to content

Commit

Permalink
Add interface for the remote pinning API
Browse files Browse the repository at this point in the history
revbump to 0.8.0a3
  • Loading branch information
cipres authored and cipres committed Jun 9, 2022
1 parent f04ff60 commit 93dbf12
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ipfshttpclient/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -330,4 +332,4 @@ def get_json(self, cid, **kwargs):
object
Deserialized IPFS JSON object value
"""
return self.cat(cid, decoder='json', **kwargs)
return self.cat(cid, decoder='json', **kwargs)
86 changes: 86 additions & 0 deletions ipfshttpclient/client/pinremote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from . import base


class Section(base.SectionBase):
@base.returns_single_item(base.ResponseBase)
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,
decoder='json', **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)

@base.returns_single_item(base.ResponseBase)
def service_rm(self, service: str, **kwargs: base.CommonArgs):
args = (service,)
return self._client.request('/pin/remote/service/rm', args,
decoder='json', **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)

@base.returns_single_item(base.ResponseBase)
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', (),
decoder='json', **kwargs)
2 changes: 1 addition & 1 deletion ipfshttpclient/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 93dbf12

Please sign in to comment.