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

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallenstedt committed Dec 23, 2021
1 parent 1ce3079 commit de2d3ae
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion example/create_rules_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ func printRules(data []rules.DataRule) {
fmt.Printf("Tag: %v\n",datum.Tag)
fmt.Printf("Value: %v\n\n", datum.Value)
}
}
}
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ func main() {
getRules()
initiateStream()
//deleteRules()
}
}
9 changes: 8 additions & 1 deletion rules/rule_builder.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
package rules

type (
// IRuleBuilder is an interface that describers how to implement a RuleBuilder.
IRuleBuilder interface {
AddRule(value string, tag string) *RuleBuilder
Build() CreateRulesRequest
}

// RuleValue is a struct used to help create twitter stream rules.
// It takes in a value and a tag.
RuleValue struct {
Value *string `json:"value,omitempty"`
Tag *string `json:"tag,omitempty"`
}

// RuleBuilder is struct used to help create twitter stream rules.
RuleBuilder struct {
rules []*RuleValue
}

// CreateRulesRequest is a struct used to create the payload for creating rules.
CreateRulesRequest struct {
Add []*RuleValue `json:"add"`
}

// DeleteRulesRequest is a struct used to create the payload for deleting rules.
DeleteRulesRequest struct {
Delete struct {
Ids []int `json:"ids"`
Expand All @@ -27,12 +33,14 @@ type (

)

// NewDeleteRulesRequest will create an instance of DeleteRulesRequest.
func NewDeleteRulesRequest(ids ...int) DeleteRulesRequest {
return DeleteRulesRequest{Delete: struct {
Ids []int `json:"ids"`
}(struct{ Ids []int }{Ids: ids})}
}

// NewRuleBuilder will create an instance of `RuleBuilder`.
func NewRuleBuilder() *RuleBuilder {
return &RuleBuilder{
rules: []*RuleValue{},
Expand Down Expand Up @@ -64,4 +72,3 @@ func (r *RuleValue) setValueTag(value string, tag string) *RuleValue {
r.Tag = &tag
return r
}

2 changes: 1 addition & 1 deletion rules/rule_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ func TestNewRuleBuilderBuildsManyRules(t *testing.T) {
if string(body) != "{\"add\":[{\"value\":\"cats\",\"tag\":\"cat tweets\"},{\"value\":\"dogs\",\"tag\":\"dog tweets\"}]}" {
t.Errorf("Expected %v to equal %v", string(body), "{\"add\":[{\"value\":\"cats\",\"tag\":\"cat tweets\"},{\"value\":\"dogs\",\"tag\":\"dog tweets\"}]}")
}
}
}
2 changes: 1 addition & 1 deletion rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ func (t *rules) addDryRun(dryRun bool) *url.Values {
} else {
return nil
}
}
}
1 change: 1 addition & 0 deletions stream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type (
}
)

// NewStream creates an instance of `Stream`. This is used to manage the stream with Twitter.
func NewStream(httpClient httpclient.IHttpClient, reader IStreamResponseBodyReader) IStream {
return &Stream{
unmarshalHook: func(bytes []byte) (interface{}, error) {
Expand Down

0 comments on commit de2d3ae

Please sign in to comment.