How DropletKit resources and actions work
mainDropletKit uses a resource-oriented design where API endpoints are accessed as methods on the client instance.
- Resource Access: Calling a resource method (e.g.,
client.droplets) returns a resource object (e.g.,DropletKit::DropletResource). - Lazy Execution: For actions returning multiple objects, the API request is not executed until the result is accessed (e.g., by calling
.allor.first). - Data Objects: The client returns Plain Old Ruby Objects (POROs) containing API data.
- Persistence: To save or create objects, you must instantiate the appropriate data object and pass it to the resource's action method.
client = DropletKit::Client.new(access_token: 'YOUR_TOKEN')
# Lazy loading example
client.droplets.all.first
# Creation example
droplet = DropletKit::Droplet.new(name: 'mysite.com', region: 'nyc2', image: 'ubuntu-14-04-x64', size: 's-1vcpu-1gb')
created = client.droplets.create(droplet)