Class: PeopleGroup::Connectors::Workday::Client

Inherits:
Object
  • Object
show all
Includes:
XML::GetOrganizations, XML::RequestOneTimePayment
Defined in:
lib/peoplegroup/connectors/workday/client.rb

Overview

Workday client

Constant Summary collapse

XML_NAMESPACES =
{
  'xmlns' => nil,
  'xmlns:env' => 'http://schemas.xmlsoap.org/soap/envelope/',
  'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
  'xmlns:wsse' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'
}.freeze
API_VERSION =

Current Workday API Version

'v37.0'
EmployeeNotFoundError =
Class.new(StandardError)
ClientError =
Class.new(StandardError)

Constants included from XML::RequestOneTimePayment

XML::RequestOneTimePayment::DISCRETIONARY_BONUS, XML::RequestOneTimePayment::OPERATION, XML::RequestOneTimePayment::OPERATION_AS_PARAM

Constants included from XML::GetOrganizations

XML::GetOrganizations::OPERATION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from XML::RequestOneTimePayment

#add_bonus

Methods included from XML::GetOrganizations

#departments, #locations, #pay_groups, #regions

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/peoplegroup/connectors/workday/client.rb', line 36

def initialize(options = {})
  @options = {
    url: ENV.fetch('WORKDAY_SERVICE_URL', nil),
    username: ENV.fetch('WORKDAY_ISU_USERNAME', nil),
    password: ENV.fetch('WORKDAY_ISU_PASSWORD', nil),
    debug: ENV.fetch('WORKDAY_SOAP_DEBUG_LOGS', false)
  }.merge!(options)

  @uri = URI.parse(@options[:url])
  @uri.query = nil

  @instance = client(services)
rescue URI::InvalidURIError
  raise ClientError, "Invalid service URI: #{uri}"
end

Instance Attribute Details

#instanceObject (readonly)

The client instance



22
23
24
# File 'lib/peoplegroup/connectors/workday/client.rb', line 22

def instance
  @instance
end

#optionsObject (readonly)

Client Options



25
26
27
# File 'lib/peoplegroup/connectors/workday/client.rb', line 25

def options
  @options
end

#uriObject (readonly)

service uri



28
29
30
# File 'lib/peoplegroup/connectors/workday/client.rb', line 28

def uri
  @uri
end

Instance Method Details

#attributesObject

Default Workday specific body paramaters xmlns:wd - The URN of the XMLNS file wd:version - The API Version of workday



98
99
100
# File 'lib/peoplegroup/connectors/workday/client.rb', line 98

def attributes
  { attributes: { 'xmlns:wd' => 'urn:com.workday/bsvc', 'wd:version' => API_VERSION } }
end

#auto_paginated_call(operation_name, options = {}, &block) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/peoplegroup/connectors/workday/client.rb', line 63

def auto_paginated_call(operation_name, options = {}, &block)
  data = nil
  page = 1

  loop do
    response = @instance.call(operation_name, { **options, **attributes }, &block)
    # The response hash contains only one key named after the operation performed
    # eg. get_workers_response
    _operation_response_name, operation_result = response.to_hash.first

    page = operation_result.dig(:response_results, :page).to_i
    total_pages = operation_result.dig(:response_results, :total_pages).to_i

    # The operation data hash contains only one key named after the Workday object(s) retrieved
    # eg. worker
    _object_label, partial_data = operation_result[:response_data].first

    page == 1 ? data = partial_data : data.concat(partial_data)

    break if page == total_pages

    page += 1
  end

  data
end

#call(operation_name, options = {}, &block) ⇒ Object



56
57
58
59
60
61
# File 'lib/peoplegroup/connectors/workday/client.rb', line 56

def call(operation_name, options = {}, &block)
  response = @instance.call(operation_name, { **options, **attributes }, &block)
  { **response.body, code: response.http.code }
rescue Savon::UnknownOperationError => e
  raise ClientError.new(e), cause: nil
end

#debug_enabled?Boolean

Check if workday debug is enabled for the instance.

Returns:

  • (Boolean)


91
92
93
# File 'lib/peoplegroup/connectors/workday/client.rb', line 91

def debug_enabled?
  @options[:debug] ? true : false
end

#retry_on_error(&block) ⇒ Object



52
53
54
# File 'lib/peoplegroup/connectors/workday/client.rb', line 52

def retry_on_error(&block)
  Utils.retry_on_error(errors: [Net::ReadTimeout], delay: 3, &block)
end

#wsdl_urlString

Returns:

  • (String)

    The combined url to access the service at



105
106
107
# File 'lib/peoplegroup/connectors/workday/client.rb', line 105

def wsdl_url
  @wsdl_url ||= "#{@uri}/#{API_VERSION}?wsdl"
end