Class: SDEE
- Inherits:
-
Object
- Object
- SDEE
- Defined in:
- lib/sdee.rb
Instance Method Summary collapse
- #get_events ⇒ Object
-
#initialize(options = {}) ⇒ SDEE
constructor
A new instance of SDEE.
- #login ⇒ Object
- #poll_events(sleep_time = 5) ⇒ Object
- #request(params) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ SDEE
Returns a new instance of SDEE.
98 99 100 101 102 103 104 |
# File 'lib/sdee.rb', line 98 def initialize( = {}) @host = [:host] @path = '/cgi-bin/sdee-server' @proto = 'https://' @creds = Base64.encode64("#{options[:user]}:#{options[:pass]}") end |
Instance Method Details
#get_events ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/sdee.rb', line 133 def get_events puts "Please login first" unless @subscription_id params = { action: 'get', confirm: 'yes', timeout: 1, maxNbrofEvents: 20, subscriptionId: @subscription_id, sessionId: @session_id } res = request params doc = Nokogiri::XML(res.body) xml_alerts = doc.xpath("//sd:evIdsAlert") hash_alerts = xml_alerts.collect {|x| Alert.new(x).to_hash }.uniq hash_alerts.each {|h| puts h.to_json } hash_alerts end |
#login ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/sdee.rb', line 106 def login params = { action: 'open', events: 'evIdsAlert', force: 'yes' } response = request params doc = Nokogiri::XML(response.body) @session_id = doc.xpath('//env:Header').first. xpath('//sd:oobInfo').first. xpath('//sd:sessionId').first.text @subscription_id = doc.xpath('//env:Body').first. xpath('//sd:subscriptionId').first.text response end |
#poll_events(sleep_time = 5) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/sdee.rb', line 126 def poll_events(sleep_time=5) while true do get_events sleep sleep_time end end |
#request(params) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/sdee.rb', line 156 def request(params) http = Net::HTTP.new(@host, 443) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.ssl_version = :SSLv3 uri = URI(@proto + @host + @path) uri.query = URI.encode_www_form(params) req = Net::HTTP::Get.new(uri) req['Authorization'] = "BASIC #{@creds}" response = http.request(req) end |