/
heroku.go
62 lines (53 loc) · 1.15 KB
/
heroku.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
// Copyright (c) 2013 Jason McVetta. This is Free Software, released under the
// terms of the GPL v3. See http://www.gnu.org/copyleft/gpl.html for details.
// Resist intellectual serfdom - the ownership of ideas is akin to slavery.
package heroku
import (
"encoding/json"
"errors"
"github.com/jmcvetta/restclient"
"log"
"net/url"
"path/filepath"
"runtime"
"strconv"
)
const HerokuApi = "https://api.heroku.com"
var (
BadResponse = errors.New("Bad response from server")
)
type HerokuError struct {
Id string
Error string
}
func NewHeroku(apiKey string) *Heroku {
h := Heroku{
ApiKey: apiKey,
ApiHref: HerokuApi,
rc: restclient.New(),
}
return &h
}
type Heroku struct {
ApiKey string
ApiHref string
rc *restclient.Client
}
func (h *Heroku) userinfo() *url.Userinfo {
return url.UserPassword("", h.ApiKey)
}
func prettyPrint(v interface{}) {
_, file, line, ok := runtime.Caller(1)
if !ok {
file = "???"
line = 0
}
lineNo := strconv.Itoa(line)
file = filepath.Base(file)
b, err := json.MarshalIndent(v, "", "\t")
if err != nil {
log.Panic(err)
}
s := file + ":" + lineNo + ": \n" + string(b) + "\n"
println(s)
}