hackerone-client 0.17.0 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,12 @@ module HackerOne
15
15
  attributes.internal
16
16
  end
17
17
 
18
+ def attachments
19
+ @attachments ||= activity.relationships.fetch(:attachments, {})
20
+ .fetch(:data, [])
21
+ .map { |attachment| HackerOne::Client::Attachment.new(attachment) }
22
+ end
23
+
18
24
  private
19
25
 
20
26
  def relationships
@@ -85,6 +91,9 @@ module HackerOne
85
91
  delegate :message, :bounty_amount, :bonus_amount, to: :attributes
86
92
  end
87
93
 
94
+ class ReportLocked < Activity
95
+ end
96
+
88
97
  ACTIVITY_TYPE_CLASS_MAPPING = {
89
98
  "activity-bounty-awarded" => BountyAwarded,
90
99
  "activity-swag-awarded" => SwagAwarded,
@@ -93,7 +102,8 @@ module HackerOne
93
102
  "activity-bug-triaged" => BugTriaged,
94
103
  "activity-reference-id-added" => ReferenceIdAdded,
95
104
  "activity-comment" => CommentAdded,
96
- "activity-bounty-suggested" => BountySuggested
105
+ "activity-bounty-suggested" => BountySuggested,
106
+ "activity-comments-closed" => ReportLocked
97
107
  }.freeze
98
108
 
99
109
  def self.build(activity_data)
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HackerOne
4
+ module Client
5
+ class Attachment
6
+ delegate :expiring_url, :file_name, :content_type, :created_at, \
7
+ :file_size, to: :attributes
8
+
9
+ def initialize(attachment)
10
+ @attachment = attachment
11
+ end
12
+
13
+ def id
14
+ @attachment[:id]
15
+ end
16
+
17
+ private
18
+
19
+ def attributes
20
+ OpenStruct.new(@attachment[:attributes])
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HackerOne
4
+ module Client
5
+ class BillingBalance
6
+ delegate :balance, to: :attributes
7
+
8
+ def initialize(billing_balance)
9
+ @billing_balance = OpenStruct.new billing_balance
10
+ end
11
+
12
+ private
13
+ def attributes
14
+ OpenStruct.new(@billing_balance[:attributes])
15
+ end
16
+ end
17
+ end
18
+ end
@@ -76,6 +76,13 @@ module HackerOne
76
76
  response_body.map { |r| Swag.new(r, self) }
77
77
  end
78
78
 
79
+ def balance
80
+ response_body = make_get_request(
81
+ "programs/#{id}/billing/balance"
82
+ )
83
+ BillingBalance.new(response_body).balance
84
+ end
85
+
79
86
  private
80
87
 
81
88
  def members
@@ -26,6 +26,14 @@ module HackerOne
26
26
  duplicate
27
27
  ).map(&:to_sym).freeze
28
28
 
29
+ RESOLVED_STATES = %w(
30
+ resolved
31
+ not-applicable
32
+ informative
33
+ duplicate
34
+ spam
35
+ ).map(&:to_sym).freeze
36
+
29
37
  SEVERITY_RATINGS = %w(
30
38
  none
31
39
  low
@@ -135,6 +143,12 @@ module HackerOne
135
143
  classification_label.split("-").first
136
144
  end
137
145
 
146
+ def attachments
147
+ @attachments ||= relationships.fetch(:attachments, {})
148
+ .fetch(:data, [])
149
+ .map { |attachment| HackerOne::Client::Attachment.new(attachment) }
150
+ end
151
+
138
152
  def activities
139
153
  if ships = relationships.fetch(:activities, {}).fetch(:data, [])
140
154
  ships.map do |activity_data|
@@ -174,7 +188,7 @@ module HackerOne
174
188
  end
175
189
 
176
190
  def update_severity(rating:)
177
- raise ArgumentError, "Invalid severity rating" unless SEVERITY_RATINGS.include?(rating)
191
+ raise ArgumentError, "Invalid severity rating" unless SEVERITY_RATINGS.include?(rating.to_s)
178
192
 
179
193
  request_body = {
180
194
  type: "severity",
@@ -292,6 +306,19 @@ module HackerOne
292
306
  HackerOne::Client::Activities.build(response_json)
293
307
  end
294
308
 
309
+ def lock!
310
+ unless RESOLVED_STATES.include? self.state.to_sym
311
+ raise ArgumentError, "Report must be closed before locking"
312
+ end
313
+
314
+ body = {
315
+ type: "activity-comments-closed"
316
+ }
317
+
318
+ response_json = make_put_request("reports/#{id}/close_comments", request_body: body)
319
+ HackerOne::Client::Activities.build(response_json)
320
+ end
321
+
295
322
  def assign_to_user(name)
296
323
  member = program.find_member(name)
297
324
  _assign_to(member.user.id, :user)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Hackerone
4
4
  module Client
5
- VERSION = "0.17.0"
5
+ VERSION = "0.21.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hackerone-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil Matatall
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-24 00:00:00.000000000 Z
11
+ date: 2021-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -142,12 +142,18 @@ files:
142
142
  - fixtures/vcr_cassettes/award_a_bounty.yml
143
143
  - fixtures/vcr_cassettes/award_swag.yml
144
144
  - fixtures/vcr_cassettes/common_responses.yml
145
+ - fixtures/vcr_cassettes/create_report.yml
146
+ - fixtures/vcr_cassettes/create_report_invalid.yml
145
147
  - fixtures/vcr_cassettes/dup.yml
146
148
  - fixtures/vcr_cassettes/empty_report_list.yml
149
+ - fixtures/vcr_cassettes/get_balance.yml
150
+ - fixtures/vcr_cassettes/lock_report.yml
147
151
  - fixtures/vcr_cassettes/missing_report.yml
148
152
  - fixtures/vcr_cassettes/programs.yml
149
153
  - fixtures/vcr_cassettes/report.yml
150
154
  - fixtures/vcr_cassettes/report_list.yml
155
+ - fixtures/vcr_cassettes/report_list_before.yml
156
+ - fixtures/vcr_cassettes/report_list_triaged.yml
151
157
  - fixtures/vcr_cassettes/reporters.yml
152
158
  - fixtures/vcr_cassettes/server_error.yml
153
159
  - fixtures/vcr_cassettes/server_error_when_assigning_report_to_user.yml
@@ -165,6 +171,8 @@ files:
165
171
  - lib/hackerone/client.rb
166
172
  - lib/hackerone/client/activity.rb
167
173
  - lib/hackerone/client/address.rb
174
+ - lib/hackerone/client/attachment.rb
175
+ - lib/hackerone/client/billing_balance.rb
168
176
  - lib/hackerone/client/bounty.rb
169
177
  - lib/hackerone/client/group.rb
170
178
  - lib/hackerone/client/incremental/activities.rb