Class: Clacky::CloudProjectClient

Inherits:
Object
  • Object
show all
Defined in:
lib/clacky/cloud_project_client.rb

Overview

CloudProjectClient - Manages cloud project lifecycle via the OpenClacky API

Handles creating projects, fetching project details (including subscription status and categorized_config), and listing projects in a workspace.

All API calls use the Workspace API Key (clacky_ak_*) from ClackyCloudConfig.

Usage:

client = CloudProjectClient.new("clacky_ak_xxx", base_url: "https://api.clacky.ai")

# Create a new cloud project
result = client.create_project(name: "my-app")
# => { success: true, project: { "id" => "...", "name" => "...", "workspace_id" => "...",
#        "categorized_config" => { "auth" => {...}, "email" => {...}, ... } } }

# Get project details (subscription + categorized_config)
result = client.get_project("019d41be-...")
# => { success: true, project: { "id" => "...", "subscription" => { "status" => "PAID" }, ... } }

# List all projects in workspace
result = client.list_projects
# => { success: true, projects: [ { "id" => "...", "name" => "..." }, ... ] }

On failure, all methods return: { success: false, error: “…” }

Constant Summary collapse

PROJECTS_PATH =
"/openclacky/v1/projects"
REQUEST_TIMEOUT =

seconds

15
OPEN_TIMEOUT =

seconds

5

Instance Method Summary collapse

Constructor Details

#initialize(workspace_api_key, base_url:) ⇒ CloudProjectClient

Returns a new instance of CloudProjectClient.



36
37
38
39
# File 'lib/clacky/cloud_project_client.rb', line 36

def initialize(workspace_api_key, base_url:)
  @workspace_api_key = workspace_api_key.to_s.strip
  @base_url          = base_url.to_s.strip.sub(%r{/+$}, "")
end

Instance Method Details

#create_project(name:) ⇒ Hash

Create a new cloud project with the given name.

Parameters:

  • name (String)

    Project name (typically the local directory name)

Returns:

  • (Hash)

    { success: true, project: … } or { success: false, error: “…” }



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/clacky/cloud_project_client.rb', line 45

def create_project(name:)
  validate_inputs!

  response = connection.post(PROJECTS_PATH) do |req|
    req.headers["Content-Type"] = "application/json"
    req.body = JSON.generate({ name: name.to_s.strip })
  end

  unless response.status == 200
    error_msg = extract_error(response)
    return { success: false, error: "HTTP #{response.status}: #{error_msg}" }
  end

  body = parse_body(response)
  return body_error(body) unless success_code?(body)

  { success: true, project: body["data"] }
rescue Faraday::Error => e
  { success: false, error: "Network error: #{e.message}" }
rescue => e
  { success: false, error: "Unexpected error: #{e.message}" }
end

#get_project(project_id) ⇒ Hash

Get project details including subscription status and categorized_config.

Parameters:

  • project_id (String)

    The cloud project UUID

Returns:

  • (Hash)

    { success: true, project: … } or { success: false, error: “…” }



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/clacky/cloud_project_client.rb', line 72

def get_project(project_id)
  validate_inputs!

  response = connection.get("#{PROJECTS_PATH}/#{project_id}")

  unless response.status == 200
    error_msg = extract_error(response)
    return { success: false, error: "HTTP #{response.status}: #{error_msg}" }
  end

  body = parse_body(response)
  return body_error(body) unless success_code?(body)

  { success: true, project: body["data"] }
rescue Faraday::Error => e
  { success: false, error: "Network error: #{e.message}" }
rescue => e
  { success: false, error: "Unexpected error: #{e.message}" }
end

#list_projectsHash

List all projects in the current workspace.

Returns:

  • (Hash)

    { success: true, projects: […] } or { success: false, error: “…” }



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/clacky/cloud_project_client.rb', line 95

def list_projects
  validate_inputs!

  response = connection.get(PROJECTS_PATH)

  unless response.status == 200
    error_msg = extract_error(response)
    return { success: false, error: "HTTP #{response.status}: #{error_msg}" }
  end

  body = parse_body(response)
  return body_error(body) unless success_code?(body)

  projects = body["data"] || []
  projects = projects["list"] if projects.is_a?(Hash) && projects["list"]

  { success: true, projects: Array(projects) }
rescue Faraday::Error => e
  { success: false, error: "Network error: #{e.message}" }
rescue => e
  { success: false, error: "Unexpected error: #{e.message}" }
end