Skip to content

Instantly share code, notes, and snippets.

@scottwater
Created February 23, 2018 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottwater/dbe12eec3b55d5bfd8defa7405bbee66 to your computer and use it in GitHub Desktop.
Save scottwater/dbe12eec3b55d5bfd8defa7405bbee66 to your computer and use it in GitHub Desktop.
Backplane API
class BackplaneApi
include HTTParty
debug_output $stderr if Rails.env.development?
base_uri 'www.backplane.io:443'
basic_auth ENV['BACKPLANE_TOKEN'], ''
format :json
def add_route(pattern, labels={})
raw_selector = labels.map{|k,v|"#{k}=#{v}"}.join(',')
body = {
Pattern: pattern,
Route: {
RawSelector: raw_selector
}
}.to_json
self.class.post("/route", {body: body}).ok?
end
def require_tls(pattern)
body = {
Pattern: pattern,
RequireTLS: true
}.to_json
self.class.put("/e", {body: body}).ok?
end
def remove_tls(pattern)
body = {
Pattern: pattern,
RequireTLS: false
}.to_json
self.class.put("/e", {body: body}).ok?
end
def remove_route(pattern)
self.class.delete("/e/#{pattern}").ok?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment