lib/hackerone/client.rb in hackerone-client-0.2.3 vs lib/hackerone/client.rb in hackerone-client-0.3.0
- old
+ new
@@ -1,9 +1,10 @@
require "faraday"
require 'active_support/time'
require_relative "client/version"
require_relative "client/report"
+require_relative "client/activity"
module HackerOne
module Client
class NotConfiguredError < StandardError; end
@@ -19,12 +20,18 @@
resolved
not-applicable
informative
duplicate
spam
- ).map(&:to_sym)
+ ).map(&:to_sym).freeze
+ STATES_REQUIRING_STATE_CHANGE_MESSAGE = %w(
+ needs-more-info
+ informative
+ duplicate
+ ).map(&:to_sym).freeze
+
class << self
ATTRS = [:low_range, :medium_range, :high_range, :critical_range].freeze
attr_accessor :program
attr_reader *ATTRS
@@ -109,22 +116,27 @@
# id: the ID of the report
# state: the state in which the report is to be put in
#
# returns an HackerOne::Client::Report object or raises an error if
# no report is found.
- def state_change(id, state)
+ def state_change(id, state, message = nil)
raise ArgumentError, "state (#{state}) must be one of #{STATES}" unless STATES.include?(state)
body = {
data: {
type: "state-change",
attributes: {
- message: "This is has been triaged internally.",
state: state
}
}
}
+
+ if message
+ body[:message] = message
+ elsif STATES_REQUIRING_STATE_CHANGE_MESSAGE.include?(state)
+ fail ArgumentError, "State #{state} requires a message. No message was supplied."
+ end
post("reports/#{id}/state_changes", body)
end
## Public: retrieve a report
#
@@ -163,10 +175,10 @@
def parse_response(response)
if response.status.to_s.start_with?("4")
raise ArgumentError, "API called failed, probably your fault: #{response.body}"
elsif response.status.to_s.start_with?("5")
- raise Runtime, "API called failed, probobly their fault: #{response.body}"
+ raise RuntimeError, "API called failed, probably their fault: #{response.body}"
elsif response.success?
Report.new(JSON.parse(response.body, :symbolize_names => true)[:data])
else
raise RuntimeError, "Not sure what to do here: #{response.body}"
end