Class: LocalVault::ApiClient
- Inherits:
-
Object
- Object
- LocalVault::ApiClient
- Defined in:
- lib/localvault/api_client.rb
Overview
HTTP client for the InventList API (vault sync, sharing, public keys).
All requests use Bearer token auth. Timeouts: 10s open, 30s read/write. Network and timeout errors are wrapped as ApiError so callers get a consistent exception type.
Defined Under Namespace
Classes: ApiError
Constant Summary collapse
- BASE_PATH =
"/api/v1"
Instance Method Summary collapse
-
#accept_share(id) ⇒ Hash
Accept a pending vault share.
-
#create_share(vault_name:, recipient_handle:, encrypted_payload:) ⇒ Hash
Create a new vault share for a recipient.
-
#crew_public_keys(site_slug) ⇒ Hash
Fetch public keys for all crew members of a site.
-
#delete_vault(name) ⇒ Hash
Delete a vault from the cloud.
-
#get_public_key(handle) ⇒ Hash
Fetch a user’s X25519 public key by handle.
-
#initialize(token:, base_url: nil) ⇒ ApiClient
constructor
Create a new API client.
-
#list_vaults ⇒ Hash
List all vaults stored in the cloud for the authenticated user.
-
#me ⇒ Hash
Fetch the authenticated user’s profile.
-
#pending_shares ⇒ Hash
List vault shares pending acceptance by the current user.
-
#publish_public_key(public_key_b64) ⇒ Hash
Upload the current user’s X25519 public key to InventList.
-
#pull_vault(name) ⇒ String
Download a vault bundle from the cloud (raw binary).
-
#push_vault(name, blob) ⇒ Hash
Upload a vault bundle to the cloud (raw binary).
-
#revoke_share(id) ⇒ Hash
Revoke (delete) a vault share.
-
#sent_shares(vault_name: nil) ⇒ Hash
List vault shares sent by the current user, optionally filtered by vault.
-
#team_public_keys(team_handle) ⇒ Hash
Fetch public keys for all members of a team.
Constructor Details
Instance Method Details
#accept_share(id) ⇒ Hash
Accept a pending vault share.
104 105 106 |
# File 'lib/localvault/api_client.rb', line 104 def accept_share(id) patch("/vault_shares/#{URI.encode_uri_component(id.to_s)}/accept", {}) end |
#create_share(vault_name:, recipient_handle:, encrypted_payload:) ⇒ Hash
Create a new vault share for a recipient.
91 92 93 94 95 96 97 |
# File 'lib/localvault/api_client.rb', line 91 def create_share(vault_name:, recipient_handle:, encrypted_payload:) post("/vault_shares", { vault_name: vault_name, recipient_handle: recipient_handle, encrypted_payload: encrypted_payload }) end |
#crew_public_keys(site_slug) ⇒ Hash
Fetch public keys for all crew members of a site.
131 132 133 |
# File 'lib/localvault/api_client.rb', line 131 def crew_public_keys(site_slug) get("/sites/#{URI.encode_uri_component(site_slug)}/crew/public_keys") end |
#delete_vault(name) ⇒ Hash
Delete a vault from the cloud.
167 168 169 |
# File 'lib/localvault/api_client.rb', line 167 def delete_vault(name) delete("/vaults/#{URI.encode_uri_component(name)}") end |
#get_public_key(handle) ⇒ Hash
Fetch a user’s X25519 public key by handle.
52 53 54 |
# File 'lib/localvault/api_client.rb', line 52 def get_public_key(handle) get("/users/#{URI.encode_uri_component(handle)}/public_key") end |
#list_vaults ⇒ Hash
List all vaults stored in the cloud for the authenticated user.
139 140 141 |
# File 'lib/localvault/api_client.rb', line 139 def list_vaults get("/vaults") end |
#me ⇒ Hash
Fetch the authenticated user’s profile.
43 44 45 |
# File 'lib/localvault/api_client.rb', line 43 def me get("/me") end |
#pending_shares ⇒ Hash
List vault shares pending acceptance by the current user.
69 70 71 |
# File 'lib/localvault/api_client.rb', line 69 def pending_shares get("/vault_shares/pending") end |
#publish_public_key(public_key_b64) ⇒ Hash
Upload the current user’s X25519 public key to InventList.
61 62 63 |
# File 'lib/localvault/api_client.rb', line 61 def publish_public_key(public_key_b64) put("/profile/public_key", { public_key: public_key_b64 }) end |
#pull_vault(name) ⇒ String
Download a vault bundle from the cloud (raw binary).
158 159 160 |
# File 'lib/localvault/api_client.rb', line 158 def pull_vault(name) request_raw(:get, "/vaults/#{URI.encode_uri_component(name)}") end |
#push_vault(name, blob) ⇒ Hash
Upload a vault bundle to the cloud (raw binary).
149 150 151 |
# File 'lib/localvault/api_client.rb', line 149 def push_vault(name, blob) request_binary(:put, "/vaults/#{URI.encode_uri_component(name)}", blob) end |
#revoke_share(id) ⇒ Hash
Revoke (delete) a vault share.
113 114 115 |
# File 'lib/localvault/api_client.rb', line 113 def revoke_share(id) delete("/vault_shares/#{URI.encode_uri_component(id.to_s)}") end |
#sent_shares(vault_name: nil) ⇒ Hash
List vault shares sent by the current user, optionally filtered by vault.
78 79 80 81 82 |
# File 'lib/localvault/api_client.rb', line 78 def sent_shares(vault_name: nil) path = "/vault_shares/sent" path += "?vault_name=#{URI.encode_uri_component(vault_name)}" if vault_name get(path) end |
#team_public_keys(team_handle) ⇒ Hash
Fetch public keys for all members of a team.
122 123 124 |
# File 'lib/localvault/api_client.rb', line 122 def team_public_keys(team_handle) get("/teams/#{URI.encode_uri_component(team_handle)}/members/public_keys") end |