mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[stormondemand|billing] Add Billing service and related APIs
This commit is contained in:
parent
dccc11d7a8
commit
3de8f5c9c4
11 changed files with 243 additions and 0 deletions
23
lib/fog/billing.rb
Normal file
23
lib/fog/billing.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Billing
|
||||
|
||||
def self.[](provider)
|
||||
self.new(:provider => provider)
|
||||
end
|
||||
|
||||
def self.new(attributes)
|
||||
attributes = attributes.dup
|
||||
provider = attributes.delete(:provider).to_s.downcase.to_sym
|
||||
if provider == :stormondemand
|
||||
require 'fog/storm_on_demand/billing'
|
||||
Fog::Billing::StormOnDemand.new(attributes)
|
||||
else
|
||||
raise ArgumentError.new("#{provider} has no billing service")
|
||||
end
|
||||
end
|
||||
|
||||
def self.providers
|
||||
Fog.services[:billing]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -8,6 +8,7 @@ module Fog
|
|||
service(:compute, 'storm_on_demand/compute', 'Compute')
|
||||
service(:storage, 'storm_on_demand/storage', 'Storage')
|
||||
service(:dns, 'storm_on_demand/dns', 'DNS')
|
||||
service(:billing, 'storm_on_demand/billing', 'Billing')
|
||||
|
||||
end
|
||||
end
|
||||
|
|
61
lib/fog/storm_on_demand/billing.rb
Normal file
61
lib/fog/storm_on_demand/billing.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
require 'fog/billing'
|
||||
require 'fog/storm_on_demand'
|
||||
require 'fog/storm_on_demand/shared'
|
||||
|
||||
module Fog
|
||||
module Billing
|
||||
class StormOnDemand < Fog::Service
|
||||
|
||||
requires :storm_on_demand_username, :storm_on_demand_password
|
||||
recognizes :storm_on_demand_auth_url
|
||||
|
||||
model_path 'fog/storm_on_demand/models/billing'
|
||||
model :invoice
|
||||
collection :invoices
|
||||
model :payment
|
||||
collection :payments
|
||||
|
||||
request_path 'fog/storm_on_demand/requests/billing'
|
||||
request :list_invoices
|
||||
request :get_invoice
|
||||
request :next_invoice
|
||||
request :make_payment
|
||||
|
||||
class Mock
|
||||
|
||||
def self.data
|
||||
@data ||= Hash.new
|
||||
end
|
||||
|
||||
def self.reset
|
||||
@data = nil
|
||||
end
|
||||
|
||||
def self.reset_data(keys=data.keys)
|
||||
for key in [*keys]
|
||||
data.delete(key)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
@storm_on_demand_username = options[:storm_on_demand_username]
|
||||
end
|
||||
|
||||
def data
|
||||
self.class.data[@storm_on_demand_username]
|
||||
end
|
||||
|
||||
def reset_data
|
||||
self.class.data.delete(@storm_on_demand_username)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Real
|
||||
|
||||
include Fog::StormOnDemand::RealShared
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
28
lib/fog/storm_on_demand/models/billing/invoice.rb
Normal file
28
lib/fog/storm_on_demand/models/billing/invoice.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Billing
|
||||
class StormOnDemand
|
||||
|
||||
class Invoice < Fog::Model
|
||||
identity :id
|
||||
attribute :accnt
|
||||
attribute :bill_date
|
||||
attribute :due
|
||||
attribute :end_date
|
||||
attribute :lineitem_groups
|
||||
attribute :payments
|
||||
attribute :start_date
|
||||
attribute :status
|
||||
attribute :total
|
||||
attribute :type
|
||||
|
||||
def initialize(attributes={})
|
||||
super
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
30
lib/fog/storm_on_demand/models/billing/invoices.rb
Normal file
30
lib/fog/storm_on_demand/models/billing/invoices.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/storm_on_demand/models/billing/invoice'
|
||||
|
||||
module Fog
|
||||
module Billing
|
||||
class StormOnDemand
|
||||
|
||||
class Invoices < Fog::Collection
|
||||
model Fog::Billing::StormOnDemand::Invoice
|
||||
|
||||
def all(options={})
|
||||
invoices = service.list_invoices(options).body['items']
|
||||
load(invoices)
|
||||
end
|
||||
|
||||
def get(invoice_id)
|
||||
invoice = service.get_invoice(:id => invoice_id).body
|
||||
new(invoice)
|
||||
end
|
||||
|
||||
def next
|
||||
invoice = service.next_invoice.body
|
||||
new(invoice)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fog/storm_on_demand/models/billing/payment.rb
Normal file
17
lib/fog/storm_on_demand/models/billing/payment.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Billing
|
||||
class StormOnDemand
|
||||
|
||||
class Payment < Fog::Model
|
||||
|
||||
def initialize(attributes={})
|
||||
super
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
19
lib/fog/storm_on_demand/models/billing/payments.rb
Normal file
19
lib/fog/storm_on_demand/models/billing/payments.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/storm_on_demand/models/billing/payment'
|
||||
|
||||
module Fog
|
||||
module Billing
|
||||
class StormOnDemand
|
||||
|
||||
class Payments < Fog::Collection
|
||||
model Fog::Billing::StormOnDemand::Payment
|
||||
|
||||
def make(amount, card_code)
|
||||
service.make_payment(:amount => amount,
|
||||
:card_code => card_code).body['amount']
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
16
lib/fog/storm_on_demand/requests/billing/get_invoice.rb
Normal file
16
lib/fog/storm_on_demand/requests/billing/get_invoice.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
module Fog
|
||||
module Billing
|
||||
class StormOnDemand
|
||||
class Real
|
||||
|
||||
def get_invoice(options={})
|
||||
request(
|
||||
:path => '/Billing/Invoice/details',
|
||||
:body => Fog::JSON.encode(:params => options)
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
16
lib/fog/storm_on_demand/requests/billing/list_invoices.rb
Normal file
16
lib/fog/storm_on_demand/requests/billing/list_invoices.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
module Fog
|
||||
module Billing
|
||||
class StormOnDemand
|
||||
class Real
|
||||
|
||||
def list_invoices(options={})
|
||||
request(
|
||||
:path => '/Billing/Invoice/list',
|
||||
:body => Fog::JSON.encode(:params => options)
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
16
lib/fog/storm_on_demand/requests/billing/make_payment.rb
Normal file
16
lib/fog/storm_on_demand/requests/billing/make_payment.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
module Fog
|
||||
module Billing
|
||||
class StormOnDemand
|
||||
class Real
|
||||
|
||||
def make_payment(options={})
|
||||
request(
|
||||
:path => '/Billing/Payment/make',
|
||||
:body => Fog::JSON.encode(:params => options)
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
16
lib/fog/storm_on_demand/requests/billing/next_invoice.rb
Normal file
16
lib/fog/storm_on_demand/requests/billing/next_invoice.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
module Fog
|
||||
module Billing
|
||||
class StormOnDemand
|
||||
class Real
|
||||
|
||||
def next_invoice(options={})
|
||||
request(
|
||||
:path => '/Billing/Invoice/next',
|
||||
:body => Fog::JSON.encode(:params => options)
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue