Sha256: ce0b2b1225368bf3e794e50260588b3e559ddf7c78cf4fcdcf02e8ab5c38f2d8

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 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(connection)
        @connection = connection
      end

      def find(url, **options)
        query = ProfileQuery.new(url: url, **options)
        response = @connection.get("linkedin/company", query.to_h)
        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 = @connection.get("linkedin/company/resolve", query.to_request_params)
        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.1 lib/roseflow/linkedin/company.rb
roseflow-proxycurl-0.5.0 lib/roseflow/linkedin/company.rb