Sha256: 1b52ddbdc4e3a164e456efdb1e5c92d71cefc65627270368cdb01f575d657358

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require "roseflow/linkedin/company/profile_query"
require "roseflow/linkedin/company/lookup_query"

module Roseflow
  module LinkedIn
    class Company
      def initialize(client = Roseflow::Proxycurl::Client.new)
        @client = client
      end

      def find(url, **options)
        query = ProfileQuery.new(url: url, **options)
        response = @client.find_company(query)
        return Company::Object.new(JSON.parse(response.body).merge("profile_url" => url)) if company_found?(response)
        return nil if company_not_found?(response)
      end

      def lookup(query)
        query = LookupQuery.new(query)
        response = @client.lookup_company(query)
        return JSON.parse(response.body).dig("url") if company_found?(response)
        return nil if company_not_found?(response)
      end

      private

      def company_found?(response)
        response.success? && response.status == 200
      end

      def company_not_found?(response)
        response.success? && response.status == 404
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
roseflow-proxycurl-0.5.5 lib/roseflow/linkedin/company.rb
roseflow-proxycurl-0.5.2 lib/roseflow/linkedin/company.rb