Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
# Hello World Program in Ruby
require 'uri'
require 'net/http'
require 'json'
require 'ostruct'
module Heroku
module Addons
class Addon
attr_accessor :name
def initialize(attrs)
@name = attrs['name']
end
end
class AddonPlan
attr_accessor :description, :price, :unit
def initialize(attrs)
@description = attrs['description']
@price = attrs['price']['cents'] / 100.0
@unit = attrs['price']['unit']
end
def full_price
"$#{'%.2f' % price}/#{unit}"
end
end
class Client
def initialize
uri = URI.parse("https://api.heroku.com/")
@http = Net::HTTP.new(uri.host, uri.port)
@http.use_ssl = true if uri.scheme == 'https'
@headers = {
'Accept' => 'application/vnd.heroku+json; version=3'
}
end
def request(path, headers={})
response = @http.get(path, @headers.merge(headers))
JSON.parse response.body
end
end
@client = Client.new
# Loads all the available addons from Heroku
def self.all
@client.request('/addon-services').map { |addon| Addon.new(addon) }
end
def self.plans(addon)
@client.request("/addon-services/#{addon}/plans").map { |plan| AddonPlan.new(plan) }
end
end
end
#########################################################################################
addons = Heroku::Addons.all
addons.each do |addon|
name = addon.name
plans = Heroku::Addons.plans(name)
puts name
plans.sort_by(&:price).each do |plan|
puts " #{plan.description}: #{plan.full_price}"
end
end
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more