Class: HackerOne::Client::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/hackerone/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(program = nil) ⇒ Api

Returns a new instance of Api.



54
55
56
# File 'lib/hackerone/client.rb', line 54

def initialize(program = nil)
  @program = program
end

Instance Method Details

#add_report_reference(id, reference) ⇒ Object

Idempotent: Add a report reference to a project

id: the ID of the report state: value for the reference (e.g. issue number or relative path to cross-repo issue)

returns an HackerOne::Client::Report object or raises an error if no report is found.



121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/hackerone/client.rb', line 121

def add_report_reference(id, reference)
  body = {
    data: {
      type: "issue-tracker-reference-id",
      attributes: {
        reference: reference
      }
    }
  }

  Report.new(post("reports/#{id}/issue_tracker_reference_id", body))
end

#programObject



58
59
60
# File 'lib/hackerone/client.rb', line 58

def program
  @program || HackerOne::Client.program
end

#report(id) ⇒ Object

Public: retrieve a report

id: the ID of a specific report

returns an HackerOne::Client::Report object or raises an error if no report is found.



170
171
172
# File 'lib/hackerone/client.rb', line 170

def report(id)
  Report.new(get("reports/#{id}"))
end

#reportersObject

Raises:

  • (ArgumentError)


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/hackerone/client.rb', line 62

def reporters
  raise ArgumentError, "Program cannot be nil" unless program
  response = self.class.hackerone_api_connection.get do |req|
    req.url "programs/#{Program.find(program).id}/reporters"
  end

  data = self.class.parse_response(response)
  if data.nil?
    raise RuntimeError, "Expected data attribute in response: #{response.body}"
  end

  data.map do |reporter|
    Reporter.new(reporter)
  end
end

#reports(since: 3.days.ago) ⇒ Object

Returns all open reports, optionally with a time bound

program: the HackerOne program to search on (configure globally with Hackerone::Client.program=) since (optional): a time bound, don’t include reports earlier than since. Must be a DateTime object.

returns all open reports or an empty array

Raises:

  • (ArgumentError)


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/hackerone/client.rb', line 84

def reports(since: 3.days.ago)
  raise ArgumentError, "Program cannot be nil" unless program
  response = self.class.hackerone_api_connection.get do |req|
    options = {
      "filter[state][]" => "new",
      "filter[program][]" => program,
      "filter[created_at__gt]" => since.iso8601
    }
    req.url "reports", options
  end

  data = self.class.parse_response(response)

  data.map do |report|
    Report.new(report)
  end
end

#state_change(id, state, message = nil) ⇒ Object

Idempotent: change the state of a report. See STATES for valid values.

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.

Raises:

  • (ArgumentError)


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/hackerone/client.rb', line 141

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: {
        state: state
      }
    }
  }

  if message
    body[:data][:attributes][:message] = message
  elsif STATES_REQUIRING_STATE_CHANGE_MESSAGE.include?(state)
    fail ArgumentError, "State #{state} requires a message. No message was supplied."
  else
    # message is in theory optional, but a value appears to be required.
    body[:data][:attributes][:message] = ""
  end
  post("reports/#{id}/state_changes", body)
end

#triage(id, reference) ⇒ Object

Idempotent: add the issue reference and put the report into the “triage” state.

id: the ID of the report state: value for the reference (e.g. issue number or relative path to cross-repo issue)

returns an HackerOne::Client::Report object or raises an error if no report is found.



109
110
111
112
# File 'lib/hackerone/client.rb', line 109

def triage(id, reference)
  add_report_reference(id, reference)
  state_change(id, :triaged)
end