Sha256: c64786bd59bf82c55c617cd7566f1728dd629f099dd63fbd92cebb0c391d27a6

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

module Crunchbase
  class Client
    # Get information by permalink with optional one relationship
    def get(permalink, kclass_name, relationship_name = nil)
      case kclass_name
      when 'Person'
        person(permalink, relationship_name)
      when 'Organization'
        organization(permalink, relationship_name)
      end
    end

    # Get organization information by the permalink
    def organization(permalink, kclass_name = nil)
      request_perform('Organization', permalink, kclass_name)
    end

    # Get person information by the permalink
    def person(permalink, kclass_name = nil)
      request_perform('Person', permalink, kclass_name)
    end

    def list(kclass_name, options = {})
      page = options[:page] || 1

      kclass(kclass_name).list(page)
    end

    # options -> { query: "Ekohe" } || { name: "Ekohe" } || { domain_name: "ekohe.com" }
    def search(options, kclass_name)
      return [] if kclass_name.nil?

      kclass('Search').search(options, kclass_name)
    end

    def request_perform(stand_kclass, permalink, kclass_name)
      return kclass(stand_kclass).get(permalink) if kclass_name.nil?

      kclass(kclass_name).organization_lists(permalink)
    end

    private
    def kclass(kclass_name)
      Crunchbase::Model.const_get kclass_name
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
crunchbase-ruby-library-0.3.1 lib/crunchbase/client.rb