Class: Crumb::MCP::ApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/crumb/mcp/api_client.rb

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, token, repo_path, slug) ⇒ ApiClient

Returns a new instance of ApiClient.



19
20
21
22
23
24
# File 'lib/crumb/mcp/api_client.rb', line 19

def initialize(base_url, token, repo_path, slug)
  @base_url  = base_url.chomp("/")
  @token     = token
  @repo_path = repo_path
  @slug      = slug
end

Class Method Details

.for(slug) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/crumb/mcp/api_client.rb', line 11

def self.for(slug)
  ep    = Registry.endpoint_for(slug)
  token = ENV.fetch(ep[:token_env]) do
    raise Error, "Missing env var #{ep[:token_env]} for endpoint #{slug}"
  end
  new(ep[:base_url], token, ep[:repo_path], slug)
end

Instance Method Details

#detail(id) ⇒ Object



31
32
33
# File 'lib/crumb/mcp/api_client.rb', line 31

def detail(id)
  get("/deploys/#{id}").merge("endpoint" => @slug)
end

#diff(sha, repo_path: nil) ⇒ Object

Raises:



40
41
42
43
44
# File 'lib/crumb/mcp/api_client.rb', line 40

def diff(sha, repo_path: nil)
  dir = repo_path || @repo_path
  raise Error, "No repo_path configured for endpoint #{@slug}" unless dir
  `git -C #{Shellwords.escape(dir)} show #{Shellwords.escape(sha)} --stat 2>&1`
end

#recent(limit: 20) ⇒ Object



26
27
28
29
# File 'lib/crumb/mcp/api_client.rb', line 26

def recent(limit: 20)
  data = get("/deploys?limit=#{limit}")
  (data["deploys"] || []).map { |d| d.merge("endpoint" => @slug) }
end

#touching(path_prefix, limit: 20) ⇒ Object



35
36
37
38
# File 'lib/crumb/mcp/api_client.rb', line 35

def touching(path_prefix, limit: 20)
  data = get("/deploys?touching=#{URI.encode_uri_component(path_prefix)}&limit=#{limit}")
  (data["deploys"] || []).map { |d| d.merge("endpoint" => @slug) }
end