Class: BBGAPI::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/bbgapi/client.rb

Constant Summary collapse

API_URL =
"https://boxpanel.bluebox.net"

Class Method Summary collapse

Instance Method Summary collapse

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_advancedObject



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 |menu|
      puts "Load Balancer API - http://bit.ly/ucbpDF"
      puts "----------------------------------------"
      menu.prompt = "Which Objects Would You Like?  "

      menu.choices(:blocks) {BBGAPI::Blocks.menulist}
      menu.choices(:templates) {BBGAPI::Blocks_Templates.menulist}
      menu.choices(:products) {BBGAPI::Blocks_Products.menulist}
      menu.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

.helpObject



41
42
43
# File 'lib/bbgapi/client.rb', line 41

def self.help
  puts "test"
end

.lb_advancedObject



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 |menu|
      puts "Load Balancer API - http://bit.ly/ucbpDF"
      puts "----------------------------------------"
      menu.prompt = "Which Objects Would You Like?  "

      menu.choices(:applications) {BBGAPI::LB_Applications.menulist}
      menu.choices(:services) {BBGAPI::LB_Services.menulist}
      menu.choices(:backends) {BBGAPI::LB_Backends.menulist}
      menu.choices(:machines)
      menu.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

.puturlObject



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

#configObject



22
23
24
# File 'lib/bbgapi/client.rb', line 22

def config
  @config ||= Config.new(@config_file)
end

#debug!Object

def self.configload

configload = Config.new(@config_file)

end



37
38
39
# File 'lib/bbgapi/client.rb', line 37

def debug!
  @debug = true
end

#load_credentialsObject



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 |menu|
      puts "Load Balancer API - http://bit.ly/ucbpDF"
      puts "----------------------------------------"
      menu.prompt = "Easy or Advanced Mode?  "
      menu.choices(:open_documentation) {system("open", "http://bit.ly/ucbpDF")} #fuck windows anyway
      menu.choices(:easy_mode) {BBGAPI::LB_Easy.menulist(self.config)}
      menu.choices(:advanced_mode) {BBGAPI::Client.lb_advanced}
      menu.choices(:exit) {exit 0}
      puts "\n"
    end
  when "blocks"
    choose do |menu|
      puts "Blocks API - http://bit.ly/v9FtWW"
      puts "----------------------------------------"
      menu.prompt = "Easy or Advanced Mode?  "
      menu.choices(:open_documentation) {system("open", "http://bit.ly/v9FtWW")} #fuck windows anyway
      menu.choices(:easy_mode) {BBGAPI::LB_Easy.menulist}
      menu.choices(:advanced_mode) {BBGAPI::Client.blocks_advanced}
      menu.choices(:exit) {exit 0}
      puts "\n"
    end
  when "servers"
    choose do |menu|
      puts "Servers API - http://bit.ly/uDd6wQ"
      puts "----------------------------------------"
      menu.prompt = "Which Objects Would You Like?  "
      menu.choices(:open_documentation) {system("open", "http://bit.ly/uDd6wQ")} #fuck windows anyway
      menu.choices(:list) {BBGAPI::Servers.list}
      menu.choices(:exit) {exit 0}
    end
  when "help"
    help
  else
    "Invalid --api option, try --help"
  end
end