// VerifyCredentials hydrates the account object by validating the bearer token
// against the Mastodon API
-func (a *Account) VerifyCredentials(host string, token api.Token) (err error) {
+func (a *Account) VerifyCredentials(
+ host string, token api.Token, proxy string) (err error) {
u := url.URL{
Host: host,
Path: "api/v1/accounts/verify_credentials",
}
u.Scheme = "https"
- body, err := api.Get(u, host, token)
+ body, err := api.Get(u, host, token, proxy)
if err != nil {
return err
}
// GetAccount returns the details of account specified by ID.
func GetAccount(
- ID string, host string, token api.Token) (account Account, err error) {
+ ID string, host string, token api.Token, proxy string) (account Account, err error) {
id := url.PathEscape(ID)
path, err := url.JoinPath("api/v1/accounts", id)
}
u.Scheme = "https"
- body, err := api.Get(u, host, token)
+ body, err := api.Get(u, host, token, proxy)
if err != nil {
return account, err
}
}
// Get returns the currently logged in account.
-func (a *Account) Get(host string, token api.Token) (account Account, err error) {
- return GetAccount(a.ID, host, token)
+func (a *Account) Get(
+ host string, token api.Token, proxy string) (account Account, err error) {
+ return GetAccount(a.ID, host, token, proxy)
}
// GetFollowers returns a list of all accounts following the logged in user
func (a *Account) GetFollowers(
- host string, token api.Token) (followers AccountCollection, err error) {
+ host string, token api.Token, proxy string) (followers AccountCollection, err error) {
id := url.PathEscape(a.ID)
path, err := url.JoinPath("api/v1/accounts", id, "followers")
}
u.Scheme = "https"
- body, err := api.Get(u, host, token)
+ body, err := api.Get(u, host, token, proxy)
if err != nil {
return followers, err
}
// GetFollowing returns a list of all accounts followed by the logged in user
func (a *Account) GetFollowing(
- host string, token api.Token) (following AccountCollection, err error) {
+ host string, token api.Token, proxy string) (following AccountCollection, err error) {
id := url.PathEscape(a.ID)
path, err := url.JoinPath("api/v1/accounts", id, "following")
}
u.Scheme = "https"
- body, err := api.Get(u, host, token)
+ body, err := api.Get(u, host, token, proxy)
if err != nil {
return
}
}
// GetLists fetches all lists the account owns
-func (a *Account) GetLists(host string, token api.Token) (lists ListCollection, err error) {
+func (a *Account) GetLists(
+ host string, token api.Token, proxy string) (lists ListCollection, err error) {
+
u := url.URL{
Host: host,
Path: "api/v1/lists",
}
u.Scheme = "https"
- body, err := api.Get(u, host, token)
+ body, err := api.Get(u, host, token, proxy)
if err != nil {
return
}
// GetStatuses fetches a list of statuses by the account.
func (a *Account) GetStatuses(
- host string, token api.Token) (statuses StatusCollection, err error) {
+ host string, token api.Token, proxy string) (statuses StatusCollection, err error) {
id := url.PathEscape(a.ID)
path, err := url.JoinPath("api/v1/accounts", id, "statuses")
}
u.Scheme = "https"
- body, err := api.Get(u, host, token)
+ body, err := api.Get(u, host, token, proxy)
if err != nil {
return
}
"net/url"
)
+// API provides connection details necessary for all API requests.
+type API struct {
+ host string
+ token Token
+ proxyURL url.URL
+}
+
+func getClient(proxyStr string) (client *http.Client, err error) {
+ proxyURL, err := url.Parse(proxyStr)
+ if err != nil {
+ client = &http.Client{}
+ return
+ }
+
+ transport := &http.Transport{
+ Proxy: http.ProxyURL(proxyURL)}
+
+ client = &http.Client{
+ Transport: transport}
+
+ return client, err
+}
+
// Get provides a request
-func Get(u url.URL, host string, token Token) (body []byte, err error) {
- client := &http.Client{}
+func Get(u url.URL, host string, token Token, proxyStr string) (body []byte, err error) {
+ client, err := getClient(proxyStr)
+ if err != nil {
+ return
+ }
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {