Class: UcbRailsUser::UserUcPathService::UcPathClient

Inherits:
Object
  • Object
show all
Defined in:
app/models/ucb_rails_user/user_uc_path_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUcPathClient

Returns a new instance of UcPathClient.



68
69
70
71
72
73
74
75
76
77
# File 'app/models/ucb_rails_user/user_uc_path_service.rb', line 68

def initialize
  base_credentials =
    Rails.application.credentials.ucpath&.with_indifferent_access ||
    Rails.application.credentials.hcm&.with_indifferent_access ||
    Rails.application.credentials.fetch(:"ucb-hcm", {})&.with_indifferent_access
  env_credentials = base_credentials&.fetch(Rails.env, {})
  @app_id  = env_credentials&.fetch(:app_id, nil) || base_credentials&.fetch(:app_id, nil)
  @app_key = env_credentials&.fetch(:app_key, nil) || base_credentials&.fetch(:app_key, nil)
  @endpoint = env_credentials&.fetch(:endpoint, nil) || base_credentials&.fetch(:endpoint, nil)
end

Instance Attribute Details

#app_idObject (readonly)

Returns the value of attribute app_id.



66
67
68
# File 'app/models/ucb_rails_user/user_uc_path_service.rb', line 66

def app_id
  @app_id
end

#app_keyObject (readonly)

Returns the value of attribute app_key.



66
67
68
# File 'app/models/ucb_rails_user/user_uc_path_service.rb', line 66

def app_key
  @app_key
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



66
67
68
# File 'app/models/ucb_rails_user/user_uc_path_service.rb', line 66

def endpoint
  @endpoint
end

Instance Method Details

#fetch_employee_data(id, id_type) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/models/ucb_rails_user/user_uc_path_service.rb', line 87

def fetch_employee_data(id, id_type)
  if [app_id, app_key, endpoint].any?(&:blank?)
    Rails.logger.warn missing_api_values_message
    return nil
  end
  response =
    Faraday.get("#{endpoint}/employees/#{id}") do |req|
      req.params["id-type"] = id_type
      req.headers["Accept"] = "application/json"
      req.headers["app_id"] = app_id
      req.headers["app_key"] = app_key
    end
  parse_response(response)&.first
end

#fetch_employee_data_with_employee_id(employee_id) ⇒ Object



83
84
85
# File 'app/models/ucb_rails_user/user_uc_path_service.rb', line 83

def fetch_employee_data_with_employee_id(employee_id)
  fetch_employee_data(employee_id, "hr-employee-id")
end

#fetch_employee_data_with_ldap_uid(ldap_uid) ⇒ Object



79
80
81
# File 'app/models/ucb_rails_user/user_uc_path_service.rb', line 79

def fetch_employee_data_with_ldap_uid(ldap_uid)
  fetch_employee_data(ldap_uid, "campus-uid")
end