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.



40
41
42
# File 'lib/hackerone/client.rb', line 40

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.



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/hackerone/client.rb', line 94

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

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

#programObject



44
45
46
# File 'lib/hackerone/client.rb', line 44

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.



135
136
137
# File 'lib/hackerone/client.rb', line 135

def report(id)
  get("reports/#{id}")
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)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/hackerone/client.rb', line 54

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 = JSON.parse(response.body, :symbolize_names => true)[:data]
  if data.nil?
    raise RuntimeError, "Expected data attribute in response: #{response.body}"
  end

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

#state_change(id, state) ⇒ 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)


114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/hackerone/client.rb', line 114

def state_change(id, state)
  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
      }
    }
  }
  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.



82
83
84
85
# File 'lib/hackerone/client.rb', line 82

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