Class: Boxcutter::Api
- Inherits:
-
Object
- Object
- Boxcutter::Api
- Defined in:
- lib/boxcutter/api.rb
Instance Method Summary collapse
- #application(app_id) ⇒ Object
- #applications ⇒ Object
- #backend(service_id, backend_id) ⇒ Object
- #backends(service_id) ⇒ Object
- #conn ⇒ Object
-
#create_machine(backend_id, machine_id, options = {}) ⇒ Object
Options are: port - The port the machine is serving http or https on.
- #delete_machine(backend_id, machine_id) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(customer_id, api_key_secret) ⇒ Api
constructor
A new instance of Api.
- #machine(backend_id, machine_id) ⇒ Object
- #machines(backend_id) ⇒ Object
- #servers ⇒ Object
- #service(app_id, service_id) ⇒ Object
- #services(app_id) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(customer_id, api_key_secret) ⇒ Api
Returns a new instance of Api.
6 7 8 9 |
# File 'lib/boxcutter/api.rb', line 6 def initialize(customer_id, api_key_secret) @customer_id = customer_id @api_key_secret = api_key_secret end |
Instance Method Details
#application(app_id) ⇒ Object
36 37 38 |
# File 'lib/boxcutter/api.rb', line 36 def application(app_id) get("lb_applications/#{app_id}") end |
#applications ⇒ Object
32 33 34 |
# File 'lib/boxcutter/api.rb', line 32 def applications get('lb_applications') end |
#backend(service_id, backend_id) ⇒ Object
52 53 54 |
# File 'lib/boxcutter/api.rb', line 52 def backend(service_id, backend_id) get("lb_services/#{service_id}/lb_backends/#{backend_id}") end |
#backends(service_id) ⇒ Object
48 49 50 |
# File 'lib/boxcutter/api.rb', line 48 def backends(service_id) get("lb_services/#{service_id}/lb_backends") end |
#conn ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/boxcutter/api.rb', line 24 def conn @conn ||= Faraday.new(:url => "https://boxpanel.bluebox.net/api") do |conn| conn.request :url_encoded conn.adapter Faraday.default_adapter conn.basic_auth(@customer_id, @api_key_secret) end end |
#create_machine(backend_id, machine_id, options = {}) ⇒ Object
Options are: port - The port the machine is serving http or https on. Defaults to the
port the service is listening on.
weight - The multiplier for what portion of the incoming traffic should be
routed to this machine.
maxconn - The maximum number of simultaneous connections allowed for this
machine.
backup - Only direct traffic to this node if all the other nodes are down.
76 77 78 79 80 |
# File 'lib/boxcutter/api.rb', line 76 def create_machine(backend_id, machine_id, = {}) data = { 'lb_machine' => machine_id } data['lb_options'] = unless .empty? conn.post("lb_backends/#{backend_id}/lb_machines", data) end |
#delete_machine(backend_id, machine_id) ⇒ Object
64 65 66 |
# File 'lib/boxcutter/api.rb', line 64 def delete_machine(backend_id, machine_id) conn.delete("lb_backends/#{backend_id}/lb_machines/#{machine_id}") end |
#get(path) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/boxcutter/api.rb', line 15 def get(path) response = conn.get(path) begin Yajl::Parser.new.parse(response.body) rescue Yajl::ParseError {:message => response.body} end end |
#machine(backend_id, machine_id) ⇒ Object
60 61 62 |
# File 'lib/boxcutter/api.rb', line 60 def machine(backend_id, machine_id) get("lb_backends/#{backend_id}/lb_machines/#{machine_id}") end |
#machines(backend_id) ⇒ Object
56 57 58 |
# File 'lib/boxcutter/api.rb', line 56 def machines(backend_id) get("lb_backends/#{backend_id}/lb_machines") end |
#servers ⇒ Object
82 83 84 |
# File 'lib/boxcutter/api.rb', line 82 def servers get("servers") end |
#service(app_id, service_id) ⇒ Object
44 45 46 |
# File 'lib/boxcutter/api.rb', line 44 def service(app_id, service_id) get("lb_applications/#{app_id}/lb_services/#{service_id}") end |
#services(app_id) ⇒ Object
40 41 42 |
# File 'lib/boxcutter/api.rb', line 40 def services(app_id) get("lb_applications/#{app_id}/lb_services") end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/boxcutter/api.rb', line 11 def to_s "#<Api customer_id:'#{@customer_id}' api_key_secret:'***'>" end |