Class: Woods::Unblocked::Client
- Inherits:
-
Object
- Object
- Woods::Unblocked::Client
- Defined in:
- lib/woods/unblocked/client.rb
Overview
REST client for the Unblocked API v1.
Handles document and collection CRUD with rate limiting, retries, and error handling. Uses Net::HTTP for zero external dependencies.
Constant Summary collapse
- BASE_URL =
'https://getunblocked.com/api/v1'- MAX_RETRIES =
3- DEFAULT_TIMEOUT =
30
Instance Method Summary collapse
-
#create_collection(name:, description:, icon_url: nil) ⇒ Hash
Create a new collection.
-
#delete_document(document_id:) ⇒ Hash
Delete a document by ID.
-
#initialize(api_token:, rate_limiter: RateLimiter.new) ⇒ Client
constructor
A new instance of Client.
-
#list_collections ⇒ Array<Hash>
List all collections.
-
#put_document(collection_id:, title:, body:, uri:) ⇒ Hash
Create or update a document (upsert by URI).
Constructor Details
#initialize(api_token:, rate_limiter: RateLimiter.new) ⇒ Client
Returns a new instance of Client.
32 33 34 35 36 37 |
# File 'lib/woods/unblocked/client.rb', line 32 def initialize(api_token:, rate_limiter: RateLimiter.new) raise ArgumentError, 'api_token is required' if api_token.nil? || api_token.to_s.strip.empty? @api_token = api_token @rate_limiter = rate_limiter end |
Instance Method Details
#create_collection(name:, description:, icon_url: nil) ⇒ Hash
Create a new collection.
65 66 67 68 69 |
# File 'lib/woods/unblocked/client.rb', line 65 def create_collection(name:, description:, icon_url: nil) body = { name: name, description: description } body[:iconUrl] = icon_url if icon_url request(:post, 'collections', body) end |
#delete_document(document_id:) ⇒ Hash
Delete a document by ID.
83 84 85 |
# File 'lib/woods/unblocked/client.rb', line 83 def delete_document(document_id:) request(:delete, "documents/#{document_id}") end |
#list_collections ⇒ Array<Hash>
List all collections.
74 75 76 77 |
# File 'lib/woods/unblocked/client.rb', line 74 def list_collections result = request(:get, 'collections') result['items'] || result['data'] || [result].flatten.compact end |
#put_document(collection_id:, title:, body:, uri:) ⇒ Hash
Create or update a document (upsert by URI).
Documents are unique by ‘uri` across the organization. If a document with the given URI exists, it is updated; otherwise it is created. Documents become available for queries within ~1 minute.
50 51 52 53 54 55 56 57 |
# File 'lib/woods/unblocked/client.rb', line 50 def put_document(collection_id:, title:, body:, uri:) request(:put, 'documents', { collectionId: collection_id, title: title, body: body, uri: uri }) end |