{"action":"created","comment":{"url":"https://api.github.com/repos/rapid7/nexpose-client/pulls/comments/27931972","id":27931972,"diff_hunk":"@@ -114,138 +32,191 @@ class VulnFilter\n     attr_accessor :confirmed, :unconfirmed, :potential\n \n     def initialize(severity = 1, confirmed = 1, unconfirmed = 1, potential = 1)\n-      @severity, @confirmed, @unconfirmed, @potential = severity, confirmed, unconfirmed, potential\n-    end\n-\n-    def as_xml\n-      xml = REXML::Element.new('vulnFilter')\n-      xml.attributes['severityThreshold'] = @severity\n-      xml.attributes['confirmed'] = @confirmed\n-      xml.attributes['unconfirmed'] = @unconfirmed\n-      xml.attributes['potential'] = @potential\n-      xml\n-    end\n-\n-    def to_xml\n-      as_xml.to_s\n+      @severity, @confirmed, @unconfirmed, @potential = severity.to_i, confirmed.to_i, unconfirmed.to_i, potential.to_i\n     end\n \n-    def self.parse(xml)\n-      new(xml.attributes['severityThreshold'].to_i,\n-          xml.attributes['confirmed'].to_i,\n-          xml.attributes['unconfirmed'].to_i,\n-          xml.attributes['potential'].to_i)\n+    def self.json_initializer(filter)\n+      new(filter[:severity] ? 1 : 0, filter[:unconfirmed] ? 1 : 0, filter[:confirmed] ? 1 : 0, filter[:potential] ? 1 : 0)\n     end\n   end\n \n-  # Syslog Alert\n-  # This class should only exist as an element of an Alert.\n-  #\n-  class SyslogAlert\n+  # Alert base behavior.\n+  # The supported three alert types should have these properties and behaviors\n+  module Alert\n+    include JsonSerializer\n+    extend TypedAccessor\n \n-    # The server to sent this alert to.\n+    # ID for this alert.\n+    attr_accessor :id\n+    # Name for this alert.\n+    attr_accessor :name\n+    # Whether or not this alert is currently active.\n+    attr_accessor :enabled\n+    # Send at most this many alerts per scan.\n+    attr_accessor :max_alerts\n+    # Alert type and its configuration. One of SMTPAlert, SyslogAlert, SNMPAlert\n+    attr_accessor :alert_type\n+    # Server target the alerts\n     attr_accessor :server\n+    # Server port\n+    attr_accessor :server_port\n \n-    def initialize(server)\n-      @server = server\n-    end\n+    # Send alerts based upon scan status.\n+    typed_accessor :scan_filter, ScanFilter\n+    # Send alerts based upon vulnerability finding status.\n+    typed_accessor :vuln_filter, VulnFilter\n \n-    def self.parse(xml)\n-      new(xml.attributes['server'])\n+    # load a particular site alert\n+    def self.load(nsc, site_id, alert_id)\n+      uri = \"/api/2.1/site_configurations/#{site_id}/alerts/#{alert_id}\"\n+      resp = AJAX.get(nsc, uri, AJAX::CONTENT_TYPE::JSON)\n+\n+      unless resp.to_s == ''\n+        data = JSON.parse(resp, symbolize_names: true)\n+        json_initializer(data).deserialize(data)\n+      end\n     end\n \n-    def as_xml\n-      xml = REXML::Element.new('syslogAlert')\n-      xml.attributes['server'] = @server\n-      xml\n+    # load alerts from an array of hashes\n+    def self.load_alerts(alerts)\n+      alerts.map { |hash| json_initializer(hash).deserialize(hash) }\n     end\n \n-    def to_xml\n-      as_xml.to_s\n+    # load a list of alerts for a given site\n+    def self.list_alerts(nsc, site_id)\n+      uri = \"/api/2.1/site_configurations/#{site_id}/alerts\"\n+      resp = AJAX.get(nsc, uri, AJAX::CONTENT_TYPE::JSON)\n+      data = JSON.parse(resp, symbolize_names: true)\n+      self.load_alerts(data) unless data.nil?\n     end\n-  end\n \n-  # SNMP Alert\n-  # This class should only exist as an element of an Alert.\n-  #\n-  class SNMPAlert\n+    def self.json_initializer(hash)\n+      create(hash)\n+    end\n \n-    # The community string\n-    attr_accessor :community\n+    def to_h\n+      to_hash(Hash.new)\n+    end\n \n-    # The server to sent this alert\n-    attr_accessor :server\n+    def to_json\n+      serialize()\n+    end\n \n-    def initialize(community, server)\n-      @community = community\n-      @server = server\n+    # delete an alert from the given site\n+    def delete(nsc, site_id)\n+      uri = \"/api/2.1/site_configurations/#{site_id}/alerts/#{self.id}\"","path":"lib/nexpose/alert.rb","position":236,"original_position":236,"commit_id":"124d5a02c2f131ad422c2aa64bfbaac8cae75117","original_commit_id":"124d5a02c2f131ad422c2aa64bfbaac8cae75117","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Redundant `self` detected.","created_at":"2015-04-07T23:46:00Z","updated_at":"2015-04-07T23:46:00Z","html_url":"https://github.com/rapid7/nexpose-client/pull/157#discussion_r27931972","pull_request_url":"https://api.github.com/repos/rapid7/nexpose-client/pulls/157","_links":{"self":{"href":"https://api.github.com/repos/rapid7/nexpose-client/pulls/comments/27931972"},"html":{"href":"https://github.com/rapid7/nexpose-client/pull/157#discussion_r27931972"},"pull_request":{"href":"https://api.github.com/repos/rapid7/nexpose-client/pulls/157"}}},"pull_request":{"url":"https://api.github.com/repos/rapid7/nexpose-client/pulls/157","id":32816896,"html_url":"https://github.com/rapid7/nexpose-client/pull/157","diff_url":"https://github.com/rapid7/nexpose-client/pull/157.diff","patch_url":"https://github.com/rapid7/nexpose-client/pull/157.patch","issue_url":"https://api.github.com/repos/rapid7/nexpose-client/issues/157","number":157,"state":"open","locked":false,"title":"Merging Staging/v1 into Master","user":{"login":"sgreen-r7","id":10285110,"avatar_url":"https://avatars.githubusercontent.com/u/10285110?v=3","gravatar_id":"","url":"https://api.github.com/users/sgreen-r7","html_url":"https://github.com/sgreen-r7","followers_url":"https://api.github.com/users/sgreen-r7/followers","following_url":"https://api.github.com/users/sgreen-r7/following{/other_user}","gists_url":"https://api.github.com/users/sgreen-r7/gists{/gist_id}","starred_url":"https://api.github.com/users/sgreen-r7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgreen-r7/subscriptions","organizations_url":"https://api.github.com/users/sgreen-r7/orgs","repos_url":"https://api.github.com/users/sgreen-r7/repos","events_url":"https://api.github.com/users/sgreen-r7/events{/privacy}","received_events_url":"https://api.github.com/users/sgreen-r7/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-04-07T23:45:45Z","updated_at":"2015-04-07T23:46:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1cac64f787ffe596b0ae246b2c1449480bb46426","assignee":null,"milestone":{"url":"https://api.github.com/repos/rapid7/nexpose-client/milestones/1","html_url":"https://github.com/rapid7/nexpose-client/milestones/One%20Dot%20Oh","labels_url":"https://api.github.com/repos/rapid7/nexpose-client/milestones/1/labels","id":1008443,"number":1,"title":"One Dot Oh","description":"Wherein we break backwards compatibility.","creator":{"login":"gschneider-r7","id":4418817,"avatar_url":"https://avatars.githubusercontent.com/u/4418817?v=3","gravatar_id":"","url":"https://api.github.com/users/gschneider-r7","html_url":"https://github.com/gschneider-r7","followers_url":"https://api.github.com/users/gschneider-r7/followers","following_url":"https://api.github.com/users/gschneider-r7/following{/other_user}","gists_url":"https://api.github.com/users/gschneider-r7/gists{/gist_id}","starred_url":"https://api.github.com/users/gschneider-r7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gschneider-r7/subscriptions","organizations_url":"https://api.github.com/users/gschneider-r7/orgs","repos_url":"https://api.github.com/users/gschneider-r7/repos","events_url":"https://api.github.com/users/gschneider-r7/events{/privacy}","received_events_url":"https://api.github.com/users/gschneider-r7/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":12,"state":"open","created_at":"2015-03-05T23:35:17Z","updated_at":"2015-04-07T23:45:45Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/rapid7/nexpose-client/pulls/157/commits","review_comments_url":"https://api.github.com/repos/rapid7/nexpose-client/pulls/157/comments","review_comment_url":"https://api.github.com/repos/rapid7/nexpose-client/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rapid7/nexpose-client/issues/157/comments","statuses_url":"https://api.github.com/repos/rapid7/nexpose-client/statuses/124d5a02c2f131ad422c2aa64bfbaac8cae75117","head":{"label":"rapid7:staging/v1","ref":"staging/v1","sha":"124d5a02c2f131ad422c2aa64bfbaac8cae75117","user":{"login":"rapid7","id":1013671,"avatar_url":"https://avatars.githubusercontent.com/u/1013671?v=3","gravatar_id":"","url":"https://api.github.com/users/rapid7","html_url":"https://github.com/rapid7","followers_url":"https://api.github.com/users/rapid7/followers","following_url":"https://api.github.com/users/rapid7/following{/other_user}","gists_url":"https://api.github.com/users/rapid7/gists{/gist_id}","starred_url":"https://api.github.com/users/rapid7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rapid7/subscriptions","organizations_url":"https://api.github.com/users/rapid7/orgs","repos_url":"https://api.github.com/users/rapid7/repos","events_url":"https://api.github.com/users/rapid7/events{/privacy}","received_events_url":"https://api.github.com/users/rapid7/received_events","type":"Organization","site_admin":false},"repo":{"id":2622467,"name":"nexpose-client","full_name":"rapid7/nexpose-client","owner":{"login":"rapid7","id":1013671,"avatar_url":"https://avatars.githubusercontent.com/u/1013671?v=3","gravatar_id":"","url":"https://api.github.com/users/rapid7","html_url":"https://github.com/rapid7","followers_url":"https://api.github.com/users/rapid7/followers","following_url":"https://api.github.com/users/rapid7/following{/other_user}","gists_url":"https://api.github.com/users/rapid7/gists{/gist_id}","starred_url":"https://api.github.com/users/rapid7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rapid7/subscriptions","organizations_url":"https://api.github.com/users/rapid7/orgs","repos_url":"https://api.github.com/users/rapid7/repos","events_url":"https://api.github.com/users/rapid7/events{/privacy}","received_events_url":"https://api.github.com/users/rapid7/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rapid7/nexpose-client","description":"Rapid7 Nexpose API client library written in Ruby","fork":false,"url":"https://api.github.com/repos/rapid7/nexpose-client","forks_url":"https://api.github.com/repos/rapid7/nexpose-client/forks","keys_url":"https://api.github.com/repos/rapid7/nexpose-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rapid7/nexpose-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rapid7/nexpose-client/teams","hooks_url":"https://api.github.com/repos/rapid7/nexpose-client/hooks","issue_events_url":"https://api.github.com/repos/rapid7/nexpose-client/issues/events{/number}","events_url":"https://api.github.com/repos/rapid7/nexpose-client/events","assignees_url":"https://api.github.com/repos/rapid7/nexpose-client/assignees{/user}","branches_url":"https://api.github.com/repos/rapid7/nexpose-client/branches{/branch}","tags_url":"https://api.github.com/repos/rapid7/nexpose-client/tags","blobs_url":"https://api.github.com/repos/rapid7/nexpose-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rapid7/nexpose-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rapid7/nexpose-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/rapid7/nexpose-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rapid7/nexpose-client/statuses/{sha}","languages_url":"https://api.github.com/repos/rapid7/nexpose-client/languages","stargazers_url":"https://api.github.com/repos/rapid7/nexpose-client/stargazers","contributors_url":"https://api.github.com/repos/rapid7/nexpose-client/contributors","subscribers_url":"https://api.github.com/repos/rapid7/nexpose-client/subscribers","subscription_url":"https://api.github.com/repos/rapid7/nexpose-client/subscription","commits_url":"https://api.github.com/repos/rapid7/nexpose-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/rapid7/nexpose-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/rapid7/nexpose-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/rapid7/nexpose-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/rapid7/nexpose-client/contents/{+path}","compare_url":"https://api.github.com/repos/rapid7/nexpose-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rapid7/nexpose-client/merges","archive_url":"https://api.github.com/repos/rapid7/nexpose-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rapid7/nexpose-client/downloads","issues_url":"https://api.github.com/repos/rapid7/nexpose-client/issues{/number}","pulls_url":"https://api.github.com/repos/rapid7/nexpose-client/pulls{/number}","milestones_url":"https://api.github.com/repos/rapid7/nexpose-client/milestones{/number}","notifications_url":"https://api.github.com/repos/rapid7/nexpose-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rapid7/nexpose-client/labels{/name}","releases_url":"https://api.github.com/repos/rapid7/nexpose-client/releases{/id}","created_at":"2011-10-21T19:04:49Z","updated_at":"2015-03-28T00:44:42Z","pushed_at":"2015-04-07T23:45:45Z","git_url":"git://github.com/rapid7/nexpose-client.git","ssh_url":"git@github.com:rapid7/nexpose-client.git","clone_url":"https://github.com/rapid7/nexpose-client.git","svn_url":"https://github.com/rapid7/nexpose-client","homepage":"http://www.rapid7.com/","size":3943,"stargazers_count":67,"watchers_count":67,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":52,"mirror_url":null,"open_issues_count":10,"forks":52,"open_issues":10,"watchers":67,"default_branch":"master"}},"base":{"label":"rapid7:master","ref":"master","sha":"49fc8d2beeb2f7077b5216772b3d7943038ca3a2","user":{"login":"rapid7","id":1013671,"avatar_url":"https://avatars.githubusercontent.com/u/1013671?v=3","gravatar_id":"","url":"https://api.github.com/users/rapid7","html_url":"https://github.com/rapid7","followers_url":"https://api.github.com/users/rapid7/followers","following_url":"https://api.github.com/users/rapid7/following{/other_user}","gists_url":"https://api.github.com/users/rapid7/gists{/gist_id}","starred_url":"https://api.github.com/users/rapid7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rapid7/subscriptions","organizations_url":"https://api.github.com/users/rapid7/orgs","repos_url":"https://api.github.com/users/rapid7/repos","events_url":"https://api.github.com/users/rapid7/events{/privacy}","received_events_url":"https://api.github.com/users/rapid7/received_events","type":"Organization","site_admin":false},"repo":{"id":2622467,"name":"nexpose-client","full_name":"rapid7/nexpose-client","owner":{"login":"rapid7","id":1013671,"avatar_url":"https://avatars.githubusercontent.com/u/1013671?v=3","gravatar_id":"","url":"https://api.github.com/users/rapid7","html_url":"https://github.com/rapid7","followers_url":"https://api.github.com/users/rapid7/followers","following_url":"https://api.github.com/users/rapid7/following{/other_user}","gists_url":"https://api.github.com/users/rapid7/gists{/gist_id}","starred_url":"https://api.github.com/users/rapid7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rapid7/subscriptions","organizations_url":"https://api.github.com/users/rapid7/orgs","repos_url":"https://api.github.com/users/rapid7/repos","events_url":"https://api.github.com/users/rapid7/events{/privacy}","received_events_url":"https://api.github.com/users/rapid7/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rapid7/nexpose-client","description":"Rapid7 Nexpose API client library written in Ruby","fork":false,"url":"https://api.github.com/repos/rapid7/nexpose-client","forks_url":"https://api.github.com/repos/rapid7/nexpose-client/forks","keys_url":"https://api.github.com/repos/rapid7/nexpose-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rapid7/nexpose-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rapid7/nexpose-client/teams","hooks_url":"https://api.github.com/repos/rapid7/nexpose-client/hooks","issue_events_url":"https://api.github.com/repos/rapid7/nexpose-client/issues/events{/number}","events_url":"https://api.github.com/repos/rapid7/nexpose-client/events","assignees_url":"https://api.github.com/repos/rapid7/nexpose-client/assignees{/user}","branches_url":"https://api.github.com/repos/rapid7/nexpose-client/branches{/branch}","tags_url":"https://api.github.com/repos/rapid7/nexpose-client/tags","blobs_url":"https://api.github.com/repos/rapid7/nexpose-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rapid7/nexpose-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rapid7/nexpose-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/rapid7/nexpose-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rapid7/nexpose-client/statuses/{sha}","languages_url":"https://api.github.com/repos/rapid7/nexpose-client/languages","stargazers_url":"https://api.github.com/repos/rapid7/nexpose-client/stargazers","contributors_url":"https://api.github.com/repos/rapid7/nexpose-client/contributors","subscribers_url":"https://api.github.com/repos/rapid7/nexpose-client/subscribers","subscription_url":"https://api.github.com/repos/rapid7/nexpose-client/subscription","commits_url":"https://api.github.com/repos/rapid7/nexpose-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/rapid7/nexpose-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/rapid7/nexpose-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/rapid7/nexpose-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/rapid7/nexpose-client/contents/{+path}","compare_url":"https://api.github.com/repos/rapid7/nexpose-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rapid7/nexpose-client/merges","archive_url":"https://api.github.com/repos/rapid7/nexpose-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rapid7/nexpose-client/downloads","issues_url":"https://api.github.com/repos/rapid7/nexpose-client/issues{/number}","pulls_url":"https://api.github.com/repos/rapid7/nexpose-client/pulls{/number}","milestones_url":"https://api.github.com/repos/rapid7/nexpose-client/milestones{/number}","notifications_url":"https://api.github.com/repos/rapid7/nexpose-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rapid7/nexpose-client/labels{/name}","releases_url":"https://api.github.com/repos/rapid7/nexpose-client/releases{/id}","created_at":"2011-10-21T19:04:49Z","updated_at":"2015-03-28T00:44:42Z","pushed_at":"2015-04-07T23:45:45Z","git_url":"git://github.com/rapid7/nexpose-client.git","ssh_url":"git@github.com:rapid7/nexpose-client.git","clone_url":"https://github.com/rapid7/nexpose-client.git","svn_url":"https://github.com/rapid7/nexpose-client","homepage":"http://www.rapid7.com/","size":3943,"stargazers_count":67,"watchers_count":67,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":52,"mirror_url":null,"open_issues_count":10,"forks":52,"open_issues":10,"watchers":67,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rapid7/nexpose-client/pulls/157"},"html":{"href":"https://github.com/rapid7/nexpose-client/pull/157"},"issue":{"href":"https://api.github.com/repos/rapid7/nexpose-client/issues/157"},"comments":{"href":"https://api.github.com/repos/rapid7/nexpose-client/issues/157/comments"},"review_comments":{"href":"https://api.github.com/repos/rapid7/nexpose-client/pulls/157/comments"},"review_comment":{"href":"https://api.github.com/repos/rapid7/nexpose-client/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rapid7/nexpose-client/pulls/157/commits"},"statuses":{"href":"https://api.github.com/repos/rapid7/nexpose-client/statuses/124d5a02c2f131ad422c2aa64bfbaac8cae75117"}}}}