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 12, 2022
1 parent f04ff60 commit 5638b08
Show file tree
Hide file tree
Showing 3 changed files with 85 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)
81 changes: 81 additions & 0 deletions ipfshttpclient/client/pinremote.py
Original file line number Diff line number Diff line change
@@ -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)
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 5638b08

Please sign in to comment.