Skip to content

Commit 0519a8d

Browse files
committed
Record response for OEmbed test
1 parent 35b6f74 commit 0519a8d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

oembed.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package anaconda
22

33
import (
4+
"io"
5+
"io/ioutil"
46
"net/http"
57
"net/url"
8+
"os"
9+
"path/filepath"
610
"strconv"
11+
"strings"
712
)
813

914
type OEmbed struct {
@@ -22,12 +27,23 @@ type OEmbed struct {
2227

2328
// No authorization on this endpoint. Its the only one.
2429
func (a TwitterApi) GetOEmbed(v url.Values) (o OEmbed, err error) {
30+
var f io.Writer
31+
32+
filename := filepath.Join(append([]string{"json"}, strings.Split("/statuses/oembed.json", "/")...)...)
33+
fl, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, 0644)
34+
if err != nil {
35+
return o, err
36+
}
37+
defer fl.Close()
38+
f = fl
39+
2540
resp, err := http.Get(a.baseUrlV1() + "/statuses/oembed.json?" + v.Encode())
2641
if err != nil {
2742
return
2843
}
2944
defer resp.Body.Close()
3045

46+
resp.Body = ioutil.NopCloser(io.TeeReader(resp.Body, f))
3147
err = decodeResponse(resp, &o)
3248
return
3349
}

0 commit comments

Comments
 (0)