# frozen_string_literal: true require_relative "../../response/inducement_response" require_relative "../../response/providers_users_details_response" module ONEAccess module API module V3_0 class Providers < Base api_path "/providers" class << self def inducements(recipient_user_id:, sender_email:, subject:, email_body:, receive_date:) params = { recipientuserid: recipient_user_id, senderemail: sender_email, subject: subject, emailbody: email_body, receivedate: receive_date }.reject { |_, v| v.nil? } response = send_post("inducements", inducement: params) Response::InducementResponse.from_json(response.body) end # rubocop:disable Metrics/MethodLength def users_details( buy_side_org_id:, provider_id:, contract_status_id: nil, user_id: nil, user_email: nil, user_reverse_entitlement_status: nil, vendor_id: nil, reverse_entitlement_status: nil ) params = { buysideorgid: buy_side_org_id, contractstatusid: contract_status_id, userid: user_id, useremail: user_email, userreverseentitlementstatus: user_reverse_entitlement_status, vendorid: vendor_id, reverseentitlementstatus: reverse_entitlement_status }.compact! resp = send_get("GetProviderUserDetails?providerid=#{comma_separated_values(provider_id)}", params) Response::ProvidersUsersDetailsResponse.from_json(resp.body) end # rubocop:enable Metrics/MethodLength private # We need to diffently handle comma separated values since the RestClient, # gem URI encode the commas and this is not supported by the API. # # Examples: # [1,2$,3] => '1,2%24,3' # '1,2$,3' => '1,2%24,3' def comma_separated_values(values) values = values.split(",") if values.is_a?(String) if values.is_a?(Array) values = values.map do |value| URI.encode_www_form_component(value) end.join(",") end values end end end end end end