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

Commit

Permalink
Object.New
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Jan 9, 2019
1 parent 3217104 commit 60321ed
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (api *HttpApi) Pin() iface.PinAPI {
}

func (api *HttpApi) Object() iface.ObjectAPI {
return nil
return (*ObjectAPI)(api)
}

func (api *HttpApi) Dht() iface.DhtAPI {
Expand Down
8 changes: 8 additions & 0 deletions ipldnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ type ipldNode struct {
api *HttpApi
}

func (a *HttpApi) nodeFromPath(ctx context.Context, p iface.ResolvedPath) ipld.Node {
return &ipldNode{
ctx: ctx,
path: p,
api: a,
}
}

func (n *ipldNode) RawData() []byte {
r, err := n.api.Block().Get(n.ctx, n.path)
if err != nil {
Expand Down
82 changes: 82 additions & 0 deletions object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package httpapi

import (
"context"
"github.com/ipfs/go-cid"
"io"

"github.com/ipfs/go-ipfs/core/coreapi/interface"
caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"

"github.com/ipfs/go-ipld-format"
)

type ObjectAPI HttpApi

type objectOut struct {
Hash string
}

func (api *ObjectAPI) New(ctx context.Context, opts ...caopts.ObjectNewOption) (format.Node, error) {
options, err := caopts.ObjectNewOptions(opts...)
if err != nil {
return nil, err
}

var out objectOut
err = api.core().request("object/new", options.Type).Exec(ctx, &out)
if err != nil {
return nil, err
}

c, err := cid.Parse(out.Hash)
if err != nil {
return nil, err
}

return api.core().nodeFromPath(ctx, iface.IpfsPath(c)), nil
}

func (api *ObjectAPI) Put(context.Context, io.Reader, ...caopts.ObjectPutOption) (iface.ResolvedPath, error) {
panic("implement me")
}

func (api *ObjectAPI) Get(context.Context, iface.Path) (format.Node, error) {
panic("implement me")
}

func (api *ObjectAPI) Data(context.Context, iface.Path) (io.Reader, error) {
panic("implement me")
}

func (api *ObjectAPI) Links(context.Context, iface.Path) ([]*format.Link, error) {
panic("implement me")
}

func (api *ObjectAPI) Stat(context.Context, iface.Path) (*iface.ObjectStat, error) {
panic("implement me")
}

func (api *ObjectAPI) AddLink(ctx context.Context, base iface.Path, name string, child iface.Path, opts ...caopts.ObjectAddLinkOption) (iface.ResolvedPath, error) {
panic("implement me")
}

func (api *ObjectAPI) RmLink(ctx context.Context, base iface.Path, link string) (iface.ResolvedPath, error) {
panic("implement me")
}

func (api *ObjectAPI) AppendData(context.Context, iface.Path, io.Reader) (iface.ResolvedPath, error) {
panic("implement me")
}

func (api *ObjectAPI) SetData(context.Context, iface.Path, io.Reader) (iface.ResolvedPath, error) {
panic("implement me")
}

func (api *ObjectAPI) Diff(context.Context, iface.Path, iface.Path) ([]iface.ObjectChange, error) {
panic("implement me")
}

func (api *ObjectAPI) core() *HttpApi {
return (*HttpApi)(api)
}

0 comments on commit 60321ed

Please sign in to comment.