Class: BBGAPI::Client
Constant Summary collapse
- API_URL =
"https://boxpanel.bluebox.net"
Class Method Summary collapse
- .blocks_advanced ⇒ Object
- .deleteurl(partial) ⇒ Object
- .geturl(partial, opts = {}) ⇒ Object
- .help ⇒ Object
- .lb_advanced ⇒ Object
- .posturl(partial, opts = {}) ⇒ Object
- .puturl ⇒ Object
- .query(partial, request) ⇒ Object
Instance Method Summary collapse
- #config ⇒ Object
-
#debug! ⇒ Object
def self.configload configload = Config.new(@config_file) end.
-
#initialize(config_file) ⇒ Client
constructor
A new instance of Client.
- #load_credentials ⇒ Object
- #parseopt(type = "", action = "", id = "") ⇒ Object
Constructor Details
#initialize(config_file) ⇒ Client
Returns a new instance of Client.
17 18 19 20 |
# File 'lib/bbgapi/client.rb', line 17 def initialize(config_file) @config_file = config_file @debug = false end |
Class Method Details
.blocks_advanced ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/bbgapi/client.rb', line 102 def self.blocks_advanced choose do || puts "Load Balancer API - http://bit.ly/ucbpDF" puts "----------------------------------------" .prompt = "Which Objects Would You Like? " .choices(:blocks) {BBGAPI::Blocks.} .choices(:templates) {BBGAPI::Blocks_Templates.} .choices(:products) {BBGAPI::Blocks_Products.} .choices(:exit) {exit 0} end end |
.deleteurl(partial) ⇒ Object
76 77 78 79 80 |
# File 'lib/bbgapi/client.rb', line 76 def self.deleteurl(partial) url = "#{API_URL}#{partial}" response = delete(url) return response end |
.geturl(partial, opts = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bbgapi/client.rb', line 45 def self.geturl(partial, opts={}) url = "#{API_URL}#{partial}" response = get(url) #puts response.code if response.code == 401 puts "Access denied. Bad Customer Number or API Key." exit 0 end if response.code != 200 puts "Response code is #{response.code}" puts response exit 0 end if @debug puts "Response Code: #{response.code}" puts "Response RAW: #{response}" end response end |
.help ⇒ Object
41 42 43 |
# File 'lib/bbgapi/client.rb', line 41 def self.help puts "test" end |
.lb_advanced ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/bbgapi/client.rb', line 88 def self.lb_advanced choose do || puts "Load Balancer API - http://bit.ly/ucbpDF" puts "----------------------------------------" .prompt = "Which Objects Would You Like? " .choices(:applications) {BBGAPI::LB_Applications.} .choices(:services) {BBGAPI::LB_Services.} .choices(:backends) {BBGAPI::LB_Backends.} .choices(:machines) .choices(:exit) {exit 0} end end |
.posturl(partial, opts = {}) ⇒ Object
70 71 72 73 74 |
# File 'lib/bbgapi/client.rb', line 70 def self.posturl(partial, opts={}) url = "#{API_URL}#{partial}" response = post(url,opts) return response end |
.puturl ⇒ Object
82 83 84 85 86 |
# File 'lib/bbgapi/client.rb', line 82 def self.puturl # alternatively: # raise NotImplementedError, "bla" puts "bla" end |
.query(partial, request) ⇒ Object
11 12 13 14 |
# File 'lib/bbgapi/client.rb', line 11 def query(partial, request) url = "#{@api_url}#{partial}" response = get(url) end |
Instance Method Details
#config ⇒ Object
22 23 24 |
# File 'lib/bbgapi/client.rb', line 22 def config @config ||= Config.new(@config_file) end |
#debug! ⇒ Object
37 38 39 |
# File 'lib/bbgapi/client.rb', line 37 def debug! @debug = true end |
#load_credentials ⇒ Object
26 27 28 29 30 31 |
# File 'lib/bbgapi/client.rb', line 26 def load_credentials @@credentials = { :bluebox_customer_id => self.config["bluebox_customer_id"], :bluebox_api_key => self.config["bluebox_api_key"] } end |
#parseopt(type = "", action = "", id = "") ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/bbgapi/client.rb', line 115 def parseopt(type="",action="",id="") ssh_key_file = File.new("#{ENV['HOME']}/.ssh/id_rsa.pub", "r") keyfile = ssh_key_file.gets self.class.basic_auth config[:bluebox_customer_id], config[:bluebox_api_key] case type when "lb" choose do || puts "Load Balancer API - http://bit.ly/ucbpDF" puts "----------------------------------------" .prompt = "Easy or Advanced Mode? " .choices(:open_documentation) {system("open", "http://bit.ly/ucbpDF")} #fuck windows anyway .choices(:easy_mode) {BBGAPI::LB_Easy.(self.config)} .choices(:advanced_mode) {BBGAPI::Client.lb_advanced} .choices(:exit) {exit 0} puts "\n" end when "blocks" choose do || puts "Blocks API - http://bit.ly/v9FtWW" puts "----------------------------------------" .prompt = "Easy or Advanced Mode? " .choices(:open_documentation) {system("open", "http://bit.ly/v9FtWW")} #fuck windows anyway .choices(:easy_mode) {BBGAPI::LB_Easy.} .choices(:advanced_mode) {BBGAPI::Client.blocks_advanced} .choices(:exit) {exit 0} puts "\n" end when "servers" choose do || puts "Servers API - http://bit.ly/uDd6wQ" puts "----------------------------------------" .prompt = "Which Objects Would You Like? " .choices(:open_documentation) {system("open", "http://bit.ly/uDd6wQ")} #fuck windows anyway .choices(:list) {BBGAPI::Servers.list} .choices(:exit) {exit 0} end when "help" help else "Invalid --api option, try --help" end end |