From de2d3ae323a551d556af5dcd0b00c63017b1ba0e Mon Sep 17 00:00:00 2001 From: Alex Fallenstedt <13971824+Fallenstedt@users.noreply.github.com> Date: Wed, 22 Dec 2021 17:10:37 -0800 Subject: [PATCH] add comments --- example/create_rules_example.go | 2 +- example/main.go | 2 +- rules/rule_builder.go | 9 ++++++++- rules/rule_builder_test.go | 2 +- rules/rules.go | 2 +- stream/stream.go | 1 + 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/example/create_rules_example.go b/example/create_rules_example.go index be117fd..1c138e3 100644 --- a/example/create_rules_example.go +++ b/example/create_rules_example.go @@ -89,4 +89,4 @@ func printRules(data []rules.DataRule) { fmt.Printf("Tag: %v\n",datum.Tag) fmt.Printf("Value: %v\n\n", datum.Value) } -} \ No newline at end of file +} diff --git a/example/main.go b/example/main.go index fd73447..2952e62 100644 --- a/example/main.go +++ b/example/main.go @@ -9,4 +9,4 @@ func main() { getRules() initiateStream() //deleteRules() -} \ No newline at end of file +} diff --git a/rules/rule_builder.go b/rules/rule_builder.go index a21e89c..8d23828 100644 --- a/rules/rule_builder.go +++ b/rules/rule_builder.go @@ -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"` @@ -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{}, @@ -64,4 +72,3 @@ func (r *RuleValue) setValueTag(value string, tag string) *RuleValue { r.Tag = &tag return r } - diff --git a/rules/rule_builder_test.go b/rules/rule_builder_test.go index 603aef3..1e01f48 100644 --- a/rules/rule_builder_test.go +++ b/rules/rule_builder_test.go @@ -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\"}]}") } -} \ No newline at end of file +} diff --git a/rules/rules.go b/rules/rules.go index 802ee86..1d3ac96 100644 --- a/rules/rules.go +++ b/rules/rules.go @@ -126,4 +126,4 @@ func (t *rules) addDryRun(dryRun bool) *url.Values { } else { return nil } -} \ No newline at end of file +} diff --git a/stream/stream.go b/stream/stream.go index b18b5ea..c66d238 100644 --- a/stream/stream.go +++ b/stream/stream.go @@ -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) {