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.



54
55
56
57
58
59
60
# File 'app/models/ucb_rails_user/user_uc_path_service.rb', line 54

def initialize
  credentials =
    Rails.application.credentials.ucpath || Rails.application.credentials.hcm
  @app_id  = credentials&.fetch(:app_id)
  @app_key = credentials&.fetch(:app_key)
  @endpoint = credentials&.fetch(:endpoint)
end

Instance Attribute Details

#app_idObject (readonly)

Returns the value of attribute app_id.



52
53
54
# File 'app/models/ucb_rails_user/user_uc_path_service.rb', line 52

def app_id
  @app_id
end

#app_keyObject (readonly)

Returns the value of attribute app_key.



52
53
54
# File 'app/models/ucb_rails_user/user_uc_path_service.rb', line 52

def app_key
  @app_key
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



52
53
54
# File 'app/models/ucb_rails_user/user_uc_path_service.rb', line 52

def endpoint
  @endpoint
end

Instance Method Details

#fetch_employee_data(ldap_uid) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/ucb_rails_user/user_uc_path_service.rb', line 62

def fetch_employee_data(ldap_uid)
  if [app_id, app_key, endpoint].any?(&:blank?)
    Rails.logger.warn missing_api_values_message
    return nil
  end

  response =
    Faraday.get("#{endpoint}/employees/#{ldap_uid}") do |req|
      req.params["id-type"] = "campus-uid"
      req.headers["Accept"] = "application/json"
      req.headers["app_id"] = app_id
      req.headers["app_key"] = app_key
    end
  parse_response(response)&.first
end