Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #13 from hinshun/export-request
Browse files Browse the repository at this point in the history
Export (*HttpApi).request to enable building custom requests
  • Loading branch information
Stebalien authored Apr 3, 2019
2 parents 880cd01 + 8c9ed7d commit 7f260a2
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (api *HttpApi) WithOptions(opts ...caopts.ApiOption) (iface.CoreAPI, error)
return &subApi, nil
}

func (api *HttpApi) request(command string, args ...string) *RequestBuilder {
func (api *HttpApi) Request(command string, args ...string) *RequestBuilder {
return &RequestBuilder{
command: command,
args: args,
Expand Down
6 changes: 3 additions & 3 deletions apifile.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (api *UnixfsAPI) Get(ctx context.Context, p iface.Path) (files.Node, error)
Type string
Size int64 // unixfs size
}
err := api.core().request("files/stat", p.String()).Exec(ctx, &stat)
err := api.core().Request("files/stat", p.String()).Exec(ctx, &stat)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -59,7 +59,7 @@ func (f *apiFile) reset() error {
_ = f.r.Cancel()
f.r = nil
}
req := f.core.request("cat", f.path.String())
req := f.core.Request("cat", f.path.String())
if f.at != 0 {
req.Option("offset", f.at)
}
Expand Down Expand Up @@ -225,7 +225,7 @@ func (d *apiDir) Entries() files.DirIterator {
}

func (api *UnixfsAPI) getDir(ctx context.Context, p iface.Path, size int64) (files.Node, error) {
resp, err := api.core().request("ls", p.String()).
resp, err := api.core().Request("ls", p.String()).
Option("resolve-size", true).
Option("stream", true).Send(ctx)

Expand Down
8 changes: 4 additions & 4 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (api *BlockAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.BlockP
return nil, fmt.Errorf("unknowm mhType %d", options.MhType)
}

req := api.core().request("block/put").
req := api.core().Request("block/put").
Option("mhtype", mht).
Option("mhlen", options.MhLength).
Option("format", options.Codec).
Expand All @@ -61,7 +61,7 @@ func (api *BlockAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.BlockP
}

func (api *BlockAPI) Get(ctx context.Context, p iface.Path) (io.Reader, error) {
resp, err := api.core().request("block/get", p.String()).Send(ctx)
resp, err := api.core().Request("block/get", p.String()).Send(ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -90,7 +90,7 @@ func (api *BlockAPI) Rm(ctx context.Context, p iface.Path, opts ...caopts.BlockR
Error string `json:",omitempty"`
}{}

req := api.core().request("block/rm").
req := api.core().Request("block/rm").
Option("force", options.Force).
Arguments(p.String())

Expand All @@ -107,7 +107,7 @@ func (api *BlockAPI) Rm(ctx context.Context, p iface.Path, opts ...caopts.BlockR

func (api *BlockAPI) Stat(ctx context.Context, p iface.Path) (iface.BlockStat, error) {
var out blockStat
err := api.core().request("block/stat", p.String()).Exec(ctx, &out)
err := api.core().Request("block/stat", p.String()).Exec(ctx, &out)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (api *DhtAPI) FindPeer(ctx context.Context, p peer.ID) (peerstore.PeerInfo,
Type notif.QueryEventType
Responses []peerstore.PeerInfo
}
resp, err := api.core().request("dht/findpeer", p.Pretty()).Send(ctx)
resp, err := api.core().Request("dht/findpeer", p.Pretty()).Send(ctx)
if err != nil {
return peerstore.PeerInfo{}, err
}
Expand Down Expand Up @@ -48,7 +48,7 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caop
return nil, err
}

resp, err := api.core().request("dht/findprovs", rp.Cid().String()).
resp, err := api.core().Request("dht/findprovs", rp.Cid().String()).
Option("num-providers", options.NumProviders).
Send(ctx)
if err != nil {
Expand Down Expand Up @@ -104,7 +104,7 @@ func (api *DhtAPI) Provide(ctx context.Context, p iface.Path, opts ...caopts.Dht
return err
}

return api.core().request("dht/provide", rp.Cid().String()).
return api.core().Request("dht/provide", rp.Cid().String()).
Option("recursive", options.Recursive).
Exec(ctx, nil)
}
Expand Down
10 changes: 5 additions & 5 deletions key.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (api *KeyAPI) Generate(ctx context.Context, name string, opts ...caopts.Key
}

var out keyOutput
err = api.core().request("key/gen", name).
err = api.core().Request("key/gen", name).
Option("type", options.Algorithm).
Option("size", options.Size).
Exec(ctx, &out)
Expand All @@ -61,7 +61,7 @@ func (api *KeyAPI) Rename(ctx context.Context, oldName string, newName string, o
Id string
Overwrite bool
}
err = api.core().request("key/rename", oldName, newName).
err = api.core().Request("key/rename", oldName, newName).
Option("force", options.Force).
Exec(ctx, &out)
if err != nil {
Expand All @@ -75,7 +75,7 @@ func (api *KeyAPI) Rename(ctx context.Context, oldName string, newName string, o

func (api *KeyAPI) List(ctx context.Context) ([]iface.Key, error) {
var out struct{ Keys []*keyOutput }
if err := api.core().request("key/list").Exec(ctx, &out); err != nil {
if err := api.core().Request("key/list").Exec(ctx, &out); err != nil {
return nil, err
}

Expand All @@ -94,7 +94,7 @@ func (api *KeyAPI) List(ctx context.Context) ([]iface.Key, error) {

func (api *KeyAPI) Self(ctx context.Context) (iface.Key, error) {
var id struct{ ID string }
if err := api.core().request("id").Exec(ctx, &id); err != nil {
if err := api.core().Request("id").Exec(ctx, &id); err != nil {
return nil, err
}

Expand All @@ -106,7 +106,7 @@ func (api *KeyAPI) Self(ctx context.Context) (iface.Key, error) {

func (api *KeyAPI) Remove(ctx context.Context, name string) (iface.Key, error) {
var out struct{ Keys []keyOutput }
if err := api.core().request("key/rm", name).Exec(ctx, &out); err != nil {
if err := api.core().Request("key/rm", name).Exec(ctx, &out); err != nil {
return nil, err
}
if len(out.Keys) != 1 {
Expand Down
6 changes: 3 additions & 3 deletions name.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (api *NameAPI) Publish(ctx context.Context, p iface.Path, opts ...caopts.Na
return nil, err
}

req := api.core().request("name/publish", p.String()).
req := api.core().Request("name/publish", p.String()).
Option("key", options.Key).
Option("allow-offline", options.AllowOffline).
Option("lifetime", options.ValidTime).
Expand Down Expand Up @@ -63,7 +63,7 @@ func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.Name
return nil, fmt.Errorf("Name.Resolve: depth other than 1 or %d not supported", nsopts.DefaultDepthLimit)
}

req := api.core().request("name/resolve", name).
req := api.core().Request("name/resolve", name).
Option("nocache", !options.Cache).
Option("recursive", ropts.Depth != 1).
Option("dht-record-count", ropts.DhtRecordCount).
Expand Down Expand Up @@ -120,7 +120,7 @@ func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.Nam
return nil, fmt.Errorf("Name.Resolve: depth other than 1 or %d not supported", nsopts.DefaultDepthLimit)
}

req := api.core().request("name/resolve", name).
req := api.core().Request("name/resolve", name).
Option("nocache", !options.Cache).
Option("recursive", ropts.Depth != 1).
Option("dht-record-count", ropts.DhtRecordCount).
Expand Down
18 changes: 9 additions & 9 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (api *ObjectAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.Objec
}

var out objectOut
err = api.core().request("object/put").
err = api.core().Request("object/put").
Option("inputenc", options.InputEnc).
Option("datafieldenc", options.DataType).
Option("pin", options.Pin).
Expand Down Expand Up @@ -80,7 +80,7 @@ func (api *ObjectAPI) Get(ctx context.Context, p iface.Path) (ipld.Node, error)
}

func (api *ObjectAPI) Data(ctx context.Context, p iface.Path) (io.Reader, error) {
resp, err := api.core().request("object/data", p.String()).Send(ctx)
resp, err := api.core().Request("object/data", p.String()).Send(ctx)
if err != nil {
return nil, err
}
Expand All @@ -106,7 +106,7 @@ func (api *ObjectAPI) Links(ctx context.Context, p iface.Path) ([]*ipld.Link, er
Size uint64
}
}
if err := api.core().request("object/links", p.String()).Exec(ctx, &out); err != nil {
if err := api.core().Request("object/links", p.String()).Exec(ctx, &out); err != nil {
return nil, err
}
res := make([]*ipld.Link, len(out.Links))
Expand Down Expand Up @@ -135,7 +135,7 @@ func (api *ObjectAPI) Stat(ctx context.Context, p iface.Path) (*iface.ObjectStat
DataSize int
CumulativeSize int
}
if err := api.core().request("object/stat", p.String()).Exec(ctx, &out); err != nil {
if err := api.core().Request("object/stat", p.String()).Exec(ctx, &out); err != nil {
return nil, err
}

Expand All @@ -161,7 +161,7 @@ func (api *ObjectAPI) AddLink(ctx context.Context, base iface.Path, name string,
}

var out objectOut
err = api.core().request("object/patch/add-link", base.String(), name, child.String()).
err = api.core().Request("object/patch/add-link", base.String(), name, child.String()).
Option("create", options.Create).
Exec(ctx, &out)
if err != nil {
Expand All @@ -178,7 +178,7 @@ func (api *ObjectAPI) AddLink(ctx context.Context, base iface.Path, name string,

func (api *ObjectAPI) RmLink(ctx context.Context, base iface.Path, link string) (iface.ResolvedPath, error) {
var out objectOut
err := api.core().request("object/patch/rm-link", base.String(), link).
err := api.core().Request("object/patch/rm-link", base.String(), link).
Exec(ctx, &out)
if err != nil {
return nil, err
Expand All @@ -194,7 +194,7 @@ func (api *ObjectAPI) RmLink(ctx context.Context, base iface.Path, link string)

func (api *ObjectAPI) AppendData(ctx context.Context, p iface.Path, r io.Reader) (iface.ResolvedPath, error) {
var out objectOut
err := api.core().request("object/patch/append-data", p.String()).
err := api.core().Request("object/patch/append-data", p.String()).
FileBody(r).
Exec(ctx, &out)
if err != nil {
Expand All @@ -211,7 +211,7 @@ func (api *ObjectAPI) AppendData(ctx context.Context, p iface.Path, r io.Reader)

func (api *ObjectAPI) SetData(ctx context.Context, p iface.Path, r io.Reader) (iface.ResolvedPath, error) {
var out objectOut
err := api.core().request("object/patch/set-data", p.String()).
err := api.core().Request("object/patch/set-data", p.String()).
FileBody(r).
Exec(ctx, &out)
if err != nil {
Expand All @@ -237,7 +237,7 @@ func (api *ObjectAPI) Diff(ctx context.Context, a iface.Path, b iface.Path) ([]i
var out struct {
Changes []change
}
if err := api.core().request("object/diff", a.String(), b.String()).Exec(ctx, &out); err != nil {
if err := api.core().Request("object/diff", a.String(), b.String()).Exec(ctx, &out); err != nil {
return nil, err
}
res := make([]iface.ObjectChange, len(out.Changes))
Expand Down
2 changes: 1 addition & 1 deletion path.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (api *HttpApi) ResolvePath(ctx context.Context, path iface.Path) (iface.Res
}
}

if err := api.request("dag/resolve", path.String()).Exec(ctx, &out); err != nil {
if err := api.Request("dag/resolve", path.String()).Exec(ctx, &out); err != nil {
return nil, err
}

Expand Down
10 changes: 5 additions & 5 deletions pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (api *PinAPI) Add(ctx context.Context, p iface.Path, opts ...caopts.PinAddO
return err
}

return api.core().request("pin/add", p.String()).
return api.core().Request("pin/add", p.String()).
Option("recursive", options.Recursive).Exec(ctx, nil)
}

Expand All @@ -50,7 +50,7 @@ func (api *PinAPI) Ls(ctx context.Context, opts ...caopts.PinLsOption) ([]iface.
}

var out pinRefKeyList
err = api.core().request("pin/ls").
err = api.core().Request("pin/ls").
Option("type", options.Type).Exec(ctx, &out)
if err != nil {
return nil, err
Expand All @@ -74,7 +74,7 @@ func (api *PinAPI) Rm(ctx context.Context, p iface.Path, opts ...caopts.PinRmOpt
return err
}

return api.core().request("pin/rm", p.String()).
return api.core().Request("pin/rm", p.String()).
Option("recursive", options.Recursive).
Exec(ctx, nil)
}
Expand All @@ -85,7 +85,7 @@ func (api *PinAPI) Update(ctx context.Context, from iface.Path, to iface.Path, o
return err
}

return api.core().request("pin/update").
return api.core().Request("pin/update").
Option("unpin", options.Unpin).Exec(ctx, nil)
}

Expand Down Expand Up @@ -116,7 +116,7 @@ func (n *badNode) Err() error {
}

func (api *PinAPI) Verify(ctx context.Context) (<-chan iface.PinStatus, error) {
resp, err := api.core().request("pin/verify").Option("verbose", true).Send(ctx)
resp, err := api.core().Request("pin/verify").Option("verbose", true).Send(ctx)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (api *PubsubAPI) Ls(ctx context.Context) ([]string, error) {
Strings []string
}

if err := api.core().request("pubsub/ls").Exec(ctx, &out); err != nil {
if err := api.core().Request("pubsub/ls").Exec(ctx, &out); err != nil {
return nil, err
}

Expand All @@ -35,7 +35,7 @@ func (api *PubsubAPI) Peers(ctx context.Context, opts ...caopts.PubSubPeersOptio
Strings []string
}

if err := api.core().request("pubsub/peers", options.Topic).Exec(ctx, &out); err != nil {
if err := api.core().Request("pubsub/peers", options.Topic).Exec(ctx, &out); err != nil {
return nil, err
}

Expand All @@ -51,7 +51,7 @@ func (api *PubsubAPI) Peers(ctx context.Context, opts ...caopts.PubSubPeersOptio
}

func (api *PubsubAPI) Publish(ctx context.Context, topic string, message []byte) error {
return api.core().request("pubsub/pub", topic).
return api.core().Request("pubsub/pub", topic).
FileBody(bytes.NewReader(message)).
Exec(ctx, nil)
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func (api *PubsubAPI) Subscribe(ctx context.Context, topic string, opts ...caopt
return nil, err
}

resp, err := api.core().request("pubsub/sub", topic).
resp, err := api.core().Request("pubsub/sub", topic).
Option("discover", options.Discover).Send(ctx)

if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ func (api *SwarmAPI) Connect(ctx context.Context, pi peerstore.PeerInfo) error {
saddrs[i] = addr.Encapsulate(pidma).String()
}

return api.core().request("swarm/connect", saddrs...).Exec(ctx, nil)
return api.core().Request("swarm/connect", saddrs...).Exec(ctx, nil)
}

func (api *SwarmAPI) Disconnect(ctx context.Context, addr multiaddr.Multiaddr) error {
return api.core().request("swarm/disconnect", addr.String()).Exec(ctx, nil)
return api.core().Request("swarm/disconnect", addr.String()).Exec(ctx, nil)
}

type connInfo struct {
Expand Down Expand Up @@ -75,7 +75,7 @@ func (api *SwarmAPI) Peers(ctx context.Context) ([]iface.ConnectionInfo, error)
}
}

err := api.core().request("swarm/peers").
err := api.core().Request("swarm/peers").
Option("streams", true).
Option("latency", true).
Exec(ctx, &resp)
Expand Down Expand Up @@ -116,7 +116,7 @@ func (api *SwarmAPI) KnownAddrs(ctx context.Context) (map[peer.ID][]multiaddr.Mu
var out struct {
Addrs map[string][]string
}
if err := api.core().request("swarm/addrs").Exec(ctx, &out); err != nil {
if err := api.core().Request("swarm/addrs").Exec(ctx, &out); err != nil {
return nil, err
}
res := map[peer.ID][]multiaddr.Multiaddr{}
Expand Down Expand Up @@ -147,7 +147,7 @@ func (api *SwarmAPI) LocalAddrs(ctx context.Context) ([]multiaddr.Multiaddr, err
Strings []string
}

if err := api.core().request("swarm/addrs/local").Exec(ctx, &out); err != nil {
if err := api.core().Request("swarm/addrs/local").Exec(ctx, &out); err != nil {
return nil, err
}

Expand All @@ -167,7 +167,7 @@ func (api *SwarmAPI) ListenAddrs(ctx context.Context) ([]multiaddr.Multiaddr, er
Strings []string
}

if err := api.core().request("swarm/addrs/listen").Exec(ctx, &out); err != nil {
if err := api.core().Request("swarm/addrs/listen").Exec(ctx, &out); err != nil {
return nil, err
}

Expand Down
Loading

0 comments on commit 7f260a2

Please sign in to comment.