-
Notifications
You must be signed in to change notification settings - Fork 0
/
fun.go
58 lines (49 loc) · 1.38 KB
/
fun.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
package btcapi
import (
"encoding/json"
"fmt"
)
type QuoteDetails struct {
Text string `json:"text"`
Speaker string `json:"speaker"`
URL string `json:"url"`
Date string `json:"date"`
Context string `json:"context"`
}
const QuotesRoute string = "/quotes"
// Quotes returns all quotes
func (c Config) Quotes() (quotes []QuoteDetails, err error) {
body, err := getAPI(c.ExplorerURL + api + QuotesRoute + "/all")
if err != nil {
return quotes, err
}
err = json.Unmarshal(body, "es)
if err != nil {
return quotes, fmt.Errorf("unable to parse returned body: %w", err)
}
return quotes, nil
}
// Quote takes an index and returns the corresponding quote
func (c Config) Quote(index int) (quote QuoteDetails, err error) {
body, err := getAPI(c.ExplorerURL + api + QuotesRoute + "/" + fmt.Sprintf("%d", index))
if err != nil {
return quote, err
}
err = json.Unmarshal(body, "e)
if err != nil {
return quote, fmt.Errorf("unable to parse returned body: %w", err)
}
return quote, nil
}
// RandomQuote takes an index and returns the corresponding quote
func (c Config) RandomQuote() (quote QuoteDetails, err error) {
body, err := getAPI(c.ExplorerURL + api + QuotesRoute + "/random")
if err != nil {
return quote, err
}
err = json.Unmarshal(body, "e)
if err != nil {
return quote, fmt.Errorf("unable to parse returned body: %w", err)
}
return quote, nil
}