octaspace 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +105 -14
  3. data/LICENSE +21 -0
  4. data/README.md +104 -285
  5. data/lib/octaspace/client.rb +40 -23
  6. data/lib/octaspace/configuration.rb +73 -14
  7. data/lib/octaspace/errors.rb +75 -18
  8. data/lib/octaspace/json_null.rb +56 -0
  9. data/lib/octaspace/middleware/url_rotator.rb +3 -3
  10. data/lib/octaspace/model.rb +115 -0
  11. data/lib/octaspace/money.rb +69 -0
  12. data/lib/octaspace/railtie.rb +1 -2
  13. data/lib/octaspace/resources/accounts.rb +8 -20
  14. data/lib/octaspace/resources/base.rb +49 -2
  15. data/lib/octaspace/resources/compute.rb +123 -0
  16. data/lib/octaspace/resources/hosting.rb +107 -0
  17. data/lib/octaspace/resources/network.rb +24 -5
  18. data/lib/octaspace/resources/render.rb +46 -0
  19. data/lib/octaspace/resources/sessions.rb +125 -10
  20. data/lib/octaspace/resources/stats.rb +57 -0
  21. data/lib/octaspace/resources/vpn.rb +48 -0
  22. data/lib/octaspace/response.rb +62 -12
  23. data/lib/octaspace/transport/base.rb +30 -30
  24. data/lib/octaspace/transport/faraday_transport.rb +157 -91
  25. data/lib/octaspace/transport/persistent_transport.rb +23 -49
  26. data/lib/octaspace/types/account.rb +17 -4
  27. data/lib/octaspace/types/hosting.rb +116 -0
  28. data/lib/octaspace/types/machines.rb +158 -0
  29. data/lib/octaspace/types/network.rb +87 -0
  30. data/lib/octaspace/types/session.rb +173 -4
  31. data/lib/octaspace/types/stats.rb +143 -0
  32. data/lib/octaspace/version.rb +1 -1
  33. data/lib/octaspace.rb +21 -18
  34. metadata +30 -34
  35. data/MIT-LICENSE +0 -22
  36. data/lib/octaspace/resources/apps.rb +0 -19
  37. data/lib/octaspace/resources/idle_jobs.rb +0 -32
  38. data/lib/octaspace/resources/nodes.rb +0 -63
  39. data/lib/octaspace/resources/services/machine_rental.rb +0 -48
  40. data/lib/octaspace/resources/services/render.rb +0 -30
  41. data/lib/octaspace/resources/services/session_proxy.rb +0 -49
  42. data/lib/octaspace/resources/services/vpn.rb +0 -30
  43. data/lib/octaspace/resources/services.rb +0 -39
  44. data/lib/octaspace/types/balance.rb +0 -11
  45. data/lib/octaspace/types/node.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9dd2b5c9ae96cbc0bef9e36fd492b2a1dbdcf53af596a82193986039ff8a4da9
4
- data.tar.gz: b0f0a7a1a3301be4f3d1dbe33f60652fc5c9e4b36e709779076d374fb0e16ff4
3
+ metadata.gz: f25e5f1a46bb6780c2ddc35b1641d001a91e8846f74d6714711be25d4facf034
4
+ data.tar.gz: ff9fa708b0a95f2d32df623e823c474b7d30e4c8c298dd57c013a1bdc03a7c98
5
5
  SHA512:
6
- metadata.gz: 59cb1140ec7e34939b2535857d4d7afd395b8b25d45ac69df2c14c524bd1e14503f969704299fe6aa3d51021fa2491a8f00d0cf4dee3a3d848308a9aa9fb577d
7
- data.tar.gz: 6b4353b1524bae1e594ef4109a93a371e539d48b157dcdd4e165a1283c60e4a86e719818f62276d3cac2628e4bf9cd419b651f5a4633302d391e3d5fc41f476d
6
+ metadata.gz: a15f98cfb00b8646fadc39f342f126e97f52ffbf399acfd59be64afcdd718bb5a46f7c58578f1ecaa6d80551f3c97193fa0e8c594a05f99f6336d6afe74e5186
7
+ data.tar.gz: 85fe51b96d0c7e2ed579d12d25f0640a37946caa4d13d7267edcbadecda1f5e0a2044e185b7fca3d54348727e56d1cdea889b859acac912cd5aa95d3d30f023c
data/CHANGELOG.md CHANGED
@@ -1,22 +1,113 @@
1
1
  # Changelog
2
2
 
3
- All notable changes to this project will be documented in this file.
3
+ All notable changes to this project are documented in this file.
4
4
 
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.3.0] - 2026-11-27
9
+
10
+ The SDK follows the current OctaSpace API. Most resources changed; see the
11
+ [resources](docs/resources.md) and [sessions](docs/sessions.md) guides.
12
+
13
+ ### Added
14
+
15
+ - `client.compute`: `list`, `apps`, `start`, `start_batch` and `restart`.
16
+ - `client.vpn`: `list` and `start` (WireGuard, AmneziaWG, VLESS Reality and
17
+ HTTP proxy).
18
+ - `client.render`: `list`, `start` and `start_batch`.
19
+ - `client.sessions`: `get`, `logs`, `stop`, `wait_ready` and `wait_stopped`;
20
+ VPN sessions.
21
+ - `client.hosting`: `nodes`, `get`, `set_prices`, `start_maintenance` and
22
+ `end_maintenance`.
23
+ - `client.network.history`, with `points`.
24
+ - `client.stats`: `gpu_current`, `gpu_history`, `gpu_locations` and `mining`.
25
+ - Read-only response models under `OctaSpace::Types`, with `[]`, `to_h` and
26
+ pattern matching.
27
+ - `OctaSpace::Money` for amounts in micro-USD.
28
+ - `ConflictError` (HTTP 409), `SessionStoppedError` and `WaitTimeoutError`.
29
+ - `retry_after`, `rate_limit` and `body` on `ApiError`, and `client.rate_limit`.
30
+ - The `max_retry_after` and `max_retry_interval` options.
31
+ - `OctaSpace::DEFAULT_BASE_URL` constant.
32
+ - The `OCTA_API_KEY` and `OCTA_API_URL` environment variables set the default
33
+ API key and host.
34
+ - Guides under `docs/`.
35
+
36
+ ### Changed
37
+
38
+ - **Breaking:** the API key is sent as `Authorization: Bearer <key>`. A key
39
+ that already has the `Bearer ` prefix is accepted.
40
+ - **Breaking:** the SDK works with the current OctaSpace API at
41
+ `https://api.octa.space` (`DEFAULT_BASE_URL`).
42
+ - **Breaking:** nodes are identified by their node number, for example
43
+ `7KQ4-M2XD-4`.
44
+ - **Breaking:** prices, charges and the balance are integer micro-USD.
45
+ - **Breaking:** resource methods return models, session UUIDs or `nil` instead
46
+ of `OctaSpace::Response`.
47
+ - **Breaking:** `sessions.list` takes no parameters and returns running
48
+ sessions only.
49
+ - **Breaking:** HTTP 400 raises `ValidationError`, and the error message is the
50
+ API's message.
51
+ - **Breaking:** only GET requests, `sessions.stop` and node maintenance are
52
+ retried; starting and restarting sessions and setting prices are never
53
+ retried. A `Retry-After` longer than 60 seconds raises the error at once.
54
+ - **Breaking:** a method that needs an API key raises `AuthenticationError`
55
+ before sending a request when none is configured.
56
+ - **Breaking:** an unknown parameter raises `ArgumentError` before the request
57
+ is sent.
58
+ - Every request carries the `X-OCTA-APP: ruby-sdk` header.
59
+ - **Breaking:** `on_request` no longer receives the request headers. The log
60
+ never contains headers or bodies.
61
+ - **Breaking:** requires Ruby 3.3 or later and Faraday 2.14.3 or later;
62
+ `faraday-retry` is no longer a dependency.
63
+
64
+ ### Removed
65
+
66
+ - **Breaking:** `client.nodes`, `client.apps`, `client.idle_jobs`,
67
+ `client.services`, `accounts.profile` and `accounts.generate_wallet`, with
68
+ their types. Hosted nodes and their prices are in `client.hosting`, sessions
69
+ in `client.sessions`.
70
+ - **Breaking:** `ProvisionRejectedError`, `PayloadHelpers`,
71
+ `Transport::MockTransport`, the `OctaSpace::Engine` playground and the
72
+ `persistent` configuration alias of `keep_alive`.
73
+
74
+ ## [0.2.0] - 2026-04-16
75
+
76
+ ### Added
77
+
78
+ - `client.services.session(uuid).logs(recent: true)` for the logs of a finished
79
+ session.
80
+ - `OctaSpace::ProvisionRejectedError` for machine rental requests that the API
81
+ accepts but rejects in the response body.
82
+ - `OctaSpace::PayloadHelpers` for app port lists sent as strings and for
83
+ marketplace bandwidth values.
84
+
85
+ ### Changed
86
+
87
+ - `services.mr.list`, `services.render.list` and `services.vpn.list` return
88
+ the marketplace catalog, not sessions.
89
+ - `services.mr.create` passes the optional `organization_id` and `project_id`.
90
+
91
+ ### Fixed
92
+
93
+ - `services.mr.create` raises `ProvisionRejectedError` for a rejection returned
94
+ with HTTP 200.
7
95
 
8
96
  ## [0.1.0] - 2026-04-12
9
97
 
98
+ First release.
99
+
10
100
  ### Added
11
101
 
12
- - Initial release of the official OctaSpace Ruby SDK.
13
- - Support for core resources: Accounts, Nodes, Sessions, Apps, Network, and Idle Jobs.
14
- - Resource-oriented client: `client.nodes.list`, `client.services.session(uuid).stop`.
15
- - Persistent HTTP connections (keep-alive mode) via `ConnectionPool`.
16
- - Automatic URL rotation and failover for high availability.
17
- - Retry with exponential backoff and jitter for transient errors.
18
- - Typed error hierarchy based on HTTP status codes.
19
- - Rails integration with automatic client sharing and graceful shutdown.
20
- - Interactive Playground app for manual testing and diagnostics.
21
-
22
- [0.1.0]: https://github.com/octaspace/ruby-sdk/compare/v0.1.0...HEAD
102
+ - `OctaSpace::Client` and `OctaSpace.configure`, with accounts, nodes,
103
+ sessions, apps, network, idle jobs and services resources.
104
+ - Persistent HTTP connections with a connection pool (`keep_alive`).
105
+ - Failover between several base URLs.
106
+ - Retries with exponential backoff and jitter for transient errors.
107
+ - Typed errors mapped from HTTP status codes.
108
+ - Rails integration: a shared client that is shut down when the process exits.
109
+ - A playground Rails engine for trying the API.
110
+
111
+ [0.3.0]: https://github.com/octaspace/ruby-sdk/compare/v0.2.0...v0.3.0
112
+ [0.2.0]: https://github.com/octaspace/ruby-sdk/compare/v0.1.0...v0.2.0
113
+ [0.1.0]: https://github.com/octaspace/ruby-sdk/releases/tag/v0.1.0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OctaSpace
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,336 +1,155 @@
1
- # octaspace
1
+ # OctaSpace Ruby SDK
2
2
 
3
3
  [![Gem Version](https://img.shields.io/gem/v/octaspace)](https://rubygems.org/gems/octaspace)
4
4
  [![CI](https://github.com/octaspace/ruby-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/octaspace/ruby-sdk/actions/workflows/ci.yml)
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](MIT-LICENSE)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
6
 
7
- Official Ruby SDK for the [OctaSpace API](https://api.octa.space/api-docs).
7
+ The official Ruby library for the [OctaSpace](https://octa.space) API. Rent
8
+ compute machines, render nodes and VPN, manage sessions and the nodes you host,
9
+ and read platform, GPU market and mining statistics from Ruby code.
8
10
 
9
- ## Features
10
-
11
- - **Resource-oriented API** — `client.nodes.list`, `client.services.session(uuid).stop`
12
- - **Keep-alive mode** — persistent connections via `faraday-net_http_persistent` + `connection_pool`
13
- - **URL rotation / failover** — round-robin across multiple endpoints with per-URL cooldown
14
- - **Retry with exponential backoff + jitter** — configurable retries on transient failures
15
- - **Typed error hierarchy** — 12 exception classes mapped from HTTP status codes
16
- - **`on_request` / `on_response` hooks** — for logging, tracing, APM
17
- - **Rails integration** — Railtie, shared client, graceful shutdown at_exit
18
- - **Playground app** — `bin/playground` with live diagnostics page
19
- - **Ruby ≥ 3.2**, Rails 7.1 / 7.2 / 8.0
11
+ **Contents:** [Installation](#installation) ·
12
+ [Quick start](#quick-start) · [Authentication](#authentication) ·
13
+ [Handling errors](#handling-errors) · [API overview](#api-overview) ·
14
+ [Documentation](#documentation) · [Versioning](#versioning)
20
15
 
21
16
  ## Installation
22
17
 
23
- ```ruby
24
- # Gemfile
25
- gem "octaspace"
26
-
27
- # Optional — required for keep_alive: true
28
- gem "faraday-net_http_persistent"
29
- gem "connection_pool"
30
- ```
31
-
32
- ```ruby
33
- bundle install
18
+ ```bash
19
+ bundle add octaspace
34
20
  ```
35
21
 
36
- ## Quick Start
22
+ Requires Ruby 3.3 or later. The only runtime dependency is
23
+ [Faraday](https://github.com/lostisland/faraday).
37
24
 
38
- ```ruby
39
- require "octaspace"
25
+ ## Quick start
40
26
 
41
- # Public endpoints (no API key required)
42
- client = OctaSpace::Client.new
43
- client.network.info # GET /network
27
+ 1. [Create an API key](#authentication) and export it:
44
28
 
45
- # Authenticated endpoints
46
- client = OctaSpace::Client.new(api_key: ENV["OCTA_API_KEY"])
29
+ ```bash
30
+ export OCTA_API_KEY="octa_ak_..."
31
+ ```
47
32
 
48
- # Accounts
49
- client.accounts.profile # GET /accounts
50
- client.accounts.balance # GET /accounts/balance
51
-
52
- # Nodes
53
- client.nodes.list # GET /nodes
54
- client.nodes.find(123) # GET /nodes/:id
55
- client.nodes.reboot(123) # GET /nodes/:id/reboot
56
- client.nodes.update_prices(123, gpu_hour: 0.5) # PATCH /nodes/:id/prices
57
-
58
- # Sessions (list)
59
- client.sessions.list # GET /sessions
60
-
61
- # Session proxy — operations on a specific session
62
- session = client.services.session("uuid-here")
63
- session.info # GET /services/:uuid/info
64
- session.logs # GET /services/:uuid/logs
65
- session.stop(score: 5) # POST /services/:uuid/stop
66
-
67
- # Services
68
- client.services.mr.list # GET /services/mr
69
- client.services.mr.create(
70
- node_id: 1,
71
- disk_size: 10,
72
- image: "ubuntu:24.04",
73
- app: "249b4cb3-3db1-4c06-98a4-772ba88cd81c"
74
- ) # POST /services/mr
75
- client.services.vpn.list # GET /services/vpn
76
- client.services.vpn.create(node_id: 1, subkind: "wg") # POST /services/vpn
77
- client.services.render.list # GET /services/render
78
- client.services.render.create(node_id: 1, disk_size: 100) # POST /services/render
79
-
80
- # Apps
81
- client.apps.list # GET /apps
82
-
83
- # Network
84
- client.network.info # GET /network
85
-
86
- # Idle Jobs
87
- client.idle_jobs.find(node_id: 69, job_id: 42) # GET /idle_jobs/:node_id/:job_id
88
- client.idle_jobs.logs(node_id: 69, job_id: 42) # GET /idle_jobs/:node_id/:job_id/logs
89
- ```
33
+ 2. Run this program:
90
34
 
91
- ## Rails Integration
35
+ ```ruby
36
+ require "octaspace"
92
37
 
93
- ### Initializer
38
+ client = OctaSpace::Client.new(api_key: ENV["OCTA_API_KEY"])
94
39
 
95
- ```ruby
96
- # config/initializers/octaspace.rb
97
- OctaSpace.configure do |config|
98
- config.api_key = ENV["OCTA_API_KEY"]
99
- config.keep_alive = true
100
- config.pool_size = ENV.fetch("RAILS_MAX_THREADS", 5).to_i
101
- config.logger = Rails.logger
102
- end
103
- ```
40
+ begin
41
+ balance = client.accounts.balance
42
+ puts "Balance: #{balance.formatted}" # Balance: $12.500000
104
43
 
105
- ### Shared client
44
+ client.compute.list.each do |m|
45
+ puts "#{m.node_number} #{m.city} #{OctaSpace::Money.format(m.base_price)} per hour"
46
+ end
47
+ rescue OctaSpace::Error => e
48
+ abort e.message
49
+ end
50
+ ```
106
51
 
107
- `OctaSpace.client` (called without arguments) returns a **lazily-initialized shared client** built from global configuration. It is safe to call it on every request:
52
+ Create one client and reuse it: it is safe to share between threads.
108
53
 
109
- ```ruby
110
- # app/controllers/application_controller.rb
111
- def octa_client
112
- OctaSpace.client # returns the same instance each time — no new connections
113
- end
114
- ```
54
+ ## Authentication
115
55
 
116
- Pass arguments to create a **one-off client** instead (e.g., for per-user API keys):
56
+ The SDK authenticates with an **API key** of your OctaSpace account. You create
57
+ and delete API keys in the OctaSpace dashboard:
117
58
 
118
- ```ruby
119
- OctaSpace.client(api_key: current_user.octa_api_key) # new client, not cached
120
- ```
59
+ 1. Sign in to the [OctaSpace dashboard](https://console.octa.space).
60
+ 2. In the sidebar, open **Account → Credentials**.
61
+ 3. In the **API Keys** section, click **Add API Key**.
62
+ 4. Enter a **Label** that tells you where the key is used, for example
63
+ `billing-service`, and click **Create key**.
64
+ 5. Copy the key. It starts with `octa_ak_`. You can copy it again later from
65
+ the **API Keys** list.
121
66
 
122
- ### Graceful shutdown
123
-
124
- The Railtie registers an `at_exit` hook that automatically shuts down the shared client's connection pool when the Rails process stops. No manual cleanup needed.
125
-
126
- ## Configuration Reference
127
-
128
- | Option | Default | Description |
129
- |---|---|---|
130
- | `api_key` | `nil` | API key sent as `Authorization` header (optional for public endpoints) |
131
- | `base_url` | `https://api.octa.space` | Single API endpoint |
132
- | `base_urls` | `nil` | Multiple endpoints — enables URL rotation |
133
- | `keep_alive` | `false` | Persistent HTTP connections + pool |
134
- | `pool_size` | `5` | Connection pool size (keep-alive mode) |
135
- | `pool_timeout` | `5` | Seconds to wait for a pool slot |
136
- | `idle_timeout` | `60` | Seconds before an idle connection closes |
137
- | `open_timeout` | `10` | Seconds to open TCP connection |
138
- | `read_timeout` | `30` | Seconds to read response |
139
- | `write_timeout` | `30` | Seconds to write request body |
140
- | `max_retries` | `2` | Retry attempts on transient failures |
141
- | `retry_interval` | `0.5` | Base retry interval in seconds |
142
- | `backoff_factor` | `2.0` | Exponential backoff multiplier |
143
- | `ssl_verify` | `true` | Verify SSL certificates |
144
- | `on_request` | `nil` | `callable(req_hash)` — before each request |
145
- | `on_response` | `nil` | `callable(response)` — after each response |
146
- | `logger` | `nil` | Ruby `Logger` instance |
147
- | `log_level` | `:info` | Log level |
148
- | `user_agent` | auto | `User-Agent` header value |
149
-
150
- `persistent` is an alias for `keep_alive` for compatibility with Cube internals.
151
-
152
- ## Keep-Alive Mode
153
-
154
- Requires `faraday-net_http_persistent` and `connection_pool` in your Gemfile.
67
+ Pass the key to `OctaSpace::Client.new`, or set the `OCTA_API_KEY` environment
68
+ variable: a client created without `api_key:` reads it. The SDK sends the key in
69
+ the `Authorization: Bearer <key>` header.
155
70
 
156
71
  ```ruby
157
- client = OctaSpace::Client.new(
158
- api_key: ENV["OCTA_API_KEY"],
159
- keep_alive: true,
160
- pool_size: ENV.fetch("RAILS_MAX_THREADS", 5).to_i,
161
- idle_timeout: 120
162
- )
163
-
164
- # Diagnostics
165
- client.transport_stats
166
- # => { mode: :persistent, pools: { "https://api.octa.space" => { size: 5, available: 4 } } }
167
-
168
- # Explicit shutdown (optional — Railtie does this automatically in Rails)
169
- client.shutdown
72
+ client = OctaSpace::Client.new(api_key: ENV["OCTA_API_KEY"])
170
73
  ```
171
74
 
172
- ## URL Rotation / Failover
75
+ > [!WARNING]
76
+ > An API key acts on behalf of your account: it can start sessions that are
77
+ > charged to your balance. Keep it out of source code and version control. If
78
+ > a key leaks, delete it under **Account → Credentials → API Keys**; every
79
+ > program that uses it stops working at once.
173
80
 
174
- ```ruby
175
- client = OctaSpace::Client.new(
176
- api_key: ENV["OCTA_API_KEY"],
177
- base_urls: ["https://api.octa.space", "https://api2.octa.space"]
178
- )
179
- ```
81
+ The **API Keys** list shows each key's label, its first characters and when it
82
+ was last used. Use a separate key for each program or machine, so that you can
83
+ delete one without affecting the others. The number of keys per account is
84
+ limited; the counter next to **API Keys** shows how many you have.
180
85
 
181
- - Requests are distributed round-robin across healthy endpoints.
182
- - If an endpoint raises a connection or timeout error, it enters a **30-second cooldown** and traffic shifts to the remaining endpoints.
183
- - After cooldown, the endpoint is re-admitted automatically.
86
+ ### Calls without an API key
184
87
 
185
- ## Hooks
88
+ These methods also work without an API key. To call them without one, create
89
+ the client with `api_key: ""` (or without `api_key:` when `OCTA_API_KEY` is not
90
+ set):
186
91
 
187
- ```ruby
188
- OctaSpace.configure do |config|
189
- config.on_request = ->(req) { Rails.logger.debug "→ #{req[:method].upcase} #{req[:path]}" }
190
- config.on_response = ->(resp) { Rails.logger.debug "← #{resp.status} (#{resp.request_id})" }
191
- end
192
- ```
92
+ | Method | Without a key |
93
+ | --- | --- |
94
+ | `network.info`, `network.history` | Same result |
95
+ | `stats.gpu_current`, `stats.gpu_history`, `stats.gpu_locations`, `stats.mining` | Same result |
96
+ | `compute.list`, `render.list`, `vpn.list` | Refreshed about once an hour instead of every 10 seconds |
97
+ | `compute.apps` | Official apps only, without your own |
98
+
99
+ Every other method requires an API key and raises
100
+ `OctaSpace::AuthenticationError` without one, before any request is sent.
193
101
 
194
- `on_request` receives `{ method:, path:, params: }`.
195
- `on_response` receives an `OctaSpace::Response` instance.
102
+ ## Handling errors
196
103
 
197
- ## Error Handling
104
+ Every error the SDK raises is an `OctaSpace::Error`. Rescue the specific class
105
+ you can handle:
198
106
 
199
107
  ```ruby
200
108
  begin
201
- client.nodes.find(999_999)
202
- rescue OctaSpace::NotFoundError => e
203
- puts "Not found — request_id: #{e.request_id}"
109
+ uuid = client.compute.start(node_number: "7KQ4-M2XD-4", image: "ubuntu:24.04")
204
110
  rescue OctaSpace::AuthenticationError
205
- puts "Invalid API key"
111
+ # the API key is missing, wrong or deleted
112
+ rescue OctaSpace::ValidationError => e
113
+ # the request was rejected; e.message says why
206
114
  rescue OctaSpace::RateLimitError => e
207
- sleep e.retry_after
208
- retry
209
- rescue OctaSpace::ConnectionError, OctaSpace::TimeoutError => e
210
- puts "Network error: #{e.message}"
211
- rescue OctaSpace::Error => e
212
- puts "API error #{e.status}: #{e.message}"
115
+ # too many requests; wait e.retry_after seconds
213
116
  end
214
117
  ```
215
118
 
216
- ### Error hierarchy
217
-
218
- ```
219
- OctaSpace::Error
220
- ├── ConfigurationError — missing gems, invalid config
221
- ├── NetworkError — no HTTP response received
222
- │ ├── ConnectionError — TCP connection refused / failed
223
- │ └── TimeoutError — open/read timeout
224
- └── ApiError — HTTP response received with error status
225
- ├── AuthenticationError 401
226
- ├── PermissionError 403
227
- ├── NotFoundError 404
228
- ├── ValidationError 422
229
- ├── RateLimitError 429 → #retry_after (seconds)
230
- └── ServerError 5xx
231
- ├── BadGatewayError 502
232
- ├── ServiceUnavailableError 503
233
- └── GatewayTimeoutError 504
234
- ```
235
-
236
- All `ApiError` subclasses expose:
119
+ See [Errors, rate limits and retries](docs/errors-and-reliability.md).
237
120
 
238
- - `#status` — HTTP status code
239
- - `#request_id` — value of `X-Request-Id` response header
240
- - `#response` — the raw `OctaSpace::Response` object
121
+ ## API overview
241
122
 
242
- ## Types (Value Objects)
123
+ | Resource | Dashboard section | Operations | Guide |
124
+ | --- | --- | --- | --- |
125
+ | `client.compute` | Marketplace → Compute, Applications | List machines and apps, start, batch start, restart | [Compute](docs/resources.md#compute) |
126
+ | `client.vpn` | Marketplace → VPN | List VPN nodes, start | [VPN](docs/resources.md#vpn) |
127
+ | `client.render` | Render → Launch Nodes | List render nodes, start, batch start | [Render](docs/resources.md#render) |
128
+ | `client.sessions` | Marketplace → Sessions, Render → Render Nodes | List, get, logs, stop, wait until ready or stopped | [Sessions](docs/sessions.md) |
129
+ | `client.hosting` | Hosting → Nodes | Your nodes, one node, set prices, maintenance | [Hosting](docs/resources.md#hosting) |
130
+ | `client.accounts` | Account → Billing | Balance | [Accounts](docs/resources.md#accounts) |
131
+ | `client.network` | — | Platform statistics now and over time | [Network](docs/resources.md#network) |
132
+ | `client.stats` | Marketplace → Mining | GPU market: current, history, locations; mining | [Stats](docs/resources.md#stats) |
243
133
 
244
- The `OctaSpace::Types` namespace provides immutable `Data.define` value objects for domain entities. They are **not** returned by default — resources return raw `response.data` (Hash/Array). Use them explicitly when you want structured objects:
134
+ Every class and method is documented on
135
+ [RubyDoc.info](https://rubydoc.info/gems/octaspace).
245
136
 
246
- ```ruby
247
- response = client.nodes.find(123)
248
- node = OctaSpace::Types::Node.new(**response.data.transform_keys(&:to_sym))
249
-
250
- node.online? # => true / false
251
- node.state # => "online"
252
- node.id # => 123
253
- ```
254
-
255
- Available types: `Node`, `Account`, `Balance`, `Session`.
256
-
257
- ## Playground App
258
-
259
- Interactive demo for manual testing against a real API key:
260
-
261
- ```bash
262
- OCTA_API_KEY=your_key bin/playground
263
- # → http://localhost:3000
264
- ```
265
-
266
- Pages:
267
-
268
- | Route | Content |
269
- |---|---|
270
- | `/playground/account` | Profile + balance |
271
- | `/playground/nodes` | Node list with state badges |
272
- | `/playground/sessions` | Active sessions |
273
- | `/playground/services` | Machine Rentals + VPN sessions |
274
- | `/playground/diagnostics` | Transport mode, pool stats, URL rotator state (auto-refresh every 5s) |
275
-
276
- ## Development
277
-
278
- ### Gem Development
279
-
280
- ```bash
281
- bin/console # IRB with gem loaded
282
- bundle exec standardrb # lint (StandardRB)
283
- bundle exec rake test # tests only
284
- ```
285
-
286
- ### Local Standalone Testing
287
-
288
- You can verify the gem in a clean Ruby environment without Rails:
289
-
290
- 1. Build the gem: `gem build octaspace.gemspec`
291
- 2. Install it locally: `gem install ./octaspace-0.1.0.gem`
292
- 3. Test in IRB:
293
-
294
- ```ruby
295
- irb
296
- > require 'octaspace'
297
- > client = OctaSpace::Client.new # Test public endpoints
298
- > client.network.info
299
- > client_auth = OctaSpace::Client.new(api_key: "token") # Test authenticated client
300
- > client_auth.accounts.profile.data # Retrieving profile data (email, ID, etc.)
301
- ```
302
-
303
- ### Running tests against multiple Rails versions
304
-
305
- ```bash
306
- bundle exec appraisal rails-7-1 rake test
307
- bundle exec appraisal rails-7-2 rake test
308
- bundle exec appraisal rails-8-0 rake test
309
- ```
310
-
311
- ### Dummy Application (Playground)
312
-
313
- The repository includes a Rails "Dummy" application for manual testing and UI prototyping. It is located in `test/dummy`.`.
314
-
315
- To run the dummy app:
316
-
317
- 1. Ensure you have an API key: `export OCTA_API_KEY=your_key`
318
- 2. Run the playground script: `bin/playground` (starts Puma on port 3000)
319
- 3. Visit `http://localhost:3000/playground/diagnostics`
320
-
321
- You can also run it manually from the directory:
322
-
323
- ```bash
324
- cd test/dummy
325
- bin/rails server
326
- ```
137
+ ## Documentation
327
138
 
328
- The dummy app is configured to use the local version of the gem. It is **not** included in the published gem package.
139
+ | Guide | Covers |
140
+ | --- | --- |
141
+ | [Client configuration](docs/getting-started.md) | Options and defaults, timeouts, logging, Rails, keep-alive connections |
142
+ | [Resources](docs/resources.md) | Compute, VPN, render, hosting, balance, network, GPU and mining statistics |
143
+ | [Sessions](docs/sessions.md) | Waiting until ready, connecting, logs, stopping |
144
+ | [Errors, rate limits and retries](docs/errors-and-reliability.md) | Error classes, limits, automatic retries |
145
+ | [Changelog](CHANGELOG.md) | Changes in each release |
329
146
 
330
- ## Packaging and Publishing
147
+ ## Versioning
331
148
 
332
- See [PUBLISHING.md](PUBLISHING.md) for instructions on how to package and release new versions of the gem.
149
+ The library follows [Semantic Versioning](https://semver.org). Until version
150
+ 1.0, a minor release can contain breaking changes; the
151
+ [changelog](CHANGELOG.md) marks them as **Breaking**.
333
152
 
334
153
  ## License
335
154
 
336
- [MIT](MIT-LICENSE) © OctaSpace Team
155
+ [MIT](LICENSE)