hcloud-ruby
hcloud-ruby copied to clipboard
lib: fetch pricing from API
Pricing is a bit different than the other resource types. It only provides a single API endpoint /pricing
. On this it only returns a single dictionary. All other resource types return an array of resources and have a /<resource>/<id>
endpoint for single resources.
Our concept of <X>
and <X>Resource
classes currently maps to the latter concept.
I tried two different approaches for a user of our client:
Stick to the same concept as closely as possible. This is the one implemented now.
pricing = client.pricings.fetch
expect(pricing.currency).to be_a String
Only use a Pricing
class or forward all calls from PricingResource
to Pricing
.
expect(client.pricing.currency).to be_a String
The second approach in my opinion would be nicer for a user, but had some complications. Without special additions to the code the client will on each call to client.pricing
issue a new API request. This would cause needlessly many API requests if a user checks a few prices. A fix to this would be that the Client
has to cache some information (pricing or pricing resource). Currently, it just creates a new instance of <X>Resource
whenever an attribute is called.
Closes #28