Created
February 23, 2018 18:46
-
-
Save scottwater/dbe12eec3b55d5bfd8defa7405bbee66 to your computer and use it in GitHub Desktop.
Backplane API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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