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

#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.



94
95
96
# File 'lib/hackerone/client.rb', line 94

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

#reportersObject

Raises:

  • (ArgumentError)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/hackerone/client.rb', line 48

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)


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/hackerone/client.rb', line 70

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