diff --git a/src/environment.go b/src/environment.go index 8231eaef..1147e083 100644 --- a/src/environment.go +++ b/src/environment.go @@ -113,7 +113,7 @@ type Environment interface { getShellName() string getWindowTitle(imageName, windowTitleRegex string) (string, error) getWindowsRegistryKeyValue(path string) (*windowsRegistryValue, error) - doGet(url string, timeout int, requestModifiers ...HTTPRequestModifier) ([]byte, error) + HTTPRequest(url string, timeout int, requestModifiers ...HTTPRequestModifier) ([]byte, error) hasParentFilePath(path string) (fileInfo *fileInfo, err error) isWsl() bool isWsl2() bool @@ -469,8 +469,8 @@ func (env *environment) getShellName() string { return *env.args.Shell } -func (env *environment) doGet(url string, timeout int, requestModifiers ...HTTPRequestModifier) ([]byte, error) { - defer env.trace(time.Now(), "doGet", url) +func (env *environment) HTTPRequest(url string, timeout int, requestModifiers ...HTTPRequestModifier) ([]byte, error) { + defer env.trace(time.Now(), "HTTPRequest", url) ctx, cncl := context.WithTimeout(context.Background(), time.Millisecond*time.Duration(timeout)) defer cncl() request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) @@ -482,13 +482,13 @@ func (env *environment) doGet(url string, timeout int, requestModifiers ...HTTPR } response, err := client.Do(request) if err != nil { - env.log(Error, "doGet", err.Error()) + env.log(Error, "HTTPRequest", err.Error()) return nil, err } defer response.Body.Close() body, err := ioutil.ReadAll(response.Body) if err != nil { - env.log(Error, "doGet", err.Error()) + env.log(Error, "HTTPRequest", err.Error()) return nil, err } return body, nil diff --git a/src/segment_brewfather.go b/src/segment_brewfather.go index 7eba9394..eb8d0024 100644 --- a/src/segment_brewfather.go +++ b/src/segment_brewfather.go @@ -271,7 +271,7 @@ func (bf *brewfather) getResult() (*Batch, error) { addAuthHeader := func(request *http.Request) { request.Header.Add("authorization", authHeader) } - body, err := bf.env.doGet(batchURL, httpTimeout, addAuthHeader) + body, err := bf.env.HTTPRequest(batchURL, httpTimeout, addAuthHeader) if err != nil { return nil, err } @@ -283,7 +283,7 @@ func (bf *brewfather) getResult() (*Batch, error) { } // readings - body, err = bf.env.doGet(batchReadingsURL, httpTimeout, addAuthHeader) + body, err = bf.env.HTTPRequest(batchReadingsURL, httpTimeout, addAuthHeader) if err != nil { return nil, err } diff --git a/src/segment_brewfather_test.go b/src/segment_brewfather_test.go index 45a6b7c9..c7e474db 100644 --- a/src/segment_brewfather_test.go +++ b/src/segment_brewfather_test.go @@ -148,8 +148,8 @@ func TestBrewfatherSegment(t *testing.T) { cache.On("get", BFCacheKey).Return(nil, false) // cache testing later because cache is a little more complicated than just the single response. // cache.On("set", BFCacheKey, tc.JSONResponse, tc.CacheTimeout).Return() - env.On("doGet", BFBatchURL).Return([]byte(tc.BatchJSONResponse), tc.Error) - env.On("doGet", BFBatchReadingsURL).Return([]byte(tc.BatchReadingsJSONResponse), tc.Error) + env.On("HTTPRequest", BFBatchURL).Return([]byte(tc.BatchJSONResponse), tc.Error) + env.On("HTTPRequest", BFBatchReadingsURL).Return([]byte(tc.BatchReadingsJSONResponse), tc.Error) env.On("cache", nil).Return(cache) if tc.Template != "" { diff --git a/src/segment_ipify.go b/src/segment_ipify.go index adf135a6..2588fe17 100644 --- a/src/segment_ipify.go +++ b/src/segment_ipify.go @@ -51,7 +51,7 @@ func (i *ipify) getResult() (string, error) { httpTimeout := i.props.getInt(HTTPTimeout, DefaultHTTPTimeout) - body, err := i.env.doGet(url, httpTimeout) + body, err := i.env.HTTPRequest(url, httpTimeout) if err != nil { return "", err } diff --git a/src/segment_ipify_test.go b/src/segment_ipify_test.go index 4b211662..4c3d7f50 100644 --- a/src/segment_ipify_test.go +++ b/src/segment_ipify_test.go @@ -47,7 +47,7 @@ func TestIpifySegment(t *testing.T) { CacheTimeout: 0, } - env.On("doGet", IPIFYAPIURL).Return([]byte(tc.Response), tc.Error) + env.On("HTTPRequest", IPIFYAPIURL).Return([]byte(tc.Response), tc.Error) if tc.Template != "" { props[SegmentTemplate] = tc.Template diff --git a/src/segment_nightscout.go b/src/segment_nightscout.go index db644af9..2c131568 100644 --- a/src/segment_nightscout.go +++ b/src/segment_nightscout.go @@ -126,7 +126,7 @@ func (ns *nightscout) getResult() (*NightscoutData, error) { } } - body, err := ns.env.doGet(url, httpTimeout) + body, err := ns.env.HTTPRequest(url, httpTimeout) if err != nil { return nil, err } diff --git a/src/segment_nightscout_test.go b/src/segment_nightscout_test.go index 4b19575c..96ba5738 100644 --- a/src/segment_nightscout_test.go +++ b/src/segment_nightscout_test.go @@ -139,7 +139,7 @@ func TestNSSegment(t *testing.T) { cache.On("get", FAKEAPIURL).Return(tc.JSONResponse, !tc.CacheFoundFail) cache.On("set", FAKEAPIURL, tc.JSONResponse, tc.CacheTimeout).Return() - env.On("doGet", FAKEAPIURL).Return([]byte(tc.JSONResponse), tc.Error) + env.On("HTTPRequest", FAKEAPIURL).Return([]byte(tc.JSONResponse), tc.Error) env.On("cache", nil).Return(cache) if tc.Template != "" { diff --git a/src/segment_owm.go b/src/segment_owm.go index d61c9164..6ded8cda 100644 --- a/src/segment_owm.go +++ b/src/segment_owm.go @@ -99,7 +99,7 @@ func (d *owm) getResult() (*owmDataResponse, error) { httpTimeout := d.props.getInt(HTTPTimeout, DefaultHTTPTimeout) d.URL = fmt.Sprintf("http://api.openweathermap.org/data/2.5/weather?q=%s&units=%s&appid=%s", location, units, apikey) - body, err := d.env.doGet(d.URL, httpTimeout) + body, err := d.env.HTTPRequest(d.URL, httpTimeout) if err != nil { return new(owmDataResponse), err } diff --git a/src/segment_owm_test.go b/src/segment_owm_test.go index 0969f492..e47f2647 100644 --- a/src/segment_owm_test.go +++ b/src/segment_owm_test.go @@ -58,7 +58,7 @@ func TestOWMSegmentSingle(t *testing.T) { CacheTimeout: 0, } - env.On("doGet", OWMAPIURL).Return([]byte(tc.JSONResponse), tc.Error) + env.On("HTTPRequest", OWMAPIURL).Return([]byte(tc.JSONResponse), tc.Error) if tc.Template != "" { props[SegmentTemplate] = tc.Template @@ -184,7 +184,7 @@ func TestOWMSegmentIcons(t *testing.T) { response := fmt.Sprintf(`{"weather":[{"icon":"%s"}],"main":{"temp":20}}`, tc.IconID) expectedString := fmt.Sprintf("%s (20°C)", tc.ExpectedIconString) - env.On("doGet", OWMAPIURL).Return([]byte(response), nil) + env.On("HTTPRequest", OWMAPIURL).Return([]byte(response), nil) o := &owm{ props: properties{ @@ -207,7 +207,7 @@ func TestOWMSegmentIcons(t *testing.T) { response := fmt.Sprintf(`{"weather":[{"icon":"%s"}],"main":{"temp":20}}`, tc.IconID) expectedString := fmt.Sprintf("[%s (20°C)](http://api.openweathermap.org/data/2.5/weather?q=AMSTERDAM,NL&units=metric&appid=key)", tc.ExpectedIconString) - env.On("doGet", OWMAPIURL).Return([]byte(response), nil) + env.On("HTTPRequest", OWMAPIURL).Return([]byte(response), nil) o := &owm{ props: properties{ diff --git a/src/segment_path_test.go b/src/segment_path_test.go index 7001bed7..120e8a18 100644 --- a/src/segment_path_test.go +++ b/src/segment_path_test.go @@ -134,7 +134,7 @@ func (env *MockedEnvironment) getWindowsRegistryKeyValue(path string) (*windowsR return args.Get(0).(*windowsRegistryValue), args.Error(1) } -func (env *MockedEnvironment) doGet(url string, timeout int, requestModifiers ...HTTPRequestModifier) ([]byte, error) { +func (env *MockedEnvironment) HTTPRequest(url string, timeout int, requestModifiers ...HTTPRequestModifier) ([]byte, error) { args := env.Called(url) return args.Get(0).([]byte), args.Error(1) } diff --git a/src/segment_wakatime.go b/src/segment_wakatime.go index d3af7dad..191bb124 100644 --- a/src/segment_wakatime.go +++ b/src/segment_wakatime.go @@ -58,7 +58,7 @@ func (w *wakatime) setAPIData() error { httpTimeout := w.props.getInt(HTTPTimeout, DefaultHTTPTimeout) - body, err := w.env.doGet(url, httpTimeout) + body, err := w.env.HTTPRequest(url, httpTimeout) if err != nil { return err } diff --git a/src/segment_wakatime_test.go b/src/segment_wakatime_test.go index 3dfe18ec..d1e5b5b8 100644 --- a/src/segment_wakatime_test.go +++ b/src/segment_wakatime_test.go @@ -71,7 +71,7 @@ func TestWTTrackedTime(t *testing.T) { response := fmt.Sprintf(`{"cummulative_total": {"seconds": %.2f, "text": "x"}}`, float64(tc.Seconds)) - env.On("doGet", FAKEAPIURL).Return([]byte(response), tc.Error) + env.On("HTTPRequest", FAKEAPIURL).Return([]byte(response), tc.Error) cache := &MockedCache{} cache.On("get", FAKEAPIURL).Return(response, !tc.CacheFoundFail) diff --git a/src/segment_ytm.go b/src/segment_ytm.go index 2c953095..95a51cd6 100644 --- a/src/segment_ytm.go +++ b/src/segment_ytm.go @@ -86,7 +86,7 @@ func (y *ytm) setStatus() error { // https://github.com/ytmdesktop/ytmdesktop/wiki/Remote-Control-API url := y.props.getString(APIURL, "http://127.0.0.1:9863") httpTimeout := y.props.getInt(APIURL, DefaultHTTPTimeout) - body, err := y.env.doGet(url+"/query", httpTimeout) + body, err := y.env.HTTPRequest(url+"/query", httpTimeout) if err != nil { return err } diff --git a/src/segment_ytm_test.go b/src/segment_ytm_test.go index 7be7cfd9..0e77438b 100644 --- a/src/segment_ytm_test.go +++ b/src/segment_ytm_test.go @@ -43,7 +43,7 @@ func TestYTMStringStoppedSong(t *testing.T) { func bootstrapYTMDATest(json string, err error) *ytm { url := "http://127.0.0.1:9863" env := new(MockedEnvironment) - env.On("doGet", url+"/query").Return([]byte(json), err) + env.On("HTTPRequest", url+"/query").Return([]byte(json), err) ytm := &ytm{ env: env, props: properties{