Class: ScoutScout::Plugin

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/scout_scout/plugin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Plugin

Returns a new instance of Plugin.



4
5
6
7
8
9
10
# File 'lib/scout_scout/plugin.rb', line 4

def initialize(hash)
  if hash['descriptors'] && hash['descriptors']['descriptor']
    @descriptor_hash = hash['descriptors']['descriptor']
    hash.delete('descriptors')
  end
  super(hash)
end

Instance Attribute Details

#serverObject

Returns the value of attribute server.



2
3
4
# File 'lib/scout_scout/plugin.rb', line 2

def server
  @server
end

Instance Method Details

#descriptorsArray

All descriptors for this plugin, including their name and current

Returns:

  • (Array)

    An array of ScoutScout::Descriptor objects



15
16
17
# File 'lib/scout_scout/plugin.rb', line 15

def descriptors
  @descriptors ||= @descriptor_hash.map { |d| decorate_with_server_and_plugin(ScoutScout::Descriptor.new(d)) }
end

#email_subscribersObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/scout_scout/plugin.rb', line 19

def email_subscribers
  response = ScoutScout.get("/#{ScoutScout.}/clients/#{server.id}/email_subscribers?plugin_id=#{id}")
  doc = Nokogiri::HTML(response.body)

  table = doc.css('table.list').first
  user_rows = table.css('tr')[1..-1] # skip first row, which is headings

  user_rows.map do |row|
    name_td, receiving_notifications_td = *row.css('td')

    name = name_td.content.gsub(/[\t\n]/, '')
    checked = receiving_notifications_td.css('input').attribute('checked')
    receiving_notifications = checked && checked.value == 'checked'
    Hashie::Mash.new :name => name, :receiving_notifications => receiving_notifications
  end
end

#triggersObject



36
37
38
39
# File 'lib/scout_scout/plugin.rb', line 36

def triggers
  response = ScoutScout.get("/#{ScoutScout.}/clients/#{server.id}/triggers.xml?plugin_id=#{id}")
  response['triggers'].map { |trigger| decorate_with_server_and_plugin(ScoutScout::Trigger.new(trigger)) }
end