Class: PeopleGroup::Connectors::Workday::Report
- Inherits:
-
Object
- Object
- PeopleGroup::Connectors::Workday::Report
- Defined in:
- lib/peoplegroup/connectors/workday/report.rb
Overview
Report
Instance Attribute Summary collapse
-
#auth_header ⇒ Object
readonly
The authorization header used for the report.
-
#uri ⇒ Object
readonly
The parsed URI of the report URL.
Class Method Summary collapse
-
.call(url:, password: nil, prompts: {}) ⇒ Array|Hash
The JSON report response.
Instance Method Summary collapse
-
#initialize(url:, password: nil) ⇒ Report
constructor
Create a new report instance.
-
#inspect ⇒ Object
Inspect the Workday Report instance.
-
#report_url(prompts = {}) ⇒ String
Combine the url and extra input parameters in an encoded format.
-
#run(prompts = {}) ⇒ Array|Hash
Run the report with the given prompts.
-
#username ⇒ Object
Extract username from URI path (needed for auth).
Constructor Details
#initialize(url:, password: nil) ⇒ Report
Create a new report instance
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/peoplegroup/connectors/workday/report.rb', line 25 def initialize(url:, password: nil) @uri = URI.parse(url) # Ensure URI is properly read raise ReportError, "Error with report URL: #{url}. Is this a valid URL?" unless @uri.scheme && @uri.host && @uri.path @uri.query = nil # clear any query params # Use provided password or search in env. pass = password || ENV.fetch('WORKDAY_ISU_PASSWORD', nil) raise ReportError, "No username provided for report: #{url}" if username.nil? raise ReportError, "No password provided for report: #{url}" if pass.nil? # Encode credentials auth = Base64.strict_encode64("#{username}:#{pass}") # Base64 Encode @auth_header = { Authorization: "Basic #{auth}" } rescue URI::InvalidURIError raise ReportError, "Invalid URI detected for report: '#{url}'." end |
Instance Attribute Details
#auth_header ⇒ Object (readonly)
The authorization header used for the report.
17 18 19 |
# File 'lib/peoplegroup/connectors/workday/report.rb', line 17 def auth_header @auth_header end |
#uri ⇒ Object (readonly)
The parsed URI of the report URL
20 21 22 |
# File 'lib/peoplegroup/connectors/workday/report.rb', line 20 def uri @uri end |
Class Method Details
.call(url:, password: nil, prompts: {}) ⇒ Array|Hash
Returns the JSON report response.
52 53 54 |
# File 'lib/peoplegroup/connectors/workday/report.rb', line 52 def self.call(url:, password: nil, prompts: {}) new(url: url, password: password)&.run(prompts) end |
Instance Method Details
#inspect ⇒ Object
Inspect the Workday Report instance
90 91 92 |
# File 'lib/peoplegroup/connectors/workday/report.rb', line 90 def inspect "#<#{self.class.name}:#{object_id} @uri='#{@uri}' @auth_header=#{@auth_header ? 'HIDDEN' : auth_header} @username=#{username}>" end |
#report_url(prompts = {}) ⇒ String
Combine the url and extra input parameters in an encoded format.
82 83 84 85 86 87 |
# File 'lib/peoplegroup/connectors/workday/report.rb', line 82 def report_url(prompts = {}) uri = @uri.clone # copy the URI object params = prompts.merge!({ format: :json }) # ensure report format is always JSON uri.query = URI.encode_www_form(params) uri.to_s end |
#run(prompts = {}) ⇒ Array|Hash
Run the report with the given prompts
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/peoplegroup/connectors/workday/report.rb', line 60 def run(prompts = {}) url = report_url(prompts) RestClient.get(url, @auth_header) do |response, _req, _result| # Raise a report error if we ran into any issues accessing the report raise ReportError, inspect, response unless response&.code == 200 # parse the response body into JSON json = JSON.parse(response.body) # if return content of 'Report_Entry' or the whole set if key does not exist. json['Report_Entry'] || json end end |
#username ⇒ Object
Extract username from URI path (needed for auth)
75 76 77 |
# File 'lib/peoplegroup/connectors/workday/report.rb', line 75 def username @username ||= @uri.path.split('/')[-2] end |