-
Notifications
You must be signed in to change notification settings - Fork 246
/
oembed.go
59 lines (50 loc) · 1.15 KB
/
oembed.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
package anaconda
import (
"net/http"
"net/url"
"strconv"
)
type OEmbed struct {
Type string
Width int
Cache_age string
Height int
Author_url string
Html string
Version string
Provider_name string
Provider_url string
Url string
Author_name string
}
// No authorization on this endpoint. Its the only one.
func (a TwitterApi) GetOEmbed(v url.Values) (o OEmbed, err error) {
resp, err := http.Get(a.baseUrlV1() + "/statuses/oembed.json?" + v.Encode())
if err != nil {
return
}
defer resp.Body.Close()
err = decodeResponse(resp, &o)
return
}
// Calls GetOEmbed with the corresponding id. Convenience wrapper for GetOEmbed()
func (a TwitterApi) GetOEmbedId(id int64, v url.Values) (o OEmbed, err error) {
v = cleanValues(v)
v.Set("id", strconv.FormatInt(id, 10))
resp, err := http.Get(a.baseUrlV1() + "/statuses/oembed.json?" + v.Encode())
if err != nil {
return
}
defer resp.Body.Close()
err = decodeResponse(resp, &o)
return
}
func (a TwitterApi) baseUrlV1() string {
if a.baseUrl == BaseUrl {
return BaseUrlV1
}
if a.baseUrl == "" {
return BaseUrlV1
}
return a.baseUrl
}