Class: Gemometer::Notifiers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gemometer/notifiers/base.rb

Direct Known Subclasses

Hipchat, Slack

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Base

Returns a new instance of Base.



11
12
13
14
# File 'lib/gemometer/notifiers/base.rb', line 11

def initialize(opts)
  @gems = opts[:gems]
  @url  = opts[:url]
end

Instance Attribute Details

#gemsObject (readonly)

Returns the value of attribute gems.



9
10
11
# File 'lib/gemometer/notifiers/base.rb', line 9

def gems
  @gems
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/gemometer/notifiers/base.rb', line 9

def url
  @url
end

Instance Method Details

#notifyObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gemometer/notifiers/base.rb', line 16

def notify
  return false if gems.empty?

  uri = URI(url)

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = (uri.scheme == "https")

  req = Net::HTTP::Post.new(uri)
  req.content_type = 'application/json'

  res = http.request(req, JSON.generate(data))

  %w(204 200).include?(res.code) ||
    raise(Gemometer::NotifyError.new("#{res.code}: #{res.message}"))
end