Skip to content

Commit 0a002cc

Browse files
committed
Add std.HTTPGetByURL and SE Questions endpoint cfg
Set Site at root of stackexchange config since it shared within requests Move number of questions to watch in config to ConfigureStackExchange section and add option to configure Stack Exchange Questions endpoint. Add std.HTTPGetByURL to perform simple calls with url as string Make std.Table to accept any value ...interface{}
1 parent 43a82d1 commit 0a002cc

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

slackoverflow/cmd-config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (a *cmdConfig) Execute(args []string) error {
4646

4747
stackexchange.AddRow("Key", slackoverflow.config.StackExchange.Key)
4848

49-
stackexchange.AddRow("Site", slackoverflow.config.StackExchange.SearchAdvanced["site"])
49+
stackexchange.AddRow("Site", slackoverflow.config.StackExchange.Site)
5050
stackexchange.AddRow("Tagged", slackoverflow.config.StackExchange.SearchAdvanced["tagged"])
5151
stackexchange.Print()
5252

slackoverflow/config-yaml.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
// Yaml mapping to yaml configuration
1717
type yamlContents struct {
1818
SlackOverflow struct {
19-
LogLevel string `yaml:"log_level"`
19+
LogLevel string `yaml:"log-level"`
2020
Watch int `yaml:"watch"`
2121
} `yaml:"slackoverflow"`
2222
Slack struct {
@@ -26,11 +26,14 @@ type yamlContents struct {
2626
APIHost string `yaml:"api-host"`
2727
} `yaml:"slack"`
2828
StackExchange struct {
29-
Enabled bool `yaml:"enabled"`
30-
Key string `yaml:"key"`
31-
APIVersion string `yaml:"api-version"`
32-
APIHost string `yaml:"api-host"`
33-
SearchAdvanced map[string]string `yaml:"search-advanced"`
29+
Enabled bool `yaml:"enabled"`
30+
Key string `yaml:"key"`
31+
APIVersion string `yaml:"api-version"`
32+
APIHost string `yaml:"api-host"`
33+
Site string `yaml:"site"`
34+
QuestionsToWatch int `yaml:"questions-to-watch"`
35+
SearchAdvanced map[string]string `yaml:"search-advanced"`
36+
Questions map[string]string `yaml:"questions"`
3437
} `yaml:"stackexchange"`
3538
}
3639

@@ -119,14 +122,6 @@ func (yc *yamlContents) ConfigureSlackOverflow() {
119122
std.Hr()
120123
yc.SlackOverflow.LogLevel = strings.TrimSpace(logLevel)
121124

122-
// Number of questions to watch
123-
std.Hr()
124-
std.Body("Set the value for how many latest questions you want to track and update.")
125-
std.Body("Good value is (25) which means that besides checking new qustions in defined stack exchange site")
126-
std.Body("also last (n) questions will be checked for comment count, view count, answer count, score and is question accepted or not.")
127-
std.Body("Emoijs of these stats will be removed from older than (n) questions.")
128-
std.Hr()
129-
fmt.Scan(&yc.SlackOverflow.Watch)
130125
yc.Save()
131126
Ok("Slack Overflow is configured")
132127
std.Hr()
@@ -157,7 +152,7 @@ func (yc *yamlContents) ConfigureStackExchange() {
157152
std.Body("For full list of available sites check: http://stackexchange.com/sites")
158153
std.Hr()
159154
site, _ := reader.ReadString('\n')
160-
yc.StackExchange.SearchAdvanced["site"] = strings.TrimSpace(site)
155+
yc.StackExchange.Site = strings.TrimSpace(site)
161156

162157
// Set tagged parameter value for Stack Exchange search advanced
163158
std.Hr()
@@ -167,6 +162,15 @@ func (yc *yamlContents) ConfigureStackExchange() {
167162
tagged, _ := reader.ReadString('\n')
168163
yc.StackExchange.SearchAdvanced["tagged"] = strings.TrimSpace(tagged)
169164

165+
// Number of questions to watch
166+
std.Hr()
167+
std.Body("Set the value for how many latest questions you want to track and update.")
168+
std.Body("Good value is (25) which means that besides checking new qustions in defined stack exchange site")
169+
std.Body("also last (n) questions will be checked for comment count, view count, answer count, score and is question accepted or not.")
170+
std.Body("Emoijs of these stats will be removed from older than (n) questions.")
171+
std.Hr()
172+
fmt.Scan(&yc.StackExchange.QuestionsToWatch)
173+
170174
// stackexchange clientKey
171175
std.Hr()
172176
std.Body("Without having Stack Exchange API APP key's you can make 300 requests per day.")

std/http.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@ import (
88
"net/url"
99
)
1010

11+
// HTTPGetByURL make Get request
12+
func HTTPGetByURL(url string, collection interface{}) error {
13+
14+
client := &http.Client{
15+
Transport: http.DefaultTransport,
16+
}
17+
18+
response, err := client.Get(url)
19+
20+
if err != nil {
21+
return err
22+
}
23+
24+
err = readResponse(response, &collection)
25+
26+
return err
27+
}
28+
1129
// HTTPGet make Get request
1230
func HTTPGet(host string, path string, qp map[string]string, collection interface{}) error {
1331

std/table.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package std
22

33
import (
4+
"fmt"
45
"strings"
56

67
"github.com/logrusorgru/aurora"
@@ -32,10 +33,11 @@ func NewTable(h ...string) *Table {
3233
}
3334

3435
// AddRow to the table
35-
func (t *Table) AddRow(a ...string) {
36+
func (t *Table) AddRow(a ...interface{}) {
3637
if t.colCount == len(a) {
3738
row := []TableCol{}
38-
for i, rowCol := range a {
39+
for i, rowColRaw := range a {
40+
rowCol := fmt.Sprintf("%v", rowColRaw)
3941
colLen := len(rowCol)
4042
col := TableCol{rowCol, colLen}
4143
if colLen > t.cols[i].colLenght {

0 commit comments

Comments
 (0)