Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package rubygemsclient

import (
"context"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -63,7 +64,12 @@ func (c *Client) GetGemInfo(name, version string) (*GemInfo, error) {
// In production, we'd use the compact index or version-specific APIs
url := fmt.Sprintf("%s/gems/%s.json", c.baseURL, name)

resp, err := c.httpClient.Get(url)
req, err := http.NewRequestWithContext(context.Background(), "GET", url, http.NoBody)
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}

resp, err := c.httpClient.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to fetch gem info: %w", err)
}
Expand Down Expand Up @@ -94,7 +100,12 @@ type VersionInfo struct {
func (c *Client) GetGemVersions(name string) ([]string, error) {
url := fmt.Sprintf("%s/versions/%s.json", c.baseURL, name)

resp, err := c.httpClient.Get(url)
req, err := http.NewRequestWithContext(context.Background(), "GET", url, http.NoBody)
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}

resp, err := c.httpClient.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to fetch gem versions: %w", err)
}
Expand Down Expand Up @@ -165,4 +176,3 @@ func (c *Client) GetMultipleGemInfo(requests []GemInfoRequest) []GemInfoResult {
wg.Wait()
return results
}

10 changes: 4 additions & 6 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http/httptest"
"testing"
"time"

)

func TestNewClient(t *testing.T) {
Expand Down Expand Up @@ -50,7 +49,7 @@ func TestGetGemInfo_Success(t *testing.T) {
}

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
_ = json.NewEncoder(w).Encode(response)
}))
defer server.Close()

Expand Down Expand Up @@ -117,7 +116,7 @@ func TestGetGemVersions_Success(t *testing.T) {
}

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(versions)
_ = json.NewEncoder(w).Encode(versions)
}))
defer server.Close()

Expand Down Expand Up @@ -152,7 +151,7 @@ func TestGetGemVersions_TooManyVersions(t *testing.T) {
}

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(versions)
_ = json.NewEncoder(w).Encode(versions)
}))
defer server.Close()

Expand Down Expand Up @@ -186,7 +185,7 @@ func TestGetMultipleGemInfo(t *testing.T) {
}

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(response)
_ = json.NewEncoder(w).Encode(response)
}))
defer server.Close()

Expand Down Expand Up @@ -233,4 +232,3 @@ func contains(s, substr string) bool {
return len(s) >= len(substr) && s[:len(substr)] == substr ||
(len(s) > len(substr) && contains(s[1:], substr))
}

Loading