1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[stormondemand|compute] Add Product APIs

This commit is contained in:
Eric Wong 2013-05-23 21:05:46 +08:00
parent 8d4710f59d
commit 767e18225a
8 changed files with 156 additions and 0 deletions

View file

@ -36,6 +36,8 @@ module Fog
collection :stats
model :template
collection :templates
model :product
collection :products
request_path 'fog/storm_on_demand/requests/compute'
request :clone_server
@ -115,6 +117,12 @@ module Fog
request :list_zones
request :set_default_zone
request :get_product
request :get_product_code
request :list_products
request :get_product_price
request :get_product_starting_price
class Mock
def self.data

View file

@ -0,0 +1,40 @@
require 'fog/core/model'
module Fog
module Compute
class StormOnDemand
class Product < Fog::Model
identity :code
attribute :alias
attribute :capabilities
attribute :categories
attribute :cycle
attribute :default_price
attribute :description
attribute :features
attribute :options
attribute :parent_product
attribute :prices
attribute :related_product
attribute :series
def initialize(attributes={})
super
end
def price(options)
requires :identity
service.get_product_price({:code => identity}.merge!(options)).body
end
def starting_price
requires :identity
service.get_product_starting_price(:code => identity).body['items']
end
end
end
end
end

View file

@ -0,0 +1,28 @@
require 'fog/core/collection'
require 'fog/storm_on_demand/models/compute/product'
module Fog
module Compute
class StormOnDemand
class Products < Fog::Collection
model Fog::Compute::StormOnDemand::Product
def get(product_code)
prod = service.get_product(:code => product_code).body
new(prod)
end
def get_product_code(options)
service.get_product_code(options).body
end
def all(options={})
service.list_products(options).body['items']
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module Compute
class StormOnDemand
class Real
def get_product(options={})
request(
:path => '/Product/details',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module Compute
class StormOnDemand
class Real
def get_product_code(options={})
request(
:path => '/Product/getProductCodeFromPath',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module Compute
class StormOnDemand
class Real
def get_product_price(options={})
request(
:path => '/Product/price',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module Compute
class StormOnDemand
class Real
def get_product_starting_price(options={})
request(
:path => '/Product/startingPrice',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module Compute
class StormOnDemand
class Real
def list_products(options={})
request(
:path => '/Product/list',
:body => Fog::JSON.encode(:params => options)
)
end
end
end
end
end