/
answers.go
67 lines (55 loc) · 2.21 KB
/
answers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package stackongo
import (
"fmt"
"strings"
)
// AllAnswers returns all answers in site
func (session Session) AllAnswers(params map[string]string) (output *Answers, error error) {
output = new(Answers)
error = session.get("answers", params, output)
return
}
// Answers returns the answers with the given ids
func (session Session) GetAnswers(ids []int, params map[string]string) (output *Answers, error error) {
string_ids := []string{}
for _, v := range ids {
string_ids = append(string_ids, fmt.Sprintf("%v", v))
}
request_path := strings.Join([]string{"answers", strings.Join(string_ids, ";")}, "/")
output = new(Answers)
error = session.get(request_path, params, output)
return
}
// AnswersForQuestions returns the answers for the questions identified with given ids
func (session Session) AnswersForQuestions(ids []int, params map[string]string) (output *Answers, error error) {
string_ids := []string{}
for _, v := range ids {
string_ids = append(string_ids, fmt.Sprintf("%v", v))
}
request_path := strings.Join([]string{"questions", strings.Join(string_ids, ";"), "answers"}, "/")
output = new(Answers)
error = session.get(request_path, params, output)
return
}
// AnswersFromUsers returns the answers from the users identified with given ids
func (session Session) AnswersFromUsers(ids []int, params map[string]string) (output *Answers, error error) {
string_ids := []string{}
for _, v := range ids {
string_ids = append(string_ids, fmt.Sprintf("%v", v))
}
request_path := strings.Join([]string{"users", strings.Join(string_ids, ";"), "answers"}, "/")
output = new(Answers)
error = session.get(request_path, params, output)
return
}
// TopAnswersFromUsers returns the top answers from the users identified with given ids for the questions with given tags
func (session Session) TopAnswersFromUsers(ids []int, tags []string, params map[string]string) (output *Answers, error error) {
string_ids := []string{}
for _, v := range ids {
string_ids = append(string_ids, fmt.Sprintf("%v", v))
}
request_path := strings.Join([]string{"users", strings.Join(string_ids, ";"), "tags", strings.Join(tags, ";"), "top-answers"}, "/")
output = new(Answers)
error = session.get(request_path, params, output)
return
}