class OnappMarket::Supply

Supplier Side OnApp Market API

This is the API used by Supplier to provide resources to the OnApp Market, and subsequently control those resources.

Assumptions

It is assumed that any user of this API will have

Attributes

api[RW]

API used to manage this resource

Public Class Methods

new(api) click to toggle source

Create a new instance of Supplier API

Attributes

  • api - The API to communicate over

# File lib/onapp_market/supply.rb, line 24
def initialize(api)
  raise "No OnAppMarket API specified" if api == nil
  @api = api
end

Public Instance Methods

create_resource(resource, pricing) click to toggle source

Create a resource on the OnApp Market.

Attributes

Returns

Roles

supplier, admin

# File lib/onapp_market/supply.rb, line 40
def create_resource(resource, pricing)
  # Create params for post as a Hash
  data = {"resource" => OnappMarket::API::Serialize.to_hash(resource),
          "pricing" => OnappMarket::API::Serialize.to_hash(pricing)}
  # Post - will de-serialize and return response
  @api.post("/resource", data)
end
get_instance_billing_data(instance_id, start_date, end_date, period = :daily) click to toggle source

Get the billing statistics for an instance for a given time period

Attributes

  • instance_id - instance id of instance whose billing data we require

  • start_date - Date - start date

  • end_date - Date - end date

  • period - Billing period: hourly|daily|monthly

Returns

Roles

supplier, admin

# File lib/onapp_market/supply.rb, line 100
def get_instance_billing_data(instance_id, start_date, end_date, period = :daily)
  @api.get("/instance/#{instance_id.url_safe}/billing", {:start => start_date.rfc3339, :end => end_date.rfc3339, :period => period.to_s})
end
get_resource(resource_id) click to toggle source

Get a resource

Attributes

  • resource_id - The resource id

Returns

Roles

supplier, admin

# File lib/onapp_market/supply.rb, line 70
def get_resource(resource_id)
  @api.get("/resource/#{resource_id.to_s.url_safe}")
end
get_resource_billing_data(resource_id, start_date, end_date) click to toggle source

Get the billing statistics for a resource for a given time period

Attributes

  • resource_id - resource id of resource whose billing data we require

  • start_date - DateTime - start date

  • end_date - DateTime - end date

  • period - Billing period: hourly|daily|monthly

Returns

Roles

supplier, admin

# File lib/onapp_market/supply.rb, line 85
def get_resource_billing_data(resource_id, start_date, end_date)
  @api.get("/resource/#{resource_id.to_s.url_safe}/billing", {:start => start_date.rfc3339, :end => end_date.rfc3339})
end
get_resources(filter = {}, detail = false) click to toggle source

Get a list of resources from the market

Attributes

  • filter - hash of exact attribute matches. In the future we may add search_resources for more flexible access.

  • detail - List of ids (false) or objects (true)

Returns

Roles

supplier, admin

# File lib/onapp_market/supply.rb, line 57
def get_resources(filter = {}, detail = false)
  @api.get("/resource",{:filter => filter, :detail => detail}, detail)
end
get_user_billing_data(user_id, start_date, end_date, period = :daily) click to toggle source

Get a user’s billing statistics

Attributes

  • user_id - user id of user whose billing data we require

  • start_date - DateTime - start date

  • end_date - DateTime - end date

  • period - Billing period: hourly|daily|monthly

Returns

Roles

admin

# File lib/onapp_market/supply.rb, line 115
def get_user_billing_data(user_id, start_date, end_date, period = :daily)
  @api.get("/admin/user/#{user_id.url_safe}/billing", {:start => start_date.rfc3339, :end => end_date.rfc3339, :period => period.to_s})
end