Class: Copyleaks::SubmissionWebhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/copyleaks/models/submissions/properties/webhooks.rb

Instance Method Summary collapse

Constructor Details

#initialize(status, newResult = nil, statusHeaders = nil, newResultHeaders = nil) ⇒ SubmissionWebhooks

Returns a new instance of SubmissionWebhooks.

Parameters:

  • status (String)

    This webhook event is triggered once the scan status changes. Use the special token STATUS to track the current scan status. This special token will automatically be replaced by the Copyleaks servers with the optional values: completed, error, creditsChecked and indexed. Read more about webhooks: api.copyleaks.com/documentation/v3/webhooks

  • newResult (String) (defaults to: nil)

    Http endpoint to be triggered while the scan is still running and a new result is found. This is useful when the report is being viewed by the user in real time so the results will load gradually as they are found.

  • statusHeaders (Array) (defaults to: nil)

    Adds headers to the webhook.

  • newResultHeaders (Array) (defaults to: nil)

    Adds headers to the webhook.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/copyleaks/models/submissions/properties/webhooks.rb', line 30

def initialize(status, newResult = nil, statusHeaders = nil, newResultHeaders = nil)
  unless status.instance_of? String
    raise 'Copyleaks::SubmissionWebhooks - status - status must be of type String'
  end
  unless newResult.nil? || newResult.instance_of?(String)
    raise 'Copyleaks::SubmissionWebhooks - newResult - newResult must be of type String'
  end
  unless header_format_valid?(statusHeaders)
    raise 'Copyleaks::SubmissionWebhooks - statusHeaders - statusHeaders must be an Array of String Array pairs'
  end
  unless header_format_valid?(newResultHeaders)
    raise 'Copyleaks::SubmissionWebhooks - newResultHeaders - newResultHeaders must be an Array of String Array pairs'
  end

  @newResult = newResult
  @status = status
  @statusHeaders = statusHeaders
  @newResultHeaders = newResultHeaders
end

Instance Method Details

#as_json(*_args) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/copyleaks/models/submissions/properties/webhooks.rb', line 50

def as_json(*_args)
  {
    newResult: @newResult,
    status: @status,
    statusHeaders: @statusHeaders,
    newResultHeaders: @newResultHeaders
  }.select { |_k, v| !v.nil? }
end

#to_json(*options) ⇒ Object



59
60
61
# File 'lib/copyleaks/models/submissions/properties/webhooks.rb', line 59

def to_json(*options)
  as_json(*options).to_json(*options)
end