53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
|
package heliumapi
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func GetHotspotActivityCount(hotspot string) (*ActivityCounts, error) {
|
||
|
path := "/v1/hotspots/" + hotspot + "/activity/count"
|
||
|
|
||
|
// query the api
|
||
|
respBody, err := getHeliumApi(path, nil)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
// unmarshal the response
|
||
|
respobject := ActivityCounts{}
|
||
|
err = json.Unmarshal(respBody, &respobject)
|
||
|
if err != nil {
|
||
|
return nil, fmt.Errorf("failed to unmarshal response from path %v: %v", path, err)
|
||
|
}
|
||
|
|
||
|
return &respobject, nil
|
||
|
}
|
||
|
|
||
|
func GetRewardsTotalForHotspot(hotspot string, minTime *time.Time, maxTime *time.Time) (*RewardTotal, error) {
|
||
|
path := "/v1/hotspots/" + hotspot + "/rewards/sum"
|
||
|
params := map[string]string{}
|
||
|
if minTime != nil {
|
||
|
params["min_time"] = minTime.UTC().Format("2006-01-02T15:04:05Z")
|
||
|
}
|
||
|
if maxTime != nil {
|
||
|
params["max_time"] = maxTime.UTC().Format("2006-01-02T15:04:05Z")
|
||
|
}
|
||
|
|
||
|
// query the api
|
||
|
respBody, err := getHeliumApi(path, ¶ms)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
// unmarshal the response
|
||
|
respobject := RewardTotal{}
|
||
|
err = json.Unmarshal(respBody, &respobject)
|
||
|
if err != nil {
|
||
|
return nil, fmt.Errorf("failed to unmarshal response from path %v: %v", path, err)
|
||
|
}
|
||
|
|
||
|
return &respobject, nil
|
||
|
}
|