class Firebell::Client
Attributes
token[RW]
Public Class Methods
new(token = Firebell.configuration.token)
click to toggle source
# File lib/firebell/client.rb, line 7 def initialize(token = Firebell.configuration.token) @token = token end
Public Instance Methods
notify(tag:, body: nil, params: {})
click to toggle source
# File lib/firebell/client.rb, line 11 def notify(tag:, body: nil, params: {}) attributes = { tag: tag } attributes.merge!(params: params) if params.any? attributes.merge!(body: body) if body send_request attributes if requestable? end
Private Instance Methods
http()
click to toggle source
# File lib/firebell/client.rb, line 37 def http @http ||= begin http = Net::HTTP.new uri.host, uri.port http.use_ssl = true if uri.is_a?(URI::HTTPS) http end end
requestable?()
click to toggle source
# File lib/firebell/client.rb, line 49 def requestable? if Firebell.configuration.notify_release_stages.any? Firebell.configuration.notify_release_stages.include? Firebell.configuration.release_stage else true end end
send_request(attrs)
click to toggle source
# File lib/firebell/client.rb, line 20 def send_request(attrs) if @token request = Net::HTTP::Post.new uri.request_uri, "Authorization" => "Token #{@token}", "Content-Type" => "application/json" request.body = JSON.generate attrs response = http.request(request) if response['Content-Type'] == "application/json" JSON.parse response.body else response.body end else raise Firebell::NoTokenError end end
uri()
click to toggle source
# File lib/firebell/client.rb, line 45 def uri @uri ||= URI.parse Firebell.configuration.url end