Skip to content

contriboss/rubygems-client-go

Repository files navigation

rubygems-client-go

Go client library for the RubyGems.org API - a provider implementation for ORE

CI Go Reference Go Report Card

Overview

This is a Go client library for the RubyGems.org API, designed as a provider implementation for ORE, the fast Ruby gem installer. It's part of ORE's plugin architecture that allows swapping gem sources.

Ruby equivalent: Gem::RemoteFetcher and Gem::SpecFetcher

Why This Exists

ORE uses a provider-based architecture to avoid vendor lock-in with RubyGems.org. This client is the default provider, but can be replaced with:

  • Private gem servers
  • GitHub Packages
  • GitLab Package Registry
  • Local caches
  • Alternative gem repositories

Quick Start

go get github.com/contriboss/rubygems-client-go

Usage

Basic API Client

package main

import (
    "fmt"
    "log"

    rubygems "github.com/contriboss/rubygems-client-go"
)

func main() {
    client := rubygems.NewClient()

    // Get gem information
    info, err := client.GetGemInfo("rails", "7.0.0")
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Gem: %s v%s\n", info.Name, info.Version)
    fmt.Printf("Runtime dependencies: %d\n", len(info.Dependencies.Runtime))

    // Get available versions
    versions, err := client.GetGemVersions("rails")
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Available versions: %v\n", versions[:5]) // Show first 5
}

Parallel Fetching

// Fetch multiple gems in parallel
requests := []rubygems.GemInfoRequest{
    {Name: "rails", Version: "7.0.0"},
    {Name: "puma", Version: "6.0.0"},
    {Name: "sidekiq", Version: "7.0.0"},
}

results := client.GetMultipleGemInfo(requests)

for _, result := range results {
    if result.Error != nil {
        log.Printf("Failed to fetch %s: %v", result.Request.Name, result.Error)
        continue
    }

    fmt.Printf("%s v%s has %d dependencies\n",
        result.Info.Name,
        result.Info.Version,
        len(result.Info.Dependencies.Runtime))
}

Provider Interface

This client implements the ORE provider interface, allowing it to be used as a gem source:

type Provider interface {
    GetGemInfo(name, version string) (*GemInfo, error)
    GetVersions(name string) ([]string, error)
    GetDependencies(name, version string) ([]Dependency, error)
    // Additional methods for downloading gems
}

Features

  • Connection pooling for efficient HTTP requests
  • Parallel fetching for multiple gems
  • Automatic retries with exponential backoff
  • Version limiting to avoid overwhelming resolvers
  • Ruby engine compatibility

Architecture

This is one component of ORE's modular architecture:

ORE (orchestrator)
    ↓
Provider Interface
    ↓
rubygems-client-go (this library)
    ↓
RubyGems.org API

Building

We use Mage for builds:

# Install Mage
go install github.com/magefile/mage@latest

# Run tests
mage test

# Run linter
mage lint

# Build
mage build

# Run CI checks
mage ci

Testing

# Run tests with coverage
mage test

# Run tests with race detector
mage testrace

# Run benchmarks
mage bench

Performance

  • Parallel gem fetching with configurable worker pool
  • Connection reuse reduces latency
  • Automatic retry on transient failures
  • Efficient caching in ORE layer

License

MIT

Related Projects


Made by @contriboss - Part of the ORE ecosystem