pnap_billing_api

BillingApi - the Ruby gem for the Billing API

Automate your infrastructure billing with the Bare Metal Cloud Billing API. Reserve your server instances to ensure guaranteed resource availability for 12, 24, and 36 months. Retrieve your server’s rated usage for a given period and enable or disable auto-renewals.

Knowledge base articles to help you can be found here

All URLs are relative to (https://api.phoenixnap.com/billing/v1/)

This SDK is automatically generated by the OpenAPI Generator project:

Installation

Build a gem

To build the Ruby code into a gem:

gem build pnap_billing_api.gemspec

Then either install the gem locally, replacing <VERSION> with the actual version:

gem install ./pnap_billing_api-<VERSION>.gem

(for development, run gem install --dev ./pnap_billing_api-<VERSION>.gem to install the development dependencies)

or publish the gem to a gem hosting service, e.g. RubyGems.

Finally add this to the Gemfile:

gem 'pnap_billing_api', '~> <VERSION>'

Install from Git

To install this Gem from this repository, you'll need to get Bundler by doing gem install bundler. Add the following line in your Gemfile:

gem 'pnap_billing_api', git: 'https://github.com/phoenixnap/ruby-sdk-bmc-poc', glob: 'BillingApi/*.gemspec'

If you'd like the development version:

gem 'pnap_billing_api', git: 'https://github.com/phoenixnap/ruby-sdk-bmc-poc', glob: 'BillingApi/*.gemspec', branch: 'develop'

Then run bundle install.

Include the Ruby code directly

Include the Ruby code directly using -I as follows:

ruby -Ilib script.rb

Getting Started

Please follow the installation procedure and then run the following code:

# Load the gem
require 'pnap_billing_api'

# Setup authorization
BillingApi.configure do |config|
  # Configure OAuth2 access token for authorization: OAuth2
  config.access_token = 'YOUR ACCESS TOKEN'
  # Configure a proc to get access tokens in lieu of the static access_token configuration
  config.access_token_getter = -> { 'YOUR TOKEN GETTER PROC' } 
end

api_instance = BillingApi::BillingConfigurationsApi.new

begin
  #Retrieves billing configuration associated with the authenticated account.
  result = api_instance.
  p result
rescue BillingApi::ApiError => e
  puts "Exception when calling BillingConfigurationsApi->account_billing_configuration_me_get: #{e}"
end

Authorization can also be setup by using the oauth library:

# Load the gem
require 'pnap_billing_api'
require 'oauth2'

# Setup variables for getting a token.
client_id = 'YOUR_CLIENT_ID'
client_secret = 'YOUR_CLIENT_SECRET'
auth_url = 'https://auth.phoenixnap.com/auth/realms/BMC/protocol/openid-connect/token'


# Setup authorization
BillingApi.configure do |config|
  # Retrieve the token using OAuth2.
  client = OAuth2::Client.new(client_id, client_secret, token_url: auth_url)
  token = client.client_credentials.get_token

  # Configure OAuth2 access token for authorization: OAuth2
  config.access_token = token.token
end

Documentation for API Endpoints

All URIs are relative to https://api.phoenixnap.com/billing/v1

Class Method HTTP request Description
BillingApi::BillingConfigurationsApi account_billing_configuration_me_get GET /account-billing-configurations/me Retrieves billing configuration associated with the authenticated account.
BillingApi::ProductAvailabilityApi product_availability_get GET /product-availability List all Product availabilities.
BillingApi::ProductsApi products_get GET /products List all Products.
BillingApi::RatedUsageApi rated_usage_get GET /rated-usage List the rated usage.
BillingApi::RatedUsageApi rated_usage_month_to_date_get GET /rated-usage/month-to-date List the rated usage records for the current calendar month.
BillingApi::ReservationsApi reservations_get GET /reservations List all Reservations.
BillingApi::ReservationsApi reservations_post POST /reservations Create a reservation.
BillingApi::ReservationsApi reservations_reservation_id_actions_auto_renew_disable_post POST /reservations/id/actions/auto-renew/disable Disable auto-renewal for reservation by id.
BillingApi::ReservationsApi reservations_reservation_id_actions_auto_renew_enable_post POST /reservations/id/actions/auto-renew/enable Enable auto-renewal for unexpired reservation by reservation id.
BillingApi::ReservationsApi reservations_reservation_id_actions_convert_post POST /reservations/id/actions/convert Convert reservation pricing model by reservation ID.
BillingApi::ReservationsApi reservations_reservation_id_get GET /reservations/id Get a reservation.

Documentation for Models

Documentation for Authorization

Authentication schemes defined for the API:

OAuth2

  • Type: OAuth
  • Flow: application
  • Authorization URL:
  • Scopes:
    • bmc: Grants full access to bmc-api.
    • bmc.read: Grants read only access to bmc-api.