Sha256: 73387dcdfe56a62eeb2a33e05c0247950628cfb03930ae144df8b02a92ae5de3

Contents?: true

Size: 1.6 KB

Versions: 4

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require "dry-validation"
require "roseflow/proxycurl/object"
require "roseflow/linkedin/person"
require "roseflow/types"

module Roseflow
  module LinkedIn
    class Person
      class LookupQuery < Proxycurl::ProxycurlObject
        class LookupQueryContract < Dry::Validation::Contract
          params do
            required(:domain).filled(:string)
            required(:first_name).filled(:string)
            optional(:last_name).filled(:string)
            optional(:title).filled(:string)
            optional(:location).filled(:string)
            optional(:enrich).filled(:bool)
          end
        end

        contract_object LookupQueryContract

        schema schema.strict

        attribute :domain, Types::String
        attribute :first_name, Types::String
        attribute? :last_name, Types::String
        attribute? :title, Types::String
        attribute? :location, Types::String
        attribute? :enrich, Types::Bool.default(false)

        def self.new(input)
          validation = self.contract_object.new.call(input)
          raise ArgumentError, validation.errors.to_h.inspect unless validation.success?
          super(input)
        end

        def to_request_params
          params = {
            company_domain: domain,
            first_name: first_name,
            last_name: last_name,
            title: title,
            location: location,
            enrich_profile: enrich == true ? "enrich" : "skip",
          }

          params.each_pair do |key, value|
            params.delete(key) unless value
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
roseflow-proxycurl-0.5.5 lib/roseflow/linkedin/person/lookup_query.rb
roseflow-proxycurl-0.5.2 lib/roseflow/linkedin/person/lookup_query.rb
roseflow-proxycurl-0.5.1 lib/roseflow/linkedin/person/lookup_query.rb
roseflow-proxycurl-0.5.0 lib/roseflow/linkedin/person/lookup_query.rb