add blocking feature to certain SDK calls

This commit is contained in:
Niko Storni 2019-06-11 18:40:48 +02:00
parent b444d284c6
commit 963177cd4c
2 changed files with 19 additions and 9 deletions

View file

@ -259,11 +259,13 @@ func (d *Client) ChannelCreate(name string, bid float64, options ChannelCreateOp
FilePath string `json:"file_path,omitempty"` FilePath string `json:"file_path,omitempty"`
IncludeProtoBuf bool `json:"include_protobuf"` IncludeProtoBuf bool `json:"include_protobuf"`
ChannelCreateOptions `json:",flatten"` ChannelCreateOptions `json:",flatten"`
Blocking bool `json:"blocking"`
}{ }{
Name: name, Name: name,
Bid: fmt.Sprintf("%.6f", bid), Bid: fmt.Sprintf("%.6f", bid),
IncludeProtoBuf: true, IncludeProtoBuf: true,
ChannelCreateOptions: options, ChannelCreateOptions: options,
Blocking: true,
} }
structs.DefaultTagName = "json" structs.DefaultTagName = "json"
return response, d.call(response, "channel_create", structs.Map(args)) return response, d.call(response, "channel_create", structs.Map(args))
@ -284,10 +286,12 @@ func (d *Client) ChannelUpdate(claimID string, options ChannelUpdateOptions) (*T
ClaimID string `json:"claim_id"` ClaimID string `json:"claim_id"`
IncludeProtoBuf bool `json:"include_protobuf"` IncludeProtoBuf bool `json:"include_protobuf"`
*ChannelUpdateOptions `json:",flatten"` *ChannelUpdateOptions `json:",flatten"`
Blocking bool `json:"blocking"`
}{ }{
ClaimID: claimID, ClaimID: claimID,
IncludeProtoBuf: true, IncludeProtoBuf: true,
ChannelUpdateOptions: &options, ChannelUpdateOptions: &options,
Blocking: true,
} }
structs.DefaultTagName = "json" structs.DefaultTagName = "json"
return response, d.call(response, "channel_update", structs.Map(args)) return response, d.call(response, "channel_update", structs.Map(args))
@ -319,12 +323,14 @@ func (d *Client) StreamCreate(name, filePath string, bid float64, options Stream
FilePath string `json:"file_path,omitempty"` FilePath string `json:"file_path,omitempty"`
FileSize *string `json:"file_size,omitempty"` FileSize *string `json:"file_size,omitempty"`
IncludeProtoBuf bool `json:"include_protobuf"` IncludeProtoBuf bool `json:"include_protobuf"`
Blocking bool `json:"blocking"`
*StreamCreateOptions `json:",flatten"` *StreamCreateOptions `json:",flatten"`
}{ }{
Name: name, Name: name,
FilePath: filePath, FilePath: filePath,
Bid: fmt.Sprintf("%.6f", bid), Bid: fmt.Sprintf("%.6f", bid),
IncludeProtoBuf: true, IncludeProtoBuf: true,
Blocking: true,
StreamCreateOptions: &options, StreamCreateOptions: &options,
} }
structs.DefaultTagName = "json" structs.DefaultTagName = "json"
@ -338,6 +344,7 @@ func (d *Client) StreamAbandon(txID string, nOut uint64, accountID *string, bloc
"nout": nOut, "nout": nOut,
"account_id": accountID, "account_id": accountID,
"include_protobuf": true, "include_protobuf": true,
"blocking": true,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -363,10 +370,12 @@ func (d *Client) StreamUpdate(claimID string, options StreamUpdateOptions) (*Tra
ClaimID string `json:"claim_id"` ClaimID string `json:"claim_id"`
IncludeProtoBuf bool `json:"include_protobuf"` IncludeProtoBuf bool `json:"include_protobuf"`
*StreamUpdateOptions `json:",flatten"` *StreamUpdateOptions `json:",flatten"`
Blocking bool `json:"blocking"`
}{ }{
ClaimID: claimID, ClaimID: claimID,
IncludeProtoBuf: true, IncludeProtoBuf: true,
StreamUpdateOptions: &options, StreamUpdateOptions: &options,
Blocking: true,
} }
structs.DefaultTagName = "json" structs.DefaultTagName = "json"
return response, d.call(response, "stream_update", structs.Map(args)) return response, d.call(response, "stream_update", structs.Map(args))
@ -379,6 +388,7 @@ func (d *Client) ChannelAbandon(txID string, nOut uint64, accountID *string, blo
"nout": nOut, "nout": nOut,
"account_id": accountID, "account_id": accountID,
"include_protobuf": true, "include_protobuf": true,
"blocking": true,
}) })
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -111,8 +111,8 @@ func TestClient_StreamCreate(t *testing.T) {
address := string(*addressResponse) address := string(*addressResponse)
got, err := d.StreamCreate("test"+fmt.Sprintf("%d", time.Now().Unix()), "/home/niko/Downloads/IMG_20171012_205120.jpg", 14.37, StreamCreateOptions{ got, err := d.StreamCreate("test"+fmt.Sprintf("%d", time.Now().Unix()), "/home/niko/Downloads/IMG_20171012_205120.jpg", 14.37, StreamCreateOptions{
ClaimCreateOptions: ClaimCreateOptions{ ClaimCreateOptions: ClaimCreateOptions{
Title: "This is a Test Title" + fmt.Sprintf("%d", time.Now().Unix()), Title: util.PtrToString("This is a Test Title" + fmt.Sprintf("%d", time.Now().Unix())),
Description: "My Special Description", Description: util.PtrToString("My Special Description"),
Tags: []string{"nsfw", "test"}, Tags: []string{"nsfw", "test"},
Languages: []string{"en-US", "fr-CH"}, Languages: []string{"en-US", "fr-CH"},
Locations: []Location{{ Locations: []Location{{
@ -142,7 +142,7 @@ func TestClient_StreamCreate(t *testing.T) {
Preview: nil, Preview: nil,
AllowDuplicateName: nil, AllowDuplicateName: nil,
ChannelName: nil, ChannelName: nil,
ChannelID: util.PtrToString("253ca42da47ad8a430e18d52860cb499c50eff25"), ChannelID: util.PtrToString("dd0b559b4f17a7af984f173efb5438534eb6ab27"),
ChannelAccountID: nil, ChannelAccountID: nil,
}) })
if err != nil { if err != nil {
@ -156,8 +156,8 @@ func TestClient_ChannelCreate(t *testing.T) {
d := NewClient("") d := NewClient("")
got, err := d.ChannelCreate("@Test"+fmt.Sprintf("%d", time.Now().Unix()), 13.37, ChannelCreateOptions{ got, err := d.ChannelCreate("@Test"+fmt.Sprintf("%d", time.Now().Unix()), 13.37, ChannelCreateOptions{
ClaimCreateOptions: ClaimCreateOptions{ ClaimCreateOptions: ClaimCreateOptions{
Title: "Mess with the channels", Title: util.PtrToString("Mess with the channels"),
Description: "And you'll get what you deserve", Description: util.PtrToString("And you'll get what you deserve"),
Tags: []string{"we", "got", "tags"}, Tags: []string{"we", "got", "tags"},
Languages: []string{"en-US"}, Languages: []string{"en-US"},
Locations: []Location{{ Locations: []Location{{
@ -186,8 +186,8 @@ func TestClient_ChannelUpdate(t *testing.T) {
ClearTags: util.PtrToBool(true), ClearTags: util.PtrToBool(true),
ChannelCreateOptions: ChannelCreateOptions{ ChannelCreateOptions: ChannelCreateOptions{
ClaimCreateOptions: ClaimCreateOptions{ ClaimCreateOptions: ClaimCreateOptions{
Title: "Mess with the channels", Title: util.PtrToString("Mess with the channels"),
Description: "And you'll get what you deserve", Description: util.PtrToString("And you'll get what you deserve"),
Tags: []string{"we", "got", "more", "tags"}, Tags: []string{"we", "got", "more", "tags"},
Languages: []string{"en-US"}, Languages: []string{"en-US"},
Locations: []Location{{ Locations: []Location{{
@ -213,8 +213,8 @@ func TestClient_ChannelAbandon(t *testing.T) {
channelName := "@TestToDelete" + fmt.Sprintf("%d", time.Now().Unix()) channelName := "@TestToDelete" + fmt.Sprintf("%d", time.Now().Unix())
channelResponse, err := d.ChannelCreate(channelName, 13.37, ChannelCreateOptions{ channelResponse, err := d.ChannelCreate(channelName, 13.37, ChannelCreateOptions{
ClaimCreateOptions: ClaimCreateOptions{ ClaimCreateOptions: ClaimCreateOptions{
Title: "Mess with the channels", Title: util.PtrToString("Mess with the channels"),
Description: "And you'll get what you deserve", Description: util.PtrToString("And you'll get what you deserve"),
Tags: []string{"we", "got", "tags"}, Tags: []string{"we", "got", "tags"},
Languages: []string{"en-US"}, Languages: []string{"en-US"},
Locations: []Location{{ Locations: []Location{{